You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/widgets/drawer/app_drawer_widget.dart

389 lines
20 KiB
Dart

4 years ago
import 'dart:io';
4 years ago
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
4 years ago
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
4 years ago
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart';
import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notifications_page.dart';
import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:flutter/material.dart';
4 years ago
import 'package:provider/provider.dart';
4 years ago
import 'package:smart_progress_bar/smart_progress_bar.dart';
4 years ago
import 'package:url_launcher/url_launcher.dart';
import '../../config/size_config.dart';
import '../../locator.dart';
import 'drawer_item_widget.dart';
class AppDrawer extends StatefulWidget {
@override
_AppDrawerState createState() => _AppDrawerState();
}
class _AppDrawerState extends State<AppDrawer> {
4 years ago
@override
void initState() {
super.initState();
checkUserData();
}
4 years ago
ProjectViewModel projectProvider;
4 years ago
var sharedPref = new AppSharedPreferences();
var familyFileProvider = FamilyFilesProvider();
4 years ago
AuthenticatedUser user;
4 years ago
AuthenticatedUser mainUser;
4 years ago
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
projectProvider = Provider.of(context);
return SizedBox(
width: MediaQuery.of(context).size.width * 0.75,
child: Container(
color: Colors.white,
child: Drawer(
child: Column(
children: <Widget>[
Expanded(
flex: 4,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Container(
4 years ago
height: SizeConfig.screenHeight * .30,
child: InkWell(
child: DrawerHeader(
child: Column(
children: <Widget>[
Container(
4 years ago
child: Image.asset('assets/images/DQ/DQ_logo.png'),
margin: EdgeInsets.all(SizeConfig.imageSizeMultiplier * 4),
),
4 years ago
(user != null && projectProvider.isLogin)
4 years ago
? Padding(
padding: EdgeInsets.all(15),
4 years ago
child: Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
Row(
4 years ago
children: <Widget>[
4 years ago
Padding(
padding: EdgeInsets.only(right: 5),
child: Icon(
Icons.account_circle,
4 years ago
color: Color(0xFF40ACC9),
4 years ago
)),
AppText(
user.firstName + ' ' + user.lastName,
color: Color(0xFF40ACC9),
)
],
),
Row(children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 30, top: 5),
child: Column(
children: <Widget>[
AppText(
TranslationBase.of(context).fileno + ": " + user.patientID.toString(),
color: Color(0xFF40ACC9),
fontSize: SizeConfig.textMultiplier * 1.5,
),
AppText(
user.bloodGroup != null ? 'Blood Group: ' + user.bloodGroup : '',
fontSize: SizeConfig.textMultiplier * 1.5,
),
],
))
])
]))
4 years ago
: SizedBox(),
],
),
),
),
),
4 years ago
Column(
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
children: <Widget>[
InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).arabicChange, Icons.translate),
4 years ago
onTap: () {
4 years ago
// Navigator.of(context).pushNamed(
// WELCOME_LOGIN,
// );
if (projectProvider.isArabic) {
projectProvider.changeLanguage('en');
} else {
projectProvider.changeLanguage('ar');
}
4 years ago
},
),
4 years ago
(user != null && projectProvider.isLogin)
4 years ago
? Column(
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
children: <Widget>[
4 years ago
InkWell(
child: DrawerItem(
TranslationBase.of(context).family,
Icons.group,
4 years ago
textColor: Color(0xFF40ACC9),
iconColor: Color(0xFF40ACC9),
bottomLine: false,
sideArrow: true,
4 years ago
),
onTap: () {
Navigator.of(context).pushNamed(
MY_FAMILIY,
);
},
),
FutureBuilder(
future: getFamilyFiles(), // async work
4 years ago
builder: (BuildContext context, AsyncSnapshot<GetAllSharedRecordsByStatusResponse> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
4 years ago
return Padding(padding: EdgeInsets.all(10), child: Text('Loading....'));
default:
if (snapshot.hasError)
4 years ago
return Padding(padding: EdgeInsets.all(10), child: Text(snapshot.error));
else
return Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
// <--- left side
color: Colors.grey[200],
width: 1.0,
),
)),
child: Column(
4 years ago
children: [
user.isFamily == true
? Container(
4 years ago
padding: EdgeInsets.only(bottom: 5),
4 years ago
child: InkWell(
onTap: () {
4 years ago
switchUser(mainUser, context);
4 years ago
},
child: Row(
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
4 years ago
Expanded(
4 years ago
child: Icon(Icons.person),
4 years ago
),
Expanded(
flex: 7,
4 years ago
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
AppText(mainUser.firstName + ' ' + mainUser.lastName),
AppText(TranslationBase.of(context).fileno + ": " + mainUser.patientID.toString()),
])),
4 years ago
],
)))
: SizedBox(),
Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: snapshot.data.getAllSharedRecordsByStatusList.map<Widget>((result) {
return result.status == 3
4 years ago
? Container(
4 years ago
padding: EdgeInsets.only(bottom: 5),
4 years ago
child: InkWell(
onTap: () {
4 years ago
switchUser(result, context);
4 years ago
},
child: Row(
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
4 years ago
Expanded(
4 years ago
child: Icon(Icons.person, color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black),
4 years ago
),
Expanded(
flex: 7,
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
AppText(result.patientName, color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black),
4 years ago
AppText(TranslationBase.of(context).fileno + ": " + result.iD.toString(),
color: result.responseID == user.patientID ? Color(0xFF40ACC9) : Colors.black),
])),
4 years ago
],
)))
: SizedBox();
}).toList())
],
));
}
},
),
4 years ago
InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).notification, Icons.notifications),
4 years ago
onTap: () {
4 years ago
//NotificationsPage
Navigator.of(context).pop();
4 years ago
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => NotificationsPage()));
4 years ago
},
),
InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).appsetting, Icons.settings_input_composite),
4 years ago
onTap: () {
Navigator.of(context).pushNamed(
4 years ago
SETTINGS,
4 years ago
);
},
),
InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).rateApp, Icons.star),
4 years ago
onTap: () {
4 years ago
if (Platform.isIOS) {
4 years ago
launch("https://apps.apple.com/sa/app/dr-suliaman-alhabib/id733503978");
4 years ago
} else {
4 years ago
launch("https://play.google.com/store/apps/details?id=com.ejada.hmg&hl=en");
4 years ago
}
4 years ago
},
),
InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).logout, Icons.lock_open),
4 years ago
onTap: () {
logout();
},
)
],
)
: InkWell(
4 years ago
child: DrawerItem(TranslationBase.of(context).loginregister, Icons.lock_open),
4 years ago
onTap: () {
4 years ago
login();
4 years ago
},
),
],
)
],
),
),
Expanded(
flex: 1,
child: Column(
children: <Widget>[
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Container(
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: <Widget>[
Text(TranslationBase.of(context).poweredBy),
Image.asset(
'assets/images/cs_logo_container.png',
width: SizeConfig.imageSizeMultiplier * 30,
)
],
),
Column(
children: <Widget>[
Image.asset(
'assets/images/new-design/vidamobile.png',
width: SizeConfig.imageSizeMultiplier * 25,
)
],
),
],
),
),
),
)
],
),
)
],
),
),
),
);
}
drawerNavigator(context, routeName) {
Navigator.of(context).pushNamed(routeName);
}
4 years ago
checkUserData() async {
4 years ago
if (await this.sharedPref.getObject(USER_PROFILE) != null) {
4 years ago
var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
4 years ago
4 years ago
var data2 = AuthenticatedUser.fromJson(await this.sharedPref.getObject(MAIN_USER));
4 years ago
print(data2);
4 years ago
setState(() {
this.user = data;
4 years ago
this.mainUser = data2;
4 years ago
});
}
4 years ago
}
logout() async {
authenticatedUserObject.logout();
4 years ago
projectProvider.isLogin = false;
await authenticatedUserObject.getUser();
4 years ago
await sharedPref.clear();
4 years ago
this.user = null;
Navigator.of(context).pushNamed(HOME);
4 years ago
projectProvider.platformBridge().unRegisterHmgGeofences();
4 years ago
}
4 years ago
login() async {
var data = await sharedPref.getObject(IMEI_USER_DATA);
sharedPref.remove(REGISTER_DATA_FOR_LOGIIN);
4 years ago
if (data != null) {
Navigator.of(context).pushNamed(CONFIRM_LOGIN);
} else {
Navigator.of(context).pushNamed(
WELCOME_LOGIN,
);
}
}
Future<GetAllSharedRecordsByStatusResponse> getFamilyFiles() async {
4 years ago
if (user != null) {
if (await sharedPref.getObject(FAMILY_FILE) != null) {
// print(await sharedPref.getObject(FAMILY_FILE));
4 years ago
return Future.value(GetAllSharedRecordsByStatusResponse.fromJson(await sharedPref.getObject(FAMILY_FILE)));
4 years ago
} else {
return familyFileProvider.getSharedRecordByStatus();
}
}
}
switchUser(user, context) {
Utils.showProgressDialog(context);
4 years ago
this.familyFileProvider.silentLoggin(user is AuthenticatedUser ? null : user, mainUser: user is AuthenticatedUser).then((value) => loginAfter(value, context)).catchError((err) {
4 years ago
print(err);
AppToast.showErrorToast(message: err);
Navigator.of(context).pop();
4 years ago
}).showProgressBar(text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
}
4 years ago
loginAfter(result, context) async {
Utils.hideProgressDialog();
result = CheckActivationCode.fromJson(result);
4 years ago
var familyFile = await sharedPref.getObject(FAMILY_FILE);
var mainUser = await sharedPref.getObject(MAIN_USER);
this.sharedPref.clear();
4 years ago
if (mainUser["PatientID"] != result.list.patientID) {
result.list.isFamily = true;
}
this.sharedPref.setObject(MAIN_USER, mainUser);
this.sharedPref.setObject(USER_PROFILE, result.list);
4 years ago
this.sharedPref.setObject(FAMILY_FILE, familyFile);
this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID);
this.sharedPref.setString(TOKEN, result.authenticationTokenID);
//this.checkIfUserAgreedBefore(result),
Navigator.of(context).pushNamed(
HOME,
);
}
}