Skip to content

Commit 2e09552

Browse files
committed
adaptive theme 2.0.0
1 parent 32a89a7 commit 2e09552

File tree

5 files changed

+135
-131
lines changed

5 files changed

+135
-131
lines changed

lib/main.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1+
import 'package:adaptive_theme/adaptive_theme.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_app/screens/loading.dart';
3-
import 'package:dynamic_theme/dynamic_theme.dart';
44
import 'package:flutter_phoenix/flutter_phoenix.dart';
55

66
void main() => runApp(Phoenix(child: MyApp()));
77

88
class MyApp extends StatelessWidget {
99
@override
1010
Widget build(BuildContext context) {
11-
return DynamicTheme(
12-
defaultBrightness: Brightness.light,
13-
data: (brightness) => ThemeData(
11+
return AdaptiveTheme(
12+
light: ThemeData(
13+
brightness: Brightness.light,
1414
primarySwatch: Colors.blue,
15-
brightness: brightness,
16-
fontFamily: 'google',
15+
fontFamily: 'google'
16+
),
17+
dark: ThemeData(
18+
brightness: Brightness.dark,
19+
primarySwatch: Colors.blue,
20+
fontFamily: 'google'
21+
),
22+
initial: AdaptiveThemeMode.light,
23+
builder: (theme, darkTheme) => MaterialApp(
24+
title: 'COVID-19 Tracker',
25+
theme: theme,
26+
darkTheme: darkTheme,
27+
home: LoadingScreen(),
1728
),
18-
themedWidgetBuilder: (context, theme) {
19-
return MaterialApp(
20-
title: 'COVID-19 Tracker',
21-
theme: theme,
22-
home: LoadingScreen(),
23-
);
24-
},
2529
);
2630
}
2731
}

lib/screens/HomePage.dart

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import 'package:adaptive_theme/adaptive_theme.dart';
12
import 'package:animations/animations.dart';
2-
import 'package:dynamic_theme/dynamic_theme.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter_app/data/country_virus_data.dart';
55
import 'package:flutter_app/data/virus_data.dart';
@@ -35,14 +35,13 @@ class _HomePageState extends State<HomePage> {
3535
CountryVirusData locationData;
3636
int index = 0;
3737
List<CountryVirusData> countriesData = [];
38-
bool isLight;
38+
bool isLight = true;
3939

4040
final _scaffoldKey = GlobalKey<ScaffoldState>();
4141

4242
@override
4343
void initState() {
4444
updateUI(widget.virusData);
45-
4645
updateLocationUI(widget.locationVirusData);
4746
updateCountriesUI(widget.countriesData);
4847
super.initState();
@@ -117,7 +116,6 @@ class _HomePageState extends State<HomePage> {
117116
@override
118117
Widget build(BuildContext context) {
119118
SizeConfig().init(context);
120-
isLight = DynamicTheme.of(context).brightness == Brightness.light;
121119
return Scaffold(
122120
appBar: AppBar(
123121
key: _scaffoldKey,
@@ -135,24 +133,12 @@ class _HomePageState extends State<HomePage> {
135133
actions: <Widget>[
136134
IconButton(
137135
icon: Icon(Icons.lightbulb_outline),
138-
onPressed: () => setState(
139-
() {
140-
if (isLight) {
141-
// brightness = Brightness.dark;
142-
isLight = !isLight;
143-
DynamicTheme.of(context).setBrightness(Brightness.dark);
144-
} else if (!isLight) {
145-
isLight = !isLight;
146-
// brightness = Brightness.light;
147-
DynamicTheme.of(context).setBrightness(Brightness.light);
148-
} else {
149-
isLight =
150-
DynamicThemeState().brightness == Brightness.light;
151-
// brightness = Brightness.dark;
152-
DynamicTheme.of(context).setBrightness(Brightness.dark);
153-
}
154-
},
155-
),
136+
onPressed: () {
137+
isLight ? AdaptiveTheme.of(context).setDark() : AdaptiveTheme.of(context).setLight();
138+
setState(() {
139+
isLight = !isLight;
140+
});
141+
}
156142
)
157143
],
158144
),
@@ -207,7 +193,7 @@ class _HomePageState extends State<HomePage> {
207193
children: <Widget>[
208194
Padding(
209195
padding: EdgeInsets.only(left: xMargin(4)),
210-
child: FlatButton(
196+
child: TextButton(
211197
onPressed: () => Navigator.push(
212198
context,
213199
MaterialPageRoute(
@@ -259,7 +245,7 @@ class _HomePageState extends State<HomePage> {
259245
child: Row(
260246
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
261247
children: <Widget>[
262-
FlatButton(
248+
TextButton(
263249
onPressed: () {
264250
Navigator.push(
265251
context,
@@ -271,7 +257,7 @@ class _HomePageState extends State<HomePage> {
271257
title: "COVID-19",
272258
),
273259
),
274-
FlatButton(
260+
TextButton(
275261
onPressed: () {
276262
Navigator.push(
277263
context,
@@ -299,7 +285,7 @@ class _HomePageState extends State<HomePage> {
299285
title: "Indian States",
300286
),
301287
),
302-
FlatButton(
288+
TextButton(
303289
onPressed: () => Navigator.push(
304290
context,
305291
MaterialPageRoute(

lib/widgets/mainDrawer.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class MyCustomClipper extends CustomClipper<Path> {
1414
Path getClip(Size size) {
1515
final path = Path();
1616

17-
path.lineTo(size.width * 0.75, 0);
17+
path.lineTo(size.width * 0.8, 0);
1818
path.quadraticBezierTo(
19-
280, size.height * 0.5, size.width * 0.7, size.height);
19+
280, size.height * 0.6, size.width * 0.8, size.height);
2020
path.lineTo(0, size.height);
2121
path.close();
2222
return path;
@@ -40,18 +40,18 @@ Drawer buildDrawer(context, isLight, widget) {
4040
padding: EdgeInsets.only(left: SizeConfig.blockSizeHorizontal * 2),
4141
child: Image.asset(
4242
isLight ? "assets/covid_black.png" : "assets/covid_white.png",
43-
width: xMargin(40),
43+
width: 160,
4444
),
4545
),
4646
Column(
4747
children: <Widget>[
48-
FlatButton(
48+
TextButton(
4949
onPressed: () {
5050
Navigator.pop(context);
5151
},
5252
child: Row(
5353
children: <Widget>[
54-
Icon(Icons.home),
54+
Icon(Icons.home, color: isLight ? Colors.black : Colors.white),
5555
SizedBox(
5656
width: 10,
5757
),
@@ -62,7 +62,7 @@ Drawer buildDrawer(context, isLight, widget) {
6262
],
6363
),
6464
),
65-
FlatButton(
65+
TextButton(
6666
onPressed: () {
6767
Navigator.pop(context);
6868
Navigator.push(
@@ -83,7 +83,7 @@ Drawer buildDrawer(context, isLight, widget) {
8383
},
8484
child: Row(
8585
children: <Widget>[
86-
Icon(Icons.flag),
86+
Icon(Icons.flag, color: isLight ? Colors.black : Colors.white),
8787
SizedBox(
8888
width: 10,
8989
),
@@ -94,7 +94,7 @@ Drawer buildDrawer(context, isLight, widget) {
9494
],
9595
),
9696
),
97-
FlatButton(
97+
TextButton(
9898
onPressed: () {
9999
Navigator.pop(context);
100100
Navigator.push(
@@ -131,7 +131,7 @@ Drawer buildDrawer(context, isLight, widget) {
131131
],
132132
),
133133
),
134-
FlatButton(
134+
TextButton(
135135
onPressed: () {
136136
Navigator.pop(context);
137137
Navigator.push(
@@ -156,13 +156,13 @@ Drawer buildDrawer(context, isLight, widget) {
156156
],
157157
),
158158
),
159-
FlatButton(
159+
TextButton(
160160
onPressed: () {
161161
Phoenix.rebirth(context);
162162
},
163163
child: Row(
164164
children: <Widget>[
165-
Icon(Icons.refresh),
165+
Icon(Icons.refresh, color: isLight ? Colors.black : Colors.white,),
166166
SizedBox(
167167
width: 10,
168168
),
@@ -173,7 +173,7 @@ Drawer buildDrawer(context, isLight, widget) {
173173
],
174174
),
175175
),
176-
FlatButton(
176+
TextButton(
177177
onPressed: () {
178178
showAboutDialog(
179179
context: context,
@@ -188,7 +188,7 @@ Drawer buildDrawer(context, isLight, widget) {
188188
},
189189
child: Row(
190190
children: <Widget>[
191-
Icon(Icons.info),
191+
Icon(Icons.info, color: isLight ? Colors.black : Colors.white,),
192192
SizedBox(
193193
width: 10,
194194
),
@@ -204,12 +204,12 @@ Drawer buildDrawer(context, isLight, widget) {
204204
Row(
205205
children: <Widget>[
206206
Padding(
207-
padding: EdgeInsets.only(left: xMargin(2)),
207+
padding: EdgeInsets.only(left: 4),
208208
child: Text(
209209
"Covid Tracker",
210210
style: TextStyle(
211211
fontFamily: "Kayak",
212-
fontSize: yMargin(2.4),
212+
fontSize: 16,
213213
color: Colors.teal),
214214
),
215215
),
@@ -226,7 +226,7 @@ Drawer buildDrawer(context, isLight, widget) {
226226
),
227227
Text(
228228
"© Aditya Singh",
229-
style: TextStyle(fontFamily: "Kayak", fontSize: yMargin(2)),
229+
style: TextStyle(fontFamily: "Kayak", fontSize: 14),
230230
)
231231
],
232232
)

0 commit comments

Comments
 (0)