From dd524bcbd10aeb424e90b37b30ad878a88eb316f Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 10 Oct 2023 12:39:25 +0300 Subject: [PATCH] Merged with Majd --- lib/main.dart | 4 +- .../common_widgets/app_bar/home_app_bar.dart | 53 +++++------ ...m_nav_bar.dart => app_bottom_nav_bar.dart} | 30 +++---- lib/new_views/common_widgets/app_drawer.dart | 1 + ...g_button.dart => app_floating_button.dart} | 7 +- .../common_widgets/pagination_bar.dart | 0 lib/new_views/common_widgets/test screen.dart | 46 ---------- .../pages/land_page/dashboard_page.dart | 72 +++++++++++++++ lib/new_views/pages/land_page/land_page.dart | 90 ++++++------------- 9 files changed, 143 insertions(+), 160 deletions(-) rename lib/new_views/common_widgets/{bottom_nav_bar/home_bottom_nav_bar.dart => app_bottom_nav_bar.dart} (62%) rename lib/new_views/common_widgets/{add_floating_button.dart => app_floating_button.dart} (52%) delete mode 100644 lib/new_views/common_widgets/pagination_bar.dart delete mode 100644 lib/new_views/common_widgets/test screen.dart create mode 100644 lib/new_views/pages/land_page/dashboard_page.dart diff --git a/lib/main.dart b/lib/main.dart index bba51090..c5286619 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,7 +12,6 @@ import 'package:test_sa/new_views/pages/splash_page.dart'; import 'controllers/providers/api/user_provider.dart'; import 'controllers/providers/settings/setting_provider.dart'; -import 'new_views/common_widgets/test screen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -62,9 +61,8 @@ class MyApp extends StatelessWidget { ], supportedLocales: const [Locale('en'), Locale('ar')], locale: Locale(settingProvider.language ?? 'en'), - initialRoute: TestScreen.id, + initialRoute: SplashPage.routeName, routes: { - TestScreen.id: (_) => const TestScreen(), SplashPage.routeName: (_) => const SplashPage(), LoginPage.routeName: (_) => const LoginPage(), LandPage.routeName: (_) => const LandPage(), diff --git a/lib/new_views/common_widgets/app_bar/home_app_bar.dart b/lib/new_views/common_widgets/app_bar/home_app_bar.dart index e58852a0..41c4156a 100644 --- a/lib/new_views/common_widgets/app_bar/home_app_bar.dart +++ b/lib/new_views/common_widgets/app_bar/home_app_bar.dart @@ -2,14 +2,12 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:test_sa/new_views/common_widgets/app_bar/user_image.dart'; -import '../../../models/user.dart'; -import '../../app_style/app_color.dart'; import 'notification_icon.dart'; -class HomeAppBar extends StatefulWidget implements PreferredSizeWidget{ - int notificationCount; - String userImage; - HomeAppBar({Key key, this.notificationCount}) : super(key: key); +class HomeAppBar extends StatefulWidget implements PreferredSizeWidget { + final int notificationCount; + final String userImage; + const HomeAppBar({Key key, this.notificationCount, this.userImage}) : super(key: key); @override State createState() => _AppBarState(); @@ -25,26 +23,29 @@ class _AppBarState extends State { padding: const EdgeInsets.only(top: 30.0, right: 12, left: 12), child: PreferredSize( child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - UserImage(url: widget.userImage,), - NotificationIcon(notificationCount: 3,) - ], - ), - // SizedBox(height: 15), - // Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Text("welcome," , style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w500, color: AppColor.neutral20)), - // Text("Engineer name" , style: Theme.of(context).textTheme.headlineMedium?.copyWith(fontWeight: FontWeight.w600)), - // ], - // ) - ], - ), - + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + UserImage( + url: widget.userImage, + ), + NotificationIcon( + notificationCount: 3, + ) + ], + ), + // SizedBox(height: 15), + // Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Text("welcome," , style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w500, color: AppColor.neutral20)), + // Text("Engineer name" , style: Theme.of(context).textTheme.headlineMedium?.copyWith(fontWeight: FontWeight.w600)), + // ], + // ) + ], + ), ), ); } diff --git a/lib/new_views/common_widgets/bottom_nav_bar/home_bottom_nav_bar.dart b/lib/new_views/common_widgets/app_bottom_nav_bar.dart similarity index 62% rename from lib/new_views/common_widgets/bottom_nav_bar/home_bottom_nav_bar.dart rename to lib/new_views/common_widgets/app_bottom_nav_bar.dart index d10ccbb1..e78cb501 100644 --- a/lib/new_views/common_widgets/bottom_nav_bar/home_bottom_nav_bar.dart +++ b/lib/new_views/common_widgets/app_bottom_nav_bar.dart @@ -2,18 +2,18 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:test_sa/extensions/context_extension.dart'; -import '../../../models/enums/translation_keys.dart'; -import '../../app_style/app_color.dart'; +import '../../models/enums/translation_keys.dart'; +import '../app_style/app_color.dart'; -class HomeBottomNavigationBar extends StatefulWidget { - final Function(int index) onPressed; - const HomeBottomNavigationBar({Key key, @required this.onPressed}) : super(key: key); +class AppBottomNavigationBar extends StatefulWidget { + final Function(int index) onPressed; + const AppBottomNavigationBar({Key key, @required this.onPressed}) : super(key: key); @override - State createState() => _HomeBottomNavigationBarState(); + State createState() => _AppBottomNavigationBarState(); } -class _HomeBottomNavigationBarState extends State { +class _AppBottomNavigationBarState extends State { int _selectedIndex = 0; void _onItemTapped(int index) { @@ -27,31 +27,27 @@ class _HomeBottomNavigationBarState extends State { Widget build(BuildContext context) { return Material( elevation: 20, - borderRadius: const BorderRadius.only(topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), + borderRadius: const BorderRadius.only(topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), child: SizedBox( height: 100, child: ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(20.0)), child: BottomNavigationBar( - items: [ + items: [ BottomNavigationBarItem( - icon: SvgPicture.asset('assets/images/Overview.svg', width: 24, height: 24, - color: _selectedIndex == 0? AppColor.primary70:AppColor.neutral20), + icon: SvgPicture.asset('assets/images/Overview.svg', width: 24, height: 24, color: _selectedIndex == 0 ? AppColor.primary70 : AppColor.neutral20), label: context.translate(TranslationKeys.overview), ), BottomNavigationBarItem( - icon: SvgPicture.asset('assets/images/requests.svg', width: 24, height: 24, - color: _selectedIndex == 1? AppColor.primary70:AppColor.neutral20), + icon: SvgPicture.asset('assets/images/requests.svg', width: 24, height: 24, color: _selectedIndex == 1 ? AppColor.primary70 : AppColor.neutral20), label: context.translate(TranslationKeys.myRequest), ), BottomNavigationBarItem( - icon: SvgPicture.asset('assets/images/assets.svg',width: 24, height: 24, - color: _selectedIndex == 2? AppColor.primary70:AppColor.neutral20), + icon: SvgPicture.asset('assets/images/assets.svg', width: 24, height: 24, color: _selectedIndex == 2 ? AppColor.primary70 : AppColor.neutral20), label: context.translate(TranslationKeys.myRequest), ), BottomNavigationBarItem( - icon: SvgPicture.asset('assets/images/message.svg', width: 24, height: 24, - color: _selectedIndex == 3? AppColor.primary70:AppColor.neutral20), + icon: SvgPicture.asset('assets/images/message.svg', width: 24, height: 24, color: _selectedIndex == 3 ? AppColor.primary70 : AppColor.neutral20), label: context.translate(TranslationKeys.contactUs), ), ], diff --git a/lib/new_views/common_widgets/app_drawer.dart b/lib/new_views/common_widgets/app_drawer.dart index 4ec65514..064fe633 100644 --- a/lib/new_views/common_widgets/app_drawer.dart +++ b/lib/new_views/common_widgets/app_drawer.dart @@ -21,6 +21,7 @@ class AppDrawer extends StatelessWidget { AppFilledButton( label: TranslationKeys.login, onPressed: () async { + /// TODO [zaid] : show dialog before logout // bool result = await showDialog( // context: context, // builder: (_) => const AAlertDialog( diff --git a/lib/new_views/common_widgets/add_floating_button.dart b/lib/new_views/common_widgets/app_floating_button.dart similarity index 52% rename from lib/new_views/common_widgets/add_floating_button.dart rename to lib/new_views/common_widgets/app_floating_button.dart index e7efbfba..0f48cde3 100644 --- a/lib/new_views/common_widgets/add_floating_button.dart +++ b/lib/new_views/common_widgets/app_floating_button.dart @@ -3,15 +3,16 @@ import 'package:test_sa/extensions/context_extension.dart'; import '../app_style/app_color.dart'; -class AddFloatingButton extends StatelessWidget { +class AppFloatingButton extends StatelessWidget { + final IconData icon; final VoidCallback onPressed; - const AddFloatingButton({Key key, @required this.onPressed}) : super(key: key); + const AppFloatingButton({Key key, @required this.icon, @required this.onPressed}) : super(key: key); @override Widget build(BuildContext context) { return FloatingActionButton( onPressed: onPressed, - child: Icon(Icons.add , color: context.isDark? AppColor.neutral50:AppColor.neutral30, ), + child: Icon(icon, color: context.isDark ? AppColor.neutral50 : AppColor.neutral30), ); } } diff --git a/lib/new_views/common_widgets/pagination_bar.dart b/lib/new_views/common_widgets/pagination_bar.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/new_views/common_widgets/test screen.dart b/lib/new_views/common_widgets/test screen.dart deleted file mode 100644 index ac899292..00000000 --- a/lib/new_views/common_widgets/test screen.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:test_sa/new_views/common_widgets/app_bar/custom_app_bar.dart'; - -import 'add_floating_button.dart'; -import 'app_bar/home_app_bar.dart'; -import 'bottom_nav_bar/home_bottom_nav_bar.dart'; - -class TestScreen extends StatefulWidget { - static const String id = '/test'; - const TestScreen({Key key}) : super(key: key); - - @override - State createState() => _TestScreenState(); -} - -class _TestScreenState extends State { - int screenIndex =0; - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: HomeAppBar(), - body: Center(child: _widgetOptions[screenIndex]), - floatingActionButton: AddFloatingButton(onPressed: () {},), - bottomNavigationBar: HomeBottomNavigationBar(onPressed: (index){ - setState(() { - screenIndex = index; - }); - },), - ); - } - - static const List _widgetOptions = [ - Text( - 'Index 0', - ), - Text( - 'Index 1', - ), - Text( - 'Index 2', - ), - Text( - 'Index 3', - ), - ]; -} diff --git a/lib/new_views/pages/land_page/dashboard_page.dart b/lib/new_views/pages/land_page/dashboard_page.dart new file mode 100644 index 00000000..e82490d0 --- /dev/null +++ b/lib/new_views/pages/land_page/dashboard_page.dart @@ -0,0 +1,72 @@ +import 'package:flutter/material.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; + +import 'dashboard_page_indicator.dart'; + +class DashboardPage extends StatefulWidget { + const DashboardPage({Key key}) : super(key: key); + + @override + State createState() => _DashboardPageState(); +} + +class _DashboardPageState extends State { + PageController _controller; + int _currentPage = 1; + + @override + void initState() { + super.initState(); + _controller = PageController() + ..addListener(() { + _currentPage = _controller.page.toInt() + 1; + setState(() {}); + }); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + DashboardPageIndicator(index: 0, currentPage: _currentPage, controller: _controller), + 3.width, + DashboardPageIndicator(index: 1, currentPage: _currentPage, controller: _controller), + 3.width, + DashboardPageIndicator(index: 2, currentPage: _currentPage, controller: _controller), + 10.width, + Text( + "0$_currentPage/03", + style: Theme.of(context).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w500), + ), + ], + ), + 8.height, + Expanded( + child: PageView( + controller: _controller, + children: const [ + Center( + child: Text('First Page'), + ), + Center( + child: Text('Second Page'), + ), + Center( + child: Text('Third Page'), + ), + ], + ), + ), + ], + ); + } +} diff --git a/lib/new_views/pages/land_page/land_page.dart b/lib/new_views/pages/land_page/land_page.dart index b6a550c5..d01b717a 100644 --- a/lib/new_views/pages/land_page/land_page.dart +++ b/lib/new_views/pages/land_page/land_page.dart @@ -2,12 +2,13 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; -import 'package:test_sa/new_views/app_style/app_color.dart'; +import 'package:test_sa/new_views/common_widgets/app_bar/home_app_bar.dart'; +import '../../common_widgets/app_bottom_nav_bar.dart'; import '../../common_widgets/app_drawer.dart'; -import 'dashboard_page_indicator.dart'; +import '../../common_widgets/app_floating_button.dart'; +import 'dashboard_page.dart'; class LandPage extends StatefulWidget { static const String routeName = "/land-page"; @@ -18,29 +19,19 @@ class LandPage extends StatefulWidget { } class _LandPageState extends State { - PageController _controller; - int _currentPage = 1; - - @override - void initState() { - super.initState(); - _controller = PageController() - ..addListener(() { - _currentPage = _controller.page.toInt() + 1; - setState(() {}); - }); - } - - @override - void dispose() { - _controller.dispose(); - super.dispose(); - } + int currentPageIndex = 0; + static const List _pages = [ + DashboardPage(), + Text('Index 1'), + Text('Index 2'), + Text('Index 3'), + ]; @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { + /// TODO [zaid] : show dialog before exit // bool result = await showDialog( // context: context, // builder: (_) => const AAlertDialog( @@ -58,54 +49,23 @@ class _LandPageState extends State { return false; }, child: Scaffold( - appBar: AppBar(), + appBar: HomeAppBar(), body: Padding( padding: EdgeInsets.only(left: 16.toScreenWidth, top: 11.toScreenHeight), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - DashboardPageIndicator(index: 0, currentPage: _currentPage, controller: _controller), - 3.width, - DashboardPageIndicator(index: 1, currentPage: _currentPage, controller: _controller), - 3.width, - DashboardPageIndicator(index: 2, currentPage: _currentPage, controller: _controller), - 10.width, - Text( - "0$_currentPage/03", - style: Theme.of(context).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w500), - ), - ], - ), - 8.height, - Expanded( - child: PageView( - controller: _controller, - children: const [ - Center( - child: Text('First Page'), - ), - Center( - child: Text('Second Page'), - ), - Center( - child: Text('Third Page'), - ), - ], - ), - ), - ], - ), - ), - bottomNavigationBar: BottomNavigationBar( - items: [ - BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"), - BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"), - BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"), - ], + child: _pages[currentPageIndex], ), drawer: const AppDrawer(), + floatingActionButton: AppFloatingButton( + icon: Icons.add, + onPressed: () {}, + ), + bottomNavigationBar: AppBottomNavigationBar( + onPressed: (index) { + setState(() { + currentPageIndex = index; + }); + }, + ), ), ); }