first step from dealing with shared preferences

merge-requests/1/merge
Elham Rababah 5 years ago
parent 36fa0c5a2f
commit da3cc456ba

@ -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';

@ -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<SharedPreferences> pref = SharedPreferences.getInstance();
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
// final SharedPreferences prefs = await _prefs;
Future<void> _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(

@ -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<SharedPreferences> _prefs = SharedPreferences.getInstance();
// final SharedPreferences prefs = await _prefs;
Future<void> 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: <Widget>[
@ -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);
},
)
],

@ -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"

@ -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.

Loading…
Cancel
Save