Created
February 19, 2019 13:59
-
-
Save erikkubica/45fc8acdce1f8a25cd5258e8b3a0e1f3 to your computer and use it in GitHub Desktop.
Wrong colors
This file contains hidden or 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 StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// Color for App bar BG, Card BG, RaisedButton BG, FloatingButton BG | |
Color primary = Colors.red; | |
// Color for text where the primary color is the background | |
Color accent = Colors.yellowAccent; | |
// Any other text color | |
Color black = Colors.black; | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.redAccent[800], | |
primaryColor: primary, | |
accentColor: accent, | |
brightness: Brightness.light, | |
primaryIconTheme: IconThemeData(color: accent), | |
accentIconTheme: IconThemeData(color: accent), | |
iconTheme: IconThemeData(color: accent), | |
cardColor: primary, | |
buttonColor: primary, | |
buttonTheme: ButtonThemeData( | |
textTheme: ButtonTextTheme.accent, | |
buttonColor: primary, | |
), | |
primaryTextTheme: TextTheme( | |
title: TextStyle(color: accent), | |
button: TextStyle(color: black), | |
), | |
accentTextTheme: TextTheme( | |
title: TextStyle(color: black), | |
button: TextStyle(color: black), | |
), | |
textTheme: TextTheme( | |
title: TextStyle(color: black), | |
button: TextStyle(color: black), | |
), | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
void _incrementCounter() { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("Foo bar"), | |
content: new Text( | |
"The delete button is set manually to ButtonTextTheme.primary to be red, it´s fine. But the keep button defaults to the ThemeData.accentColor"), | |
actions: <Widget>[ | |
new FlatButton( | |
textTheme: ButtonTextTheme.primary, | |
child: new Text( | |
"Delete", | |
style: TextStyle(color: Theme.of(context).primaryColor), | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
new FlatButton( | |
child: new Text("Keep"), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
drawer: Drawer(), | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'Floating action button background color should be the primary red, not the yellow accent color. Like the AppBar+DrawerIcon', | |
) | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment