/* This is account page we used AutomaticKeepAliveClientMixin to keep the state when moving from 1 navbar to another navbar, so the page is not refresh overtime */ import 'package:mobdr/config/constant.dart'; import 'package:mobdr/config/global_style.dart'; import 'package:mobdr/service/shared_prefs.dart'; import 'package:mobdr/ui/account/about.dart'; import 'package:mobdr/ui/account/settings.dart'; import 'package:mobdr/ui/account/log.dart'; import 'package:mobdr/ui/general/notification.dart'; import 'package:mobdr/ui/reusable/reusable_widget.dart'; import 'package:flutter/material.dart'; import 'package:mobdr/ui/authentication/signin.dart'; import 'dart:convert'; import 'package:mobdr/main.dart'; class TabAccountPage extends StatefulWidget { @override _TabAccountPageState createState() => _TabAccountPageState(); } class _TabAccountPageState extends State with AutomaticKeepAliveClientMixin { // initialize reusable widget final _reusableWidget = ReusableWidget(); Image imageFromBase64String() { String base64String = objectbox.getUserAvatar(SharedPrefs().id_utilisateur); return Image.memory(base64Decode(base64String)); } @override bool get wantKeepAlive => true; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { // if we used AutomaticKeepAliveClientMixin, we must call super.build(context); super.build(context); return Scaffold( appBar: AppBar( iconTheme: IconThemeData( color: GlobalStyle.appBarIconThemeColor, ), elevation: GlobalStyle.appBarElevation, title: Text( 'Account', style: GlobalStyle.appBarTitle, ), backgroundColor: GlobalStyle.appBarBackgroundColor, systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle, actions: [ IconButton( icon: _reusableWidget.customNotifIcon( count: 0, notifColor: BLACK_GREY), onPressed: () { Navigator.push( context, MaterialPageRoute( builder: (context) => NotificationPage())); }), ], bottom: _reusableWidget.bottomAppBar(), ), body: ListView( padding: EdgeInsets.all(16), children: [ _createAccountInformation(), _createListMenu('Settings', SettingsPage()), _reusableWidget.divider1(), _createListMenu('About', AboutPage()), _reusableWidget.divider1(), _createListMenu('Show logs', LogPage()), _reusableWidget.divider1(), Container( margin: EdgeInsets.fromLTRB(0, 18, 0, 0), child: GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { Navigator.pushAndRemoveUntil( context, PageRouteBuilder(pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { return SigninPage(); }, transitionsBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { return new SlideTransition( position: new Tween( begin: const Offset(1.0, 0.0), end: Offset.zero, ).animate(animation), child: child, ); }), (Route route) => false); }, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.power_settings_new, size: 20, color: ASSENT_COLOR), SizedBox(width: 8), Text('Sign Out', style: TextStyle(fontSize: 15, color: ASSENT_COLOR)), ], ), ), ), ], )); } Widget _createAccountInformation() { final double profilePictureSize = MediaQuery.of(context).size.width / 4; return Container( margin: EdgeInsets.only(bottom: 14), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: profilePictureSize, height: profilePictureSize, child: CircleAvatar( backgroundColor: Colors.grey[200], radius: profilePictureSize, child: CircleAvatar( backgroundColor: Colors.white, radius: profilePictureSize - 4, child: Hero( tag: 'profilePicture', child: ClipOval(child: imageFromBase64String()), ), ), ), ), SizedBox( width: 16, ), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("${SharedPrefs().prenom} ${SharedPrefs().nom}", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), SizedBox( height: 8, ), ], ), ) ], ), ); } Widget _createListMenu(String menuTitle, StatefulWidget page) { return GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => page)); }, child: Container( margin: EdgeInsets.fromLTRB(0, 18, 0, 18), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(menuTitle, style: TextStyle(fontSize: 15, color: CHARCOAL)), Icon(Icons.chevron_right, size: 20, color: SOFT_GREY), ], ), ), ); } }