How to change accent color on runtime in flutter?
Color scolor = Colors.green;
...
...
new MaterialApp(
theme: new ThemeData(
brightness: Brightness.light,
accentColor: scolor,
),
home: new SetAccentColor());
class SetAccentColor extends StatefulWidget {
@override
_SetAccentColor createState() => _SetAccentColor();
}
class _SetAccentColor extends State<SetAccentColor > {
...
...
@override
Widget build(BuildContext context) {
return Scaffold(
body: Builder(
builder: (context) => Container(
child: FutureBuilder<List<ColorDBModel>>(
future: ColorDBProvider.db.getAllColorModels(),
builder: (BuildContext context, AsyncSnapshot<List<ColorDBModel>> snapshot) {
if (snapshot.data[0].ColorName == "red")
scolor = Colors.red;
else
scolor = Colors.blue;
...
...
...
}
}
}
These are the important parts of the code. But accentColor isnt changing according to the changes in scolor.