diff --git a/lib/routes.dart b/lib/routes.dart index 12464bbf..f26e18b8 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -10,9 +10,9 @@ import './screens/my_schedule_screen.dart'; import './screens/patients/patient_search_screen.dart'; import './screens/patients/patients_list_screen.dart'; -const String INIT_ROUTE = 'login'; const String HOME = '/'; const String LOGIN = 'login'; +const String INIT_ROUTE = LOGIN; const String MY_SCHEDULE = 'my-schedule'; const String QR_READER = 'qr_reader'; const String PATIENT_SEARCH = 'patients/patient-search'; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 62aae00b..f0140f80 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,10 +1,30 @@ +import 'package:shared_preferences/shared_preferences.dart'; + import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/login_form.dart'; import 'package:flutter/material.dart'; +import 'dart:async'; class Loginsreen extends StatelessWidget { + // Future pref = SharedPreferences.getInstance(); + Future _prefs = SharedPreferences.getInstance(); + // final SharedPreferences prefs = await _prefs; + + Future _incrementCounter() async { + final SharedPreferences prefs = await _prefs; + final int counter = (prefs.getInt('counter') ?? 0) + 1; + var x = prefs.getInt('counter22222'); + // setState(() { + print(x); + prefs.setInt("counter", counter).then((bool success) { + return counter; + // }); + }); + } @override Widget build(BuildContext context) { + // prefs.setInt("counter", 1); + _incrementCounter(); return Scaffold( backgroundColor: Colors.white, body: SingleChildScrollView( diff --git a/lib/widgets/shared/app.drawer.dart b/lib/widgets/shared/app.drawer.dart index 971804fe..823b8e26 100644 --- a/lib/widgets/shared/app.drawer.dart +++ b/lib/widgets/shared/app.drawer.dart @@ -1,17 +1,34 @@ +import 'package:shared_preferences/shared_preferences.dart'; + import '../../routes.dart'; import 'package:flutter/material.dart'; import '../../i18n/ar.i18n.dart' as ar; import '../../i18n/en.i18n.dart' as en; class AppDrawer extends StatelessWidget { - ar.Ar arLang = ar.Ar(); - en.En enLang = en.En(); + ar.Ar arLang = ar.Ar(); + en.En enLang = en.En(); + + Future _prefs = SharedPreferences.getInstance(); + // final SharedPreferences prefs = await _prefs; + + Future getCounter() async { + final SharedPreferences prefs = await _prefs; + final int counter = (prefs.getInt('counter') ?? 0); + print("dddddd" + prefs.getInt('counter').toString()); + // setState(() { + // prefs.setInt("counter", counter).then((bool success) { + // print(counter); + // return counter; + // // }); + // }); + } + @override Widget build(BuildContext context) { - - print(arLang.button.save); - print(enLang.button.save); - + print(arLang.button.save); + print(enLang.button.save); + getCounter(); return Drawer( child: Column( children: [ @@ -37,7 +54,7 @@ class AppDrawer extends StatelessWidget { ListTile( title: Text('Settings'), leading: Icon(Icons.settings), - onTap: () { + onTap: () { drawerNavigator(context, SETTINGS); }, ), @@ -54,7 +71,7 @@ class AppDrawer extends StatelessWidget { title: Text('Log Out'), leading: Icon(Icons.exit_to_app), onTap: () { - drawerNavigator(context, LOGIN); + drawerNavigator(context, LOGIN); }, ) ], diff --git a/pubspec.lock b/pubspec.lock index befdb1a1..7c920531 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -207,6 +207,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" glob: dependency: transitive description: @@ -438,6 +443,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.4+2" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.6+3" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+6" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+4" shelf: dependency: transitive description: @@ -564,3 +597,4 @@ packages: version: "2.2.0" sdks: dart: ">=2.7.0 <3.0.0" + flutter: ">=1.12.13+hotfix.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 86dc2163..c5067eb7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: http: ^0.12.0+4 provider: ^3.0.0 i18n: any + shared_preferences: ^0.5.6+3 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.