From a14e1489fe75980286159a94d2707b921f11df1c Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 12 Apr 2020 16:40:38 +0300 Subject: [PATCH] optimize Scaffold widget and make options customized --- lib/screens/auth/change_password_screen.dart | 4 +- lib/screens/auth/login_screen.dart | 4 +- .../auth/verification_methods_screen.dart | 4 +- lib/screens/auth/verify_account_screen.dart | 4 +- lib/screens/dashboard_screen.dart | 49 +---------- lib/screens/home_screen.dart | 31 ------- lib/widgets/shared/app.drawer.dart | 85 ------------------- lib/widgets/shared/app_scaffold_widget.dart | 70 +++++++++++++++ 8 files changed, 86 insertions(+), 165 deletions(-) delete mode 100644 lib/screens/home_screen.dart delete mode 100644 lib/widgets/shared/app.drawer.dart create mode 100644 lib/widgets/shared/app_scaffold_widget.dart diff --git a/lib/screens/auth/change_password_screen.dart b/lib/screens/auth/change_password_screen.dart index 2c15cffa..dc57b99d 100644 --- a/lib/screens/auth/change_password_screen.dart +++ b/lib/screens/auth/change_password_screen.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/lookups/auth_lookup.dart'; import 'package:doctor_app_flutter/widgets/auth/auth_header.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import '../../widgets/auth/change_password.dart'; @@ -8,7 +9,8 @@ class ChangePasswordScreen extends StatelessWidget { Widget build(BuildContext context) { // return Container()]; - return Scaffold( + return AppScaffold( + pageOnly: true, body: SafeArea( child: ListView(children: [ Container( diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index de1f94f7..97fde198 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -41,7 +42,8 @@ class _LoginsreenState extends State { @override Widget build(BuildContext context) { getSharedPref(); - return Scaffold( + return AppScaffold( + pageOnly: true, body: SafeArea( child: ListView(children: [ FutureBuilder( diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index f0e39210..cde03171 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import '../../lookups/auth_lookup.dart'; @@ -15,7 +16,8 @@ class VerificationMethodsScreen extends StatelessWidget { @override Widget build(BuildContext context) { // return Container()]; - return Scaffold( + return AppScaffold( + pageOnly: true, body: ListView(children: [ Container( margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), diff --git a/lib/screens/auth/verify_account_screen.dart b/lib/screens/auth/verify_account_screen.dart index 752a5b7c..1b068524 100644 --- a/lib/screens/auth/verify_account_screen.dart +++ b/lib/screens/auth/verify_account_screen.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import '../../lookups/auth_lookup.dart'; @@ -8,7 +9,8 @@ class VerifyAccountScreen extends StatelessWidget { @override Widget build(BuildContext context) { // return Container()]; - return Scaffold( + return AppScaffold( + pageOnly: true, body: SafeArea( child: ListView(children: [ Container( diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index 25ff04d4..4a286cde 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; @@ -19,51 +20,9 @@ class DashboardScreen extends StatefulWidget { class _DashboardScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - elevation: 0, - backgroundColor: Colors.red[100], - textTheme: TextTheme( - title: - TextStyle(color: Colors.black, fontWeight: FontWeight.bold)), - title: Text('Home'), - leading: Builder(builder: (BuildContext context) { - return new GestureDetector( - onTap: () { - Scaffold.of(context).openDrawer(); - }, - child: IconButton( - icon: Icon(Icons.menu), - color: Colors.black, - onPressed: () => Scaffold.of(context).openDrawer(), - ), - ); - }), - centerTitle: true, - actions: [ - IconButton(icon: Icon(Icons.person), onPressed: null) - ], - ), - drawer: Theme( - data: Theme.of(context).copyWith( - canvasColor: Colors.transparent, - ), - child: SafeArea(child: AppDrawer()), - ), - // , - bottomNavigationBar: BottomNavigationBar(items: [ - BottomNavigationBarItem( - icon: Icon(DoctorApp.home_icon), - title: Text('Home'), - backgroundColor: Colors.red, - activeIcon: Icon(Icons.home)), - BottomNavigationBarItem( - icon: new Icon(Icons.mail), - title: new Text('Messages'), - ), - BottomNavigationBarItem(icon: Icon(Icons.apps), title: Text('Menu')) - ]), - body: Container( + return AppScaffold( + appBarTitle:'Home', + body: Container( decoration: new BoxDecoration( gradient: LinearGradient( colors: [Colors.red[100], Colors.white], diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart deleted file mode 100644 index 704d8be4..00000000 --- a/lib/screens/home_screen.dart +++ /dev/null @@ -1,31 +0,0 @@ -import '../lookups/home_items_lookup.dart'; -import '../routes.dart'; - -import '../widgets/home/home_item.dart'; -import '../widgets/shared/app.drawer.dart'; -import 'package:flutter/material.dart'; - - - -class HomeScreen extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('Home'), - ), - drawer: AppDrawer(), - body: GridView( - padding: EdgeInsets.all(25), - children: DUMMY_CATEGORIES - .map((data) => - HomeItem(data.id, data.title, data.image, data.link)) - .toList(), - gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( - maxCrossAxisExtent: 200, - childAspectRatio: 3 / 2, - crossAxisSpacing: 20, - mainAxisSpacing: 20)), - ); - } -} diff --git a/lib/widgets/shared/app.drawer.dart b/lib/widgets/shared/app.drawer.dart deleted file mode 100644 index 823b8e26..00000000 --- a/lib/widgets/shared/app.drawer.dart +++ /dev/null @@ -1,85 +0,0 @@ -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(); - - 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); - getCounter(); - return Drawer( - child: Column( - children: [ - AppBar( - title: Text('Hi form Elham!!'), - ), - ListTile( - title: Text('Home'), - leading: Icon(Icons.tab), - onTap: () { - drawerNavigator(context, HOME); - }, - ), - Divider(), - ListTile( - title: Text('My Schedule'), - leading: Icon(Icons.tab), - onTap: () { - drawerNavigator(context, MY_SCHEDULE); - }, - ), - Divider(), - ListTile( - title: Text('Settings'), - leading: Icon(Icons.settings), - onTap: () { - drawerNavigator(context, SETTINGS); - }, - ), - Divider(), - ListTile( - title: Text('QR Reader'), - leading: Icon(Icons.photo), - onTap: () { - drawerNavigator(context, QR_READER); - }, - ), - Divider(), - ListTile( - title: Text('Log Out'), - leading: Icon(Icons.exit_to_app), - onTap: () { - drawerNavigator(context, LOGIN); - }, - ) - ], - ), - ); - } - - drawerNavigator(context, routeName) { - Navigator.of(context).pushNamed(routeName); - } -} diff --git a/lib/widgets/shared/app_scaffold_widget.dart b/lib/widgets/shared/app_scaffold_widget.dart new file mode 100644 index 00000000..373c94c6 --- /dev/null +++ b/lib/widgets/shared/app_scaffold_widget.dart @@ -0,0 +1,70 @@ +import '../../presentation/doctor_app_icons.dart'; +import '../../widgets/shared/app_drawer_widget.dart'; +import 'package:flutter/material.dart'; + +class AppScaffold extends StatelessWidget { + AppScaffold( + {this.pageOnly, + this.appBarTitle, + this.showAppBar, + this.showBottomBar, + this.showAppDrawer, + this.body}); + bool pageOnly = false; + // bool showAll = + bool showAppBar = true; + bool showAppDrawer = true; + bool showBottomBar = true; + String appBarTitle; + Widget body; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: (pageOnly == true || showAppBar == false)?null:AppBar( + + elevation: 0, + backgroundColor: Colors.red[100], + textTheme: TextTheme( + title: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)), + title: Text(appBarTitle), + leading: Builder(builder: (BuildContext context) { + return new GestureDetector( + onTap: () { + Scaffold.of(context).openDrawer(); + }, + child: IconButton( + icon: Icon(Icons.menu), + color: Colors.black, + onPressed: () => Scaffold.of(context).openDrawer(), + ), + ); + }), + centerTitle: true, + actions: [ + IconButton(icon: Icon(Icons.person), onPressed: null) + ], + ), + drawer: (pageOnly == true || showAppDrawer == false)?null:Theme( + data: Theme.of(context).copyWith( + canvasColor: Colors.transparent, + ), + child: SafeArea(child: AppDrawer()), + ), + // , + bottomNavigationBar: (pageOnly == true || showBottomBar == false)?null: BottomNavigationBar(items: [ + BottomNavigationBarItem( + icon: Icon(DoctorApp.home_icon), + title: Text('Home'), + backgroundColor: Colors.red, + activeIcon: Icon(Icons.home)), + BottomNavigationBarItem( + icon: new Icon(Icons.mail), + title: new Text('Messages'), + ), + BottomNavigationBarItem(icon: Icon(Icons.apps), title: Text('Menu')) + ]), + body: body, + ); + } +}