diff --git a/lib/main.dart b/lib/main.dart index fa18709..604e9d2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:hashcode/custom/custom_colors.dart'; import 'package:hashcode/screens/home.dart'; +import 'package:hashcode/theme.dart'; +import 'package:provider/provider.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -8,11 +11,33 @@ void main() { } class MyApp extends StatelessWidget { + @override Widget build(BuildContext context) { + SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith( + statusBarColor: Colors.black, //set status bar color + )); + return ChangeNotifierProvider( + builder: (context)=> ThemeChanger(ThemeData.dark()), + child: HashCodeApp() + ); + } +} + + +class HashCodeApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + final theme = Provider.of(context); return MaterialApp( - theme: ThemeData(accentColor: customDarkBlack), + debugShowCheckedModeBanner: true, + title: 'HashCode App', home: Home(), + theme: theme.getTheme(), ); } } + + + + diff --git a/lib/screens/about_topic.dart b/lib/screens/about_topic.dart index f9eca9e..5a19e41 100644 --- a/lib/screens/about_topic.dart +++ b/lib/screens/about_topic.dart @@ -38,7 +38,6 @@ class _AboutTopicState extends State { Widget build(BuildContext context) { final appBar = AppBar( elevation: 1.0, - backgroundColor: customDarkBlack, title: Text('About'), centerTitle: true, leading: IconButton( @@ -101,7 +100,6 @@ class _AboutTopicState extends State { ); return Scaffold( - backgroundColor: customDarkBlack, appBar: appBar, body: body, ); diff --git a/lib/screens/code.dart b/lib/screens/code.dart index d04b229..e01d918 100644 --- a/lib/screens/code.dart +++ b/lib/screens/code.dart @@ -26,7 +26,6 @@ class _CodeState extends State { Widget build(BuildContext context) { final appBar = AppBar( elevation: 1.0, - backgroundColor: customDarkBlack, title: Text('About'), centerTitle: true, leading: IconButton( diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 2a396e2..fc4002c 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -4,20 +4,31 @@ import 'package:hashcode/custom/custom_colors.dart'; import 'package:hashcode/custom/custom_gifs.dart'; import 'package:hashcode/custom/page_transitions/slide_left_route.dart'; import 'package:hashcode/screens/lessons.dart'; +import 'package:hashcode/theme.dart'; +import 'package:provider/provider.dart'; class Home extends StatelessWidget { @override Widget build(BuildContext context) { + ThemeChanger _themeChanger = Provider.of(context); final body = CustomScrollView( physics: BouncingScrollPhysics(), slivers: [ SliverAppBar( floating: true, pinned: false, - backgroundColor: customDarkBlack, elevation: 1.0, title: Text('Dashboard'), actions: [ + Switch( + value: _themeChanger.isLightTheme, + onChanged: (lightDark) { + if (lightDark) + _themeChanger.setTheme(ThemeData(primaryColor: Colors.white)); + else + _themeChanger.setTheme(ThemeData.dark()); + }), + GestureDetector( onTap: () { Navigator.push(context, SlideLeftRoute(page: Lessons())); @@ -68,7 +79,7 @@ class Home extends StatelessWidget { ); return Scaffold( - backgroundColor: customDarkBlack, + body: body, ); } diff --git a/lib/screens/lessons.dart b/lib/screens/lessons.dart index 80593ed..72b92a9 100644 --- a/lib/screens/lessons.dart +++ b/lib/screens/lessons.dart @@ -21,7 +21,6 @@ class Lessons extends StatelessWidget { centerTitle: true, title: Text('Lessons'), elevation: 1.0, - backgroundColor: customDarkBlack, leading: IconButton( icon: Icon(Icons.arrow_back), onPressed: () { @@ -37,7 +36,7 @@ class Lessons extends StatelessWidget { Navigator.push(context, SlideLeftRoute(page: AboutTopic(lesson: courseContent[index]))); }, child: Card( - color: customLightBlack, + // color: customLightBlack, elevation: 8.0, margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0), child: ListTile( @@ -48,19 +47,19 @@ class Lessons extends StatelessWidget { border: Border( right: BorderSide( width: 1.0, - color: Colors.white24 + // color: Colors.white24 ), ), ), child: Text( (index + 1).toString(), - style: TextStyle(color: Colors.white, fontSize: 18.0), + style: TextStyle( fontSize: 18.0), ), ), title: Text( courseContent[index][0], style: TextStyle( - color: Colors.white, + // color: Colors.white, fontWeight: FontWeight.bold ), ), @@ -69,7 +68,6 @@ class Lessons extends StatelessWidget { Icon(Icons.linear_scale, color: customPink), Text( " Intermediate", - style: TextStyle(color: Colors.white), ), ], ), @@ -84,7 +82,6 @@ class Lessons extends StatelessWidget { ); return Scaffold( - backgroundColor: customDarkBlack, body: body ); } diff --git a/lib/theme.dart b/lib/theme.dart new file mode 100644 index 0000000..b1e7bcb --- /dev/null +++ b/lib/theme.dart @@ -0,0 +1,18 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class ThemeChanger with ChangeNotifier { + ThemeData _themeData; + bool isLightTheme = false; + ThemeChanger(this._themeData); + + getTheme() => _themeData; + setTheme(ThemeData theme) { + if (theme == ThemeData.dark()) + isLightTheme = false; + else + isLightTheme = true; + _themeData = theme; + notifyListeners(); + } +} diff --git a/pubspec.lock b/pubspec.lock index 1e11639..6788f87 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,42 +21,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.4.2" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.0.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.1.3" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.14.13" convert: dependency: transitive description: @@ -77,7 +77,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -115,14 +115,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.8" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.1.8" mime: dependency: transitive description: @@ -136,14 +136,21 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.7.0" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "3.0.4" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1+1" sky_engine: dependency: transitive description: flutter @@ -155,49 +162,49 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.7.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.9.5" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.0.5" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.17" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.2.0" uuid: dependency: transitive description: @@ -211,7 +218,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.0.8" xml: dependency: transitive description: @@ -234,5 +241,5 @@ packages: source: hosted version: "7.0.0+7" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.9.0-14.0.dev <3.0.0" flutter: ">=1.12.13+hotfix.5" diff --git a/pubspec.yaml b/pubspec.yaml index b6186a1..9a09a23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: sdk: flutter youtube_player_flutter: flutter_launcher_icons: + provider: ^2.0.1 flutter_icons: image_path: "assets/icon/icon.png"