From 8f3cfdeae3c97005eebf1400b409d5079c1e9d94 Mon Sep 17 00:00:00 2001 From: Sudharshan Date: Sun, 10 Feb 2019 20:56:15 +0800 Subject: [PATCH] adding pageview for navigation --- lib/routes.dart | 4 +-- lib/screens/home/home.dart | 40 +++++++++++++++++++--- lib/widgets/contact_item/contact_item.dart | 0 lib/widgets/contact_item/index.dart | 1 + lib/widgets/contact_list/contact_list.dart | 0 lib/widgets/contact_list/index.dart | 1 + lib/widgets/top_bar/top_bar.dart | 21 ++++-------- 7 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 lib/widgets/contact_item/contact_item.dart create mode 100644 lib/widgets/contact_item/index.dart create mode 100644 lib/widgets/contact_list/contact_list.dart create mode 100644 lib/widgets/contact_list/index.dart diff --git a/lib/routes.dart b/lib/routes.dart index e7c7fe0..513d27f 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -5,7 +5,7 @@ import 'themer.dart'; class Routes { final routes = { - '/home': (BuildContext context) => Home() + '/home': (BuildContext context) => Container(child: Home()), }; final theme = buildTheme(); @@ -15,7 +15,7 @@ class Routes { title: "Beep", theme: theme, routes: routes, - home: Home(), + home: Container(child: Home()), )); } } diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index c298017..b3b7873 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -4,15 +4,47 @@ import "package:frontend_flutter/widgets/top_bar/index.dart"; import "package:frontend_flutter/widgets/conversation_list/index.dart"; import "package:frontend_flutter/widgets/bottom_bar/index.dart"; -class Home extends StatelessWidget { +class Home extends StatefulWidget { + @override + _HomeState createState() => _HomeState(); +} + +class _HomeState extends State { + final List titleList = ["Conversations", "Contacts", "Settings"]; + final PageController controller = PageController(); + + int _pageNumber = 0; + + @override + initState() { + super.initState(); + controller.addListener(_updatePageNumber); + } + + @override + dispose() { + controller.dispose(); + super.dispose(); + } + + _updatePageNumber() { + setState(() { + _pageNumber = controller.page.round(); + }); + } + @override Widget build(BuildContext context) { return Scaffold( body: Column(children: [ - TopBar("Conversations"), + TopBar(title: titleList[_pageNumber], pageNumber: _pageNumber), Expanded( - child: ConversationList( - items: List.generate(100, (i) => "Item $i"))), + child: PageView(controller: controller, children: [ + ConversationList( + items: List.generate(100, (i) => "Item $i")), + ConversationList( + items: List.generate(100, (i) => "Item $i")) + ])) ]), bottomSheet: BottomBar()); } diff --git a/lib/widgets/contact_item/contact_item.dart b/lib/widgets/contact_item/contact_item.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/widgets/contact_item/index.dart b/lib/widgets/contact_item/index.dart new file mode 100644 index 0000000..6ad0155 --- /dev/null +++ b/lib/widgets/contact_item/index.dart @@ -0,0 +1 @@ +export "contact_item.dart"; diff --git a/lib/widgets/contact_list/contact_list.dart b/lib/widgets/contact_list/contact_list.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/widgets/contact_list/index.dart b/lib/widgets/contact_list/index.dart new file mode 100644 index 0000000..46f502e --- /dev/null +++ b/lib/widgets/contact_list/index.dart @@ -0,0 +1 @@ +export "contact_list.dart"; diff --git a/lib/widgets/top_bar/top_bar.dart b/lib/widgets/top_bar/top_bar.dart index 3579171..6564830 100644 --- a/lib/widgets/top_bar/top_bar.dart +++ b/lib/widgets/top_bar/top_bar.dart @@ -2,10 +2,11 @@ import "package:flutter/material.dart"; class TopBar extends StatelessWidget { final String title; + final int pageNumber; final double barHeight = 100.0; final String logo = "assets/logo.png"; - TopBar(title) : title = title; + TopBar({@required this.title, @required this.pageNumber}); @override Widget build(BuildContext context) { @@ -34,16 +35,8 @@ class TopBar extends StatelessWidget { width: 24.0, height: 24.0)), Spacer(), - IconButton( - icon: Icon(Icons.search), - onPressed: () { - print("Pressed"); - }), - IconButton( - icon: Icon(Icons.dehaze), - onPressed: () { - print("Pressed"); - }) + IconButton(icon: Icon(Icons.search), onPressed: () {}), + IconButton(icon: Icon(Icons.dehaze), onPressed: () {}) ], ), Positioned( @@ -55,7 +48,7 @@ class TopBar extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ Opacity( - opacity: 1.0, + opacity: (pageNumber == 0) ? 1.0 : 0.6, child: Padding( padding: EdgeInsets.only(left: 5.0), child: Container( @@ -65,7 +58,7 @@ class TopBar extends StatelessWidget { color: Colors.white, shape: BoxShape.circle)))), Opacity( - opacity: 0.6, + opacity: (pageNumber == 1) ? 1.0 : 0.6, child: Padding( padding: EdgeInsets.only(left: 5.0), child: Container( @@ -75,7 +68,7 @@ class TopBar extends StatelessWidget { color: Colors.white, shape: BoxShape.circle)))), Opacity( - opacity: 0.6, + opacity: (pageNumber == 2) ? 1.0 : 0.6, child: Padding( padding: EdgeInsets.only(left: 5.0), child: Container(