if you want Theme to your whole app with button toggled, simply you can use provider package, and make your main root listen to changes to mode
Make a class with changenotifier mixin that defines the your theme data with two instances of your dark and light mode
class LightDarkMode with ChangeNotifier {
var currentMode = false;
void switchMode(bool mode) {
currentMode = mode;
notifyListeners();
}
final light = const ColorScheme(
/*Light Color OF Icons*/ primary: Color.fromARGB(255, 126, 12, 12),
/*Dark Color OF Icon/Buttons*/ secondary: Color.fromARGB(255, 219, 203, 217),
onPrimary: Color.fromARGB(255, 163, 163, 163),
onSecondary: Colors.amber,
/*BACKGROUND OF APP*/ background: Color.fromARGB(255, 211, 204, 198),
/*Appbar,Big Widgets etc*/ onBackground: Color.fromARGB(255, 0, 0, 0),
surface: Color.fromARGB(255, 165, 158, 158),
onSurface: Color.fromARGB(255, 0, 0, 0),
error: Color.fromARGB(255, 233, 56, 44),
onError: Color.fromARGB(255, 124, 8, 0),
brightness: Brightness.light,
);
final dark = const ColorScheme(
/*Light Color OF Icons*/ primary: Color.fromARGB(255, 9, 75, 9),
/*Dark Color OF Icon/Buttons*/ secondary: Color.fromARGB(255, 23, 159, 168),
onPrimary: Colors.white,
onSecondary: Colors.amber,
/*BACKGROUND OF APP*/ background: Color.fromARGB(255, 0, 0, 0),
/*Appbar,Big Widgets etc*/ onBackground: Color.fromARGB(255, 255, 255, 255),
surface: Color.fromARGB(255, 231, 214, 199),
onSurface: Color.fromARGB(255, 0, 0, 0),
error: Color.fromARGB(255, 233, 56, 44),
onError: Color.fromARGB(255, 124, 8, 0),
brightness: Brightness.dark,
);
}
Now create an istance of your data class through main, and implement a listener to that instance, anywhere in your app like this:
ChangeNotifierProvider(
create: (context) => LightDarkMode(),
)
],
builder: (context, child) => Consumer<LightDarkMode>(
builder: (context, value, child) => MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',darkTheme: ThemeData() ,
theme: ThemeData(colorScheme: value.currentMode ? value.dark : value.light),
home: const Calculator(),
),
Widget build(BuildContext context) {
final device = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text(
'Calculator',
style: TextStyle(color: Colors.white, fontSize: 24),
),
backgroundColor: Theme.of(context).colorScheme.primary,
actions: [
Consumer<LightDarkMode>(
builder: (context, value, child) => ToggleButtons(
borderWidth: 0,
isSelected: selected,
onPressed: (index) {
selected[0] = !selected[0];
value.switchMode(selected[0]);
},
children: [Icon(value.currentMode == true ? Icons.mode_night : Icons.sunny, color: value.currentMode == true ? Colors.amber : Colors.white)],
),
)
]),
need to pass some custom color to the fellow widget
? – Striatedbackground:Colors.white
i wantbackground:store.xColor
– Colander