Last active
September 14, 2020 23:17
-
-
Save RyosukeOK/7f9ec91c9e23f7f00b1eb9d755c0f64a to your computer and use it in GitHub Desktop.
theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
bool isDark = false; | |
void handleDark(value) { | |
setState(() { | |
isDark = !isDark; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Theme Demo', | |
debugShowCheckedModeBanner: false, | |
theme: isDark ? darkTheme : lightTheme, | |
darkTheme: isDark ? darkTheme : lightTheme, | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Theme Demo'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: <Widget>[ | |
Switch(value: isDark, onChanged: handleDark), | |
Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
for (int index = 0; index < 2; ++index) | |
Radio<int>( | |
value: index, | |
groupValue: !isDark ? 0 : 1, | |
onChanged: handleDark, | |
), | |
], | |
), | |
RaisedButton( | |
child: Text('Button'), | |
onPressed: () { | |
handleDark(null); | |
}, | |
), | |
ConstrainedBox( | |
constraints: BoxConstraints(maxWidth: 300), | |
child: Card( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
const ListTile( | |
title: Text('Title'), | |
subtitle: Text('This is a subtitle.'), | |
), | |
ButtonBar( | |
children: <Widget>[ | |
FlatButton( | |
child: Text( | |
'Share', | |
style: Theme.of(context) | |
.textTheme | |
.button | |
.copyWith( | |
color: Theme.of(context).accentColor), | |
), | |
onPressed: () {}, | |
), | |
FlatButton( | |
child: Text( | |
'Done', | |
style: Theme.of(context) | |
.textTheme | |
.button | |
.copyWith( | |
color: Theme.of(context).accentColor), | |
), | |
textColor: Theme.of(context).accentColor, | |
onPressed: () {}, | |
), | |
], | |
), | |
], | |
), | |
), | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
handleDark(null); | |
}, | |
child: Icon(Icons.add), | |
), | |
), | |
); | |
} | |
} | |
final ThemeData lightTheme = ThemeData( | |
primarySwatch: Colors.blue, | |
brightness: Brightness.light, | |
primaryColor: Color(0xff2196f3), | |
accentColor: Color(0xff2196f3), | |
textTheme: TextTheme( | |
headline1: TextStyle( | |
color: Color(0x8a000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline2: TextStyle( | |
color: Color(0x8a000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline3: TextStyle( | |
color: Color(0x8a000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline4: TextStyle( | |
color: Color(0x8a000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline5: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline6: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
subtitle1: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
subtitle2: TextStyle( | |
color: Color(0xff000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
bodyText1: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
bodyText2: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
caption: TextStyle( | |
color: Color(0x8a000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
button: TextStyle( | |
color: Color(0xdd000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
overline: TextStyle( | |
color: Color(0xff000000), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
), | |
); | |
final ThemeData darkTheme = ThemeData( | |
primarySwatch: MaterialColor(4280361249, { | |
50: Color(0xfff2f2f2), | |
100: Color(0xffe6e6e6), | |
200: Color(0xffcccccc), | |
300: Color(0xffb3b3b3), | |
400: Color(0xff999999), | |
500: Color(0xff808080), | |
600: Color(0xff666666), | |
700: Color(0xff4d4d4d), | |
800: Color(0xff333333), | |
900: Color(0xff191919) | |
}), | |
brightness: Brightness.dark, | |
primaryColor: Color(0xff212121), | |
accentColor: Color(0xff64ffda), | |
textTheme: TextTheme( | |
headline1: TextStyle( | |
color: Color(0xb3ffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline2: TextStyle( | |
color: Color(0xb3ffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline3: TextStyle( | |
color: Color(0xb3ffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline4: TextStyle( | |
color: Color(0xb3ffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline5: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
headline6: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
subtitle1: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
subtitle2: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
bodyText1: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
bodyText2: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
caption: TextStyle( | |
color: Color(0xb3ffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
button: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
overline: TextStyle( | |
color: Color(0xffffffff), | |
fontSize: null, | |
fontWeight: FontWeight.w400, | |
fontStyle: FontStyle.normal, | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment