mod input and routes
This commit is contained in:
parent
ee655328e6
commit
059b4773f4
@ -1,10 +1,24 @@
|
||||
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>();
|
||||
|
||||
PTVModel? get ptvModel => _ptvModel.value;
|
||||
user_models.User? get currentUser => _user.value;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_getLocation();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@ -12,6 +26,26 @@ class InputController extends GetxController {
|
||||
void onReady() {}
|
||||
|
||||
@override
|
||||
void onClose() {}
|
||||
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();
|
||||
@ -135,6 +144,12 @@ class LoginController extends GetxController {
|
||||
Future<void> logout() async {
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,54 @@ class InputPage extends GetView<InputController> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(),
|
||||
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
|
||||
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);
|
||||
@ -64,6 +53,17 @@ class AppNavigation {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Navigate back
|
||||
|
||||
16
pubspec.lock
16
pubspec.lock
@ -37,10 +37,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: characters
|
||||
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
|
||||
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
version: "1.4.1"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -332,18 +332,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.11.1"
|
||||
version: "0.13.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
|
||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
version: "1.17.0"
|
||||
package_info_plus:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -497,10 +497,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
|
||||
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.6"
|
||||
version: "0.7.7"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user