import
'package:flutter/material.dart'
;
void
main() => runApp(
const
MyApp());
class
MyApp extends StatefulWidget {
const
MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class
_MyAppState extends State<MyApp> {
int
_themeIndex = 0;
final List<ThemeData> _themes = [
ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.blue.shade100
),
ThemeData(
primarySwatch: Colors.red,
scaffoldBackgroundColor: Colors.red.shade100
),
ThemeData(
primarySwatch: Colors.green,
scaffoldBackgroundColor: Colors.green.shade100
),
ThemeData(
primarySwatch: Colors.purple,
scaffoldBackgroundColor: Colors.purple.shade100
),
];
@override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'GFG - Flutter Themes'
,
theme: _themes[_themeIndex],
home: Scaffold(
appBar: AppBar(
title:
const
Text(
'GFG - Flutter Themes'
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RadioListTile(
title:
const
Text(
'Blue Theme'
),
value: 0,
groupValue: _themeIndex,
onChanged: _handleThemeChange,
),
RadioListTile(
title:
const
Text(
'Red Theme'
),
value: 1,
groupValue: _themeIndex,
onChanged: _handleThemeChange,
),
RadioListTile(
title:
const
Text(
'Green Theme'
),
value: 2,
groupValue: _themeIndex,
onChanged: _handleThemeChange,
),
RadioListTile(
title:
const
Text(
'Purple Theme'
),
value: 3,
groupValue: _themeIndex,
onChanged: _handleThemeChange,
),
],
),
),
),
);
}
void
_handleThemeChange(
int
? value) {
setState(() {
_themeIndex = value!;
});
}
}