mod input and routes
This commit is contained in:
@@ -1,17 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:appwrite/models.dart' as user_models;
|
||||
import '../controllers/login_controller.dart';
|
||||
import '../controllers/geolocation_controller.dart';
|
||||
import '../models/ptv_logistic_model.dart';
|
||||
import '../routes/app_routes.dart';
|
||||
|
||||
class InputController extends GetxController {
|
||||
|
||||
final GeolocationController geoCtrl = Get.put(GeolocationController());
|
||||
final LoginController loginCtrl = Get.put(LoginController());
|
||||
final _ptvModel = Rxn<PTVModel>();
|
||||
final _user = (Get.arguments as user_models.User).obs;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
PTVModel? get ptvModel => _ptvModel.value;
|
||||
user_models.User? get currentUser => _user.value;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_getLocation();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {}
|
||||
@override
|
||||
void onReady() {}
|
||||
|
||||
@override
|
||||
void onClose() {}
|
||||
@override
|
||||
void onClose() {
|
||||
geoCtrl.onClose();
|
||||
loginCtrl.onClose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void _getLocation() async {
|
||||
await geoCtrl.getCurrentPosition().then(
|
||||
(_) => {_ptvModel.value = geoCtrl.ptvModel},
|
||||
);
|
||||
update();
|
||||
}
|
||||
|
||||
void goToListPage() {
|
||||
//AppNavigation.goToListPage
|
||||
}
|
||||
|
||||
void logout() {
|
||||
loginCtrl.logout();
|
||||
//AppNavigation.toLogin();
|
||||
AppNavigation.offAllToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import 'package:appwrite/appwrite.dart' as account_models;
|
||||
import 'package:appwrite/models.dart' as user_models;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../routes/app_routes.dart';
|
||||
|
||||
class LoginController extends GetxController {
|
||||
final _account = Rxn<account_models.Account>();
|
||||
final mailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final nameController = TextEditingController();
|
||||
late TextEditingController mailController;
|
||||
late TextEditingController passwordController;
|
||||
late TextEditingController nameController;
|
||||
final _endpoint = dotenv.env['APPWRITE_ENDPOINT_URL'] ?? '';
|
||||
final _projectId = dotenv.env['APPWRITE_PROJECT_ID'] ?? '';
|
||||
final bool _selfSigned =
|
||||
@@ -24,6 +26,11 @@ class LoginController extends GetxController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// Initialisiere TextEditingController
|
||||
mailController = TextEditingController();
|
||||
passwordController = TextEditingController();
|
||||
nameController = TextEditingController();
|
||||
// Initialisiere Client
|
||||
Client client = Client().setEndpoint(_endpoint).setProject(_projectId);
|
||||
// Optional: Unsichere/self-signed Zertifikate im Dev zulassen (nicht im Web wirksam)
|
||||
if (!kIsWeb && _selfSigned) {
|
||||
@@ -62,6 +69,7 @@ class LoginController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> login() async {
|
||||
logout();
|
||||
try {
|
||||
var result = await _account.value!.createEmailPasswordSession(
|
||||
email: mailController.text,
|
||||
@@ -72,9 +80,10 @@ class LoginController extends GetxController {
|
||||
final user = await _account.value!.get();
|
||||
_logedInUser.value = user;
|
||||
clearFields();
|
||||
goToInput(user);
|
||||
Get.snackbar(
|
||||
'Erfolg',
|
||||
'Anmeldung erfolgreich',
|
||||
'Anmeldung erfolgreich ${user.name}, ID: ${user.$id}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} on AppwriteException catch (e) {
|
||||
@@ -97,7 +106,7 @@ class LoginController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
clearFields(){
|
||||
clearFields() {
|
||||
mailController.clear();
|
||||
passwordController.clear();
|
||||
nameController.clear();
|
||||
@@ -133,8 +142,14 @@ class LoginController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await _account.value!.deleteSession(sessionId: 'current');
|
||||
await _account.value!.deleteSession(sessionId: 'current');
|
||||
_logedInUser.value = null;
|
||||
Get.snackbar(
|
||||
'Erfolg',
|
||||
'Logout erfolgreich',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red.shade500,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -144,5 +159,8 @@ class LoginController extends GetxController {
|
||||
nameController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
void goToInput(Object args) {
|
||||
AppNavigation.toInputPageWithArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
class InputModel {
|
||||
String szDocumentId;
|
||||
String szUserId;
|
||||
String szDate;
|
||||
int nOdometer;
|
||||
double mnLiters;
|
||||
double mnPricePerLiter;
|
||||
String szLocation;
|
||||
double? mnTotalPrice;
|
||||
InputModel({required this.szDocumentId, required this.szUserId, required this.szDate, required this.nOdometer, required this.mnLiters, required this.mnPricePerLiter, required this.szLocation, this.mnTotalPrice});
|
||||
|
||||
factory InputModel.fromJson(Map<String, dynamic> json) {
|
||||
return InputModel(
|
||||
szDocumentId: json['szDocumentId'] as String,
|
||||
szUserId: json['szUserId'] as String,
|
||||
szDate: json['szDate'] as String,
|
||||
nOdometer: json['nOdometer'] as int,
|
||||
mnLiters: json['mnLiters'] as double,
|
||||
mnPricePerLiter: json['mnPricePerLiter'] as double,
|
||||
szLocation: json['szLocation'] as String,
|
||||
mnTotalPrice: (json['mnLiters'] as double) * (json['mnPricePerLiter'] as double),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'szDocumentId': szDocumentId,
|
||||
'szUserId': szUserId,
|
||||
'szDate': szDate,
|
||||
'nOdometer': nOdometer,
|
||||
'mnLiters': mnLiters,
|
||||
'mnPricePerLiter': mnPricePerLiter,
|
||||
'szLocation': szLocation,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,12 +3,58 @@ import 'package:get/get.dart';
|
||||
import '../../controllers/input_controller.dart';
|
||||
|
||||
class InputPage extends GetView<InputController> {
|
||||
const InputPage({super.key});
|
||||
const InputPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(),
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var inputCtrl = controller;
|
||||
return SafeArea(
|
||||
child: PopScope(
|
||||
canPop: false,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Tankstop Eingabe'),
|
||||
leading: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.list),
|
||||
onPressed: () {
|
||||
inputCtrl.goToListPage();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () {
|
||||
inputCtrl.onInit();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.exit_to_app),
|
||||
onPressed: () {
|
||||
inputCtrl.logout();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => inputCtrl.ptvModel != null && inputCtrl.currentUser != null
|
||||
? Text('UserEmail: ${inputCtrl.currentUser!.email}\nName: ${inputCtrl.currentUser!.name}\nFormattedAddress: ${inputCtrl.ptvModel!.locations!.first.formattedAddress}',
|
||||
)
|
||||
: const Text('Keine Daten gefunden'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ class LoginPage extends GetView<LoginController> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.local_gas_station,
|
||||
size: 100,
|
||||
IconButton(
|
||||
icon: const Icon(Icons.local_gas_station),
|
||||
iconSize: 100,
|
||||
onPressed: ()=> logCtrl.logout(),
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../bindings/input_binding.dart';
|
||||
import '../bindings/login_binding.dart';
|
||||
import '../pages/examples/geolocation_example.dart';
|
||||
import '../bindings/geolocation_binding.dart';
|
||||
import '../pages/input/input_view.dart';
|
||||
import '../pages/login/login_view.dart';
|
||||
|
||||
/// App Routes Konfiguration
|
||||
class AppRoutes {
|
||||
static const String home = '/';
|
||||
static const String geolocation = '/geolocation';
|
||||
static const String login = '/login';
|
||||
static const String listPage = '/list-page';
|
||||
static const String inputPage = '/input-page';
|
||||
|
||||
/// Route Pages Definition
|
||||
static List<GetPage> pages = [
|
||||
GetPage(
|
||||
name: geolocation,
|
||||
page: () => const GeolocationExample(),
|
||||
binding: GeolocationBinding(), // Dependency Injection
|
||||
GetPage(
|
||||
name: login,
|
||||
page: () => const LoginPage(),
|
||||
binding: LoginBinding(), // Dependency Injection
|
||||
transition: Transition.cupertino,
|
||||
transitionDuration: const Duration(milliseconds: 300),
|
||||
),
|
||||
GetPage(
|
||||
name: login,
|
||||
page: () => const LoginPage(),
|
||||
binding: LoginBinding(), // Dependency Injection
|
||||
name: inputPage,
|
||||
page: () => const InputPage(),
|
||||
binding: InputBinding(), // Dependency Injection
|
||||
transition: Transition.cupertino,
|
||||
transitionDuration: const Duration(milliseconds: 300),
|
||||
),
|
||||
@@ -34,23 +34,12 @@ class AppRoutes {
|
||||
// static const String geolocationExample = '/geolocation-example';
|
||||
// }
|
||||
|
||||
|
||||
/// Navigation Helper Klasse
|
||||
class AppNavigation {
|
||||
/// Navigate to Geolocation Example
|
||||
static void toGeolocation() {
|
||||
Get.toNamed(AppRoutes.geolocation);
|
||||
}
|
||||
|
||||
/// Navigate and replace current route
|
||||
static void offGeolocation() {
|
||||
Get.offNamed(AppRoutes.geolocation);
|
||||
}
|
||||
|
||||
/// Navigate and clear all previous routes
|
||||
static void offAllToGeolocation() {
|
||||
Get.offAllNamed(AppRoutes.geolocation);
|
||||
}
|
||||
|
||||
|
||||
/// Login Navigation Methods
|
||||
/// Navigate to Login Page
|
||||
static void toLogin() {
|
||||
Get.toNamed(AppRoutes.login);
|
||||
@@ -63,6 +52,17 @@ class AppNavigation {
|
||||
static void offAllToLogin() {
|
||||
Get.offAllNamed(AppRoutes.login);
|
||||
}
|
||||
|
||||
/// Input Navigation Methods
|
||||
/// Navigate to Input Page
|
||||
static void toInputPage() {
|
||||
Get.toNamed(AppRoutes.inputPage);
|
||||
}
|
||||
|
||||
/// Navigate to Input Page with args
|
||||
static void toInputPageWithArgs(Object args) {
|
||||
Get.toNamed(AppRoutes.inputPage, arguments: args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user