From c85fa006ce6721c9e05aac3c6e06e634bbbf7749 Mon Sep 17 00:00:00 2001 From: dafinrs Date: Sat, 26 Oct 2019 15:59:46 +0700 Subject: [PATCH] activation drawer n switch button darkmode/lightmode --- lib/main.dart | 31 +++++++++++-------- lib/screens/home.dart | 71 ++++++++++++++++++++----------------------- pubspec.lock | 27 ++++++++++------ pubspec.yaml | 1 + 4 files changed, 69 insertions(+), 61 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 57889e3..5571c98 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,16 +1,17 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_travel_concept/controller/home_controller.dart'; import 'package:flutter_travel_concept/screens/main_screen.dart'; import 'package:flutter_travel_concept/util/const.dart'; +import 'package:provider/provider.dart'; - -void main() async{ - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) { +void main() async { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) + .then((_) { runApp(MyApp()); }); } - class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); @@ -25,19 +26,23 @@ class _MyAppState extends State { SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: isDark ? Constants.darkPrimary : Constants.lightPrimary, - statusBarIconBrightness: isDark?Brightness.light:Brightness.dark, + statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark, )); } - @override Widget build(BuildContext context) { - return MaterialApp( - debugShowCheckedModeBanner: false, - title: Constants.appName, - theme: isDark ? Constants.darkTheme : Constants.lightTheme, - home: MainScreen(), - ); + return ChangeNotifierProvider( + builder: (_) => HomeController(), + child: Consumer( + builder: (_, value, child) { + return MaterialApp( + debugShowCheckedModeBanner: false, + title: Constants.appName, + theme: value.modeChange ? Constants.darkTheme : Constants.lightTheme, + home: MainScreen(), + ); + }, + )); } } - diff --git a/lib/screens/home.dart b/lib/screens/home.dart index fca4e9f..5211591 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:flutter_travel_concept/controller/home_controller.dart'; import 'package:flutter_travel_concept/screens/details.dart'; import 'package:flutter_travel_concept/widgets/icon_badge.dart'; import 'package:flutter_travel_concept/util/places.dart'; +import 'package:provider/provider.dart'; class Home extends StatefulWidget { @override @@ -11,28 +13,37 @@ class Home extends StatefulWidget { class _HomeState extends State { final TextEditingController _searchControl = new TextEditingController(); - @override Widget build(BuildContext context) { + final provider = Provider.of(context); + return Scaffold( appBar: AppBar( - leading: IconButton( - icon: Icon( - Icons.menu, - ), - onPressed: (){}, - ), - actions: [ IconButton( icon: IconBadge( icon: Icons.notifications_none, ), - onPressed: (){}, + onPressed: () {}, ), ], ), - + drawer: Drawer( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Container(), + ), + FlatButton( + child: provider.modeChange ? Text('Dark mode') : Text('White Mode'), + onPressed: () { + provider.setModeChange = !provider.modeChange; + }, + ), + ], + ), + ), body: ListView( children: [ Padding( @@ -45,8 +56,6 @@ class _HomeState extends State { ), ), ), - - Padding( padding: EdgeInsets.all(20), child: Container( @@ -65,10 +74,14 @@ class _HomeState extends State { contentPadding: EdgeInsets.all(10.0), border: OutlineInputBorder( borderRadius: BorderRadius.circular(5.0), - borderSide: BorderSide(color: Colors.white,), + borderSide: BorderSide( + color: Colors.white, + ), ), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.white,), + borderSide: BorderSide( + color: Colors.white, + ), borderRadius: BorderRadius.circular(5.0), ), hintText: "E.g: New York, United States", @@ -86,7 +99,6 @@ class _HomeState extends State { ), ), ), - Container( padding: EdgeInsets.only(top: 10, left: 20), height: 250, @@ -97,7 +109,6 @@ class _HomeState extends State { primary: false, itemCount: places == null ? 0 : places.length, itemBuilder: (BuildContext context, int index) { - Map place = places.reversed.toList()[index]; return Padding( padding: const EdgeInsets.only(right: 20), @@ -117,7 +128,6 @@ class _HomeState extends State { fit: BoxFit.cover, ), ), - SizedBox(height: 7), Container( alignment: Alignment.centerLeft, @@ -131,7 +141,6 @@ class _HomeState extends State { textAlign: TextAlign.left, ), ), - SizedBox(height: 3), Container( alignment: Alignment.centerLeft, @@ -146,14 +155,13 @@ class _HomeState extends State { textAlign: TextAlign.left, ), ), - ], ), ), - onTap: (){ + onTap: () { Navigator.of(context).push( MaterialPageRoute( - builder: (BuildContext context){ + builder: (BuildContext context) { return Details(); }, ), @@ -164,7 +172,6 @@ class _HomeState extends State { }, ), ), - Padding( padding: EdgeInsets.all(20), child: ListView.builder( @@ -175,7 +182,7 @@ class _HomeState extends State { itemBuilder: (BuildContext context, int index) { Map place = places[index]; return Padding( - padding: const EdgeInsets.only(bottom:15.0), + padding: const EdgeInsets.only(bottom: 15.0), child: InkWell( child: Container( height: 70, @@ -191,12 +198,10 @@ class _HomeState extends State { fit: BoxFit.cover, ), ), - SizedBox(width: 15), - Container( height: 80, - width: MediaQuery.of(context).size.width-130, + width: MediaQuery.of(context).size.width - 130, child: ListView( primary: false, physics: NeverScrollableScrollPhysics(), @@ -214,7 +219,6 @@ class _HomeState extends State { textAlign: TextAlign.left, ), ), - SizedBox(height: 3), Row( children: [ @@ -223,9 +227,7 @@ class _HomeState extends State { size: 13, color: Colors.blueGrey[300], ), - SizedBox(width: 3), - Container( alignment: Alignment.centerLeft, child: Text( @@ -241,7 +243,6 @@ class _HomeState extends State { ), ], ), - SizedBox(height: 10), Container( alignment: Alignment.centerLeft, @@ -255,19 +256,16 @@ class _HomeState extends State { textAlign: TextAlign.left, ), ), - - ], ), ), - ], ), ), - onTap: (){ + onTap: () { Navigator.of(context).push( MaterialPageRoute( - builder: (BuildContext context){ + builder: (BuildContext context) { return Details(); }, ), @@ -278,11 +276,8 @@ class _HomeState extends State { }, ), ), - - ], ), - ); } } diff --git a/pubspec.lock b/pubspec.lock index f6b0bbd..109af67 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.3.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -59,28 +59,35 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.7" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.8.0+1" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0+1" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -113,7 +120,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -127,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.4" + version: "0.2.5" typed_data: dependency: transitive description: @@ -143,4 +150,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.2.2 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 24286a1..468a94f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 + provider: ^3.1.0+1 dev_dependencies: flutter_test: