mod input and routes
This commit is contained in:
parent
ee655328e6
commit
059b4773f4
@ -1,17 +1,51 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.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 {
|
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
|
PTVModel? get ptvModel => _ptvModel.value;
|
||||||
void onInit() {
|
user_models.User? get currentUser => _user.value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
_getLocation();
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {}
|
void onReady() {}
|
||||||
|
|
||||||
@override
|
@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/appwrite.dart' as account_models;
|
||||||
import 'package:appwrite/models.dart' as user_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:get/get.dart';
|
||||||
import 'package:appwrite/appwrite.dart';
|
import 'package:appwrite/appwrite.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import '../routes/app_routes.dart';
|
||||||
|
|
||||||
class LoginController extends GetxController {
|
class LoginController extends GetxController {
|
||||||
final _account = Rxn<account_models.Account>();
|
final _account = Rxn<account_models.Account>();
|
||||||
final mailController = TextEditingController();
|
late TextEditingController mailController;
|
||||||
final passwordController = TextEditingController();
|
late TextEditingController passwordController;
|
||||||
final nameController = TextEditingController();
|
late TextEditingController nameController;
|
||||||
final _endpoint = dotenv.env['APPWRITE_ENDPOINT_URL'] ?? '';
|
final _endpoint = dotenv.env['APPWRITE_ENDPOINT_URL'] ?? '';
|
||||||
final _projectId = dotenv.env['APPWRITE_PROJECT_ID'] ?? '';
|
final _projectId = dotenv.env['APPWRITE_PROJECT_ID'] ?? '';
|
||||||
final bool _selfSigned =
|
final bool _selfSigned =
|
||||||
@ -24,6 +26,11 @@ class LoginController extends GetxController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
|
// Initialisiere TextEditingController
|
||||||
|
mailController = TextEditingController();
|
||||||
|
passwordController = TextEditingController();
|
||||||
|
nameController = TextEditingController();
|
||||||
|
// Initialisiere Client
|
||||||
Client client = Client().setEndpoint(_endpoint).setProject(_projectId);
|
Client client = Client().setEndpoint(_endpoint).setProject(_projectId);
|
||||||
// Optional: Unsichere/self-signed Zertifikate im Dev zulassen (nicht im Web wirksam)
|
// Optional: Unsichere/self-signed Zertifikate im Dev zulassen (nicht im Web wirksam)
|
||||||
if (!kIsWeb && _selfSigned) {
|
if (!kIsWeb && _selfSigned) {
|
||||||
@ -62,6 +69,7 @@ class LoginController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> login() async {
|
Future<void> login() async {
|
||||||
|
logout();
|
||||||
try {
|
try {
|
||||||
var result = await _account.value!.createEmailPasswordSession(
|
var result = await _account.value!.createEmailPasswordSession(
|
||||||
email: mailController.text,
|
email: mailController.text,
|
||||||
@ -72,9 +80,10 @@ class LoginController extends GetxController {
|
|||||||
final user = await _account.value!.get();
|
final user = await _account.value!.get();
|
||||||
_logedInUser.value = user;
|
_logedInUser.value = user;
|
||||||
clearFields();
|
clearFields();
|
||||||
|
goToInput(user);
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'Erfolg',
|
'Erfolg',
|
||||||
'Anmeldung erfolgreich',
|
'Anmeldung erfolgreich ${user.name}, ID: ${user.$id}',
|
||||||
snackPosition: SnackPosition.BOTTOM,
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
);
|
);
|
||||||
} on AppwriteException catch (e) {
|
} on AppwriteException catch (e) {
|
||||||
@ -97,7 +106,7 @@ class LoginController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFields(){
|
clearFields() {
|
||||||
mailController.clear();
|
mailController.clear();
|
||||||
passwordController.clear();
|
passwordController.clear();
|
||||||
nameController.clear();
|
nameController.clear();
|
||||||
@ -133,8 +142,14 @@ class LoginController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> logout() async {
|
Future<void> logout() async {
|
||||||
await _account.value!.deleteSession(sessionId: 'current');
|
await _account.value!.deleteSession(sessionId: 'current');
|
||||||
_logedInUser.value = null;
|
_logedInUser.value = null;
|
||||||
|
Get.snackbar(
|
||||||
|
'Erfolg',
|
||||||
|
'Logout erfolgreich',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
backgroundColor: Colors.red.shade500,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -144,5 +159,8 @@ class LoginController extends GetxController {
|
|||||||
nameController.dispose();
|
nameController.dispose();
|
||||||
super.onClose();
|
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';
|
import '../../controllers/input_controller.dart';
|
||||||
|
|
||||||
class InputPage extends GetView<InputController> {
|
class InputPage extends GetView<InputController> {
|
||||||
const InputPage({super.key});
|
const InputPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
var inputCtrl = controller;
|
||||||
body: Container(),
|
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(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
IconButton(
|
||||||
Icons.local_gas_station,
|
icon: const Icon(Icons.local_gas_station),
|
||||||
size: 100,
|
iconSize: 100,
|
||||||
|
onPressed: ()=> logCtrl.logout(),
|
||||||
color: Colors.grey.shade300,
|
color: Colors.grey.shade300,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import '../bindings/input_binding.dart';
|
||||||
import '../bindings/login_binding.dart';
|
import '../bindings/login_binding.dart';
|
||||||
import '../pages/examples/geolocation_example.dart';
|
import '../pages/input/input_view.dart';
|
||||||
import '../bindings/geolocation_binding.dart';
|
|
||||||
import '../pages/login/login_view.dart';
|
import '../pages/login/login_view.dart';
|
||||||
|
|
||||||
/// App Routes Konfiguration
|
/// App Routes Konfiguration
|
||||||
class AppRoutes {
|
class AppRoutes {
|
||||||
static const String home = '/';
|
|
||||||
static const String geolocation = '/geolocation';
|
|
||||||
static const String login = '/login';
|
static const String login = '/login';
|
||||||
|
static const String listPage = '/list-page';
|
||||||
|
static const String inputPage = '/input-page';
|
||||||
|
|
||||||
/// Route Pages Definition
|
/// Route Pages Definition
|
||||||
static List<GetPage> pages = [
|
static List<GetPage> pages = [
|
||||||
GetPage(
|
GetPage(
|
||||||
name: geolocation,
|
name: login,
|
||||||
page: () => const GeolocationExample(),
|
page: () => const LoginPage(),
|
||||||
binding: GeolocationBinding(), // Dependency Injection
|
binding: LoginBinding(), // Dependency Injection
|
||||||
transition: Transition.cupertino,
|
transition: Transition.cupertino,
|
||||||
transitionDuration: const Duration(milliseconds: 300),
|
transitionDuration: const Duration(milliseconds: 300),
|
||||||
),
|
),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: login,
|
name: inputPage,
|
||||||
page: () => const LoginPage(),
|
page: () => const InputPage(),
|
||||||
binding: LoginBinding(), // Dependency Injection
|
binding: InputBinding(), // Dependency Injection
|
||||||
transition: Transition.cupertino,
|
transition: Transition.cupertino,
|
||||||
transitionDuration: const Duration(milliseconds: 300),
|
transitionDuration: const Duration(milliseconds: 300),
|
||||||
),
|
),
|
||||||
@ -34,23 +34,12 @@ class AppRoutes {
|
|||||||
// static const String geolocationExample = '/geolocation-example';
|
// static const String geolocationExample = '/geolocation-example';
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
/// Navigation Helper Klasse
|
/// Navigation Helper Klasse
|
||||||
class AppNavigation {
|
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
|
/// Navigate to Login Page
|
||||||
static void toLogin() {
|
static void toLogin() {
|
||||||
Get.toNamed(AppRoutes.login);
|
Get.toNamed(AppRoutes.login);
|
||||||
@ -63,6 +52,17 @@ class AppNavigation {
|
|||||||
static void offAllToLogin() {
|
static void offAllToLogin() {
|
||||||
Get.offAllNamed(AppRoutes.login);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
pubspec.lock
16
pubspec.lock
@ -37,10 +37,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: characters
|
name: characters
|
||||||
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
|
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.4.1"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -332,18 +332,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.11.1"
|
version: "0.13.0"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
|
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.16.0"
|
version: "1.17.0"
|
||||||
package_info_plus:
|
package_info_plus:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -497,10 +497,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
|
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.6"
|
version: "0.7.7"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user