Skip to content

Commit

Permalink
Added dark and light mode (#7)
Browse files Browse the repository at this point in the history
* theme changing

* changes in about section

* all the things working perfectly

* issue 1 and 2 are solved

* issue 4 of switch solved

* theme part is all completed , everything working fine
  • Loading branch information
savagecarol authored Dec 31, 2020
1 parent de8c57b commit e6620c1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 33 deletions.
27 changes: 26 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
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();
runApp(MyApp());
}

class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.black, //set status bar color
));
return ChangeNotifierProvider<ThemeChanger>(
builder: (context)=> ThemeChanger(ThemeData.dark()),
child: HashCodeApp()
);
}
}


class HashCodeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeChanger>(context);
return MaterialApp(
theme: ThemeData(accentColor: customDarkBlack),
debugShowCheckedModeBanner: true,
title: 'HashCode App',
home: Home(),
theme: theme.getTheme(),
);
}
}




2 changes: 0 additions & 2 deletions lib/screens/about_topic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class _AboutTopicState extends State<AboutTopic> {
Widget build(BuildContext context) {
final appBar = AppBar(
elevation: 1.0,
backgroundColor: customDarkBlack,
title: Text('About'),
centerTitle: true,
leading: IconButton(
Expand Down Expand Up @@ -101,7 +100,6 @@ class _AboutTopicState extends State<AboutTopic> {
);

return Scaffold(
backgroundColor: customDarkBlack,
appBar: appBar,
body: body,
);
Expand Down
1 change: 0 additions & 1 deletion lib/screens/code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class _CodeState extends State<Code> {
Widget build(BuildContext context) {
final appBar = AppBar(
elevation: 1.0,
backgroundColor: customDarkBlack,
title: Text('About'),
centerTitle: true,
leading: IconButton(
Expand Down
15 changes: 13 additions & 2 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThemeChanger>(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()));
Expand Down Expand Up @@ -68,7 +79,7 @@ class Home extends StatelessWidget {
);

return Scaffold(
backgroundColor: customDarkBlack,

body: body,
);
}
Expand Down
11 changes: 4 additions & 7 deletions lib/screens/lessons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: () {
Expand All @@ -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(
Expand All @@ -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
),
),
Expand All @@ -69,7 +68,6 @@ class Lessons extends StatelessWidget {
Icon(Icons.linear_scale, color: customPink),
Text(
" Intermediate",
style: TextStyle(color: Colors.white),
),
],
),
Expand All @@ -84,7 +82,6 @@ class Lessons extends StatelessWidget {
);

return Scaffold(
backgroundColor: customDarkBlack,
body: body
);
}
Expand Down
18 changes: 18 additions & 0 deletions lib/theme.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}
47 changes: 27 additions & 20 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e6620c1

Please sign in to comment.