У меня есть этот код Flutter с двумя виджетами. Виджет с MaterialApp и одним ThemeData, который вызывает виджет без сохранения состояния с помощью одной кнопки.
Я хочу иметь более одного ThemeData и переключаться между ними с помощью кнопки.
Возможно ли?
Спасибо
import 'package:flutter/material.dart';
void main() {
runApp(const MyWidget());
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
fontFamily: 'Roboto',
appBarTheme: AppBarTheme(
color: Colors.green
),
primaryColor: Colors.deepOrangeAccent,
textTheme: const TextTheme(
displayLarge:
TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
titleLarge: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyMedium: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Custom Theme App'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
},
child: const Text('Theme Button'),
),
),
);
}
}
Подробнее здесь: https://stackoverflow.com/questions/766 ... -themedata