Created
May 15, 2022 19:25
-
-
Save rydmike/4dda93399426d79373fe296d46152a66 to your computer and use it in GitHub Desktop.
Flutter Typography Toggle Assert Issue
This file contains 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/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
const MyApp({super.key}); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
ThemeMode themeMode = ThemeMode.light; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Typography theme toggle issue', | |
debugShowCheckedModeBanner: false, | |
themeMode: themeMode, | |
theme: ThemeData( | |
brightness: Brightness.light, | |
typography: Typography.material2021(platform: defaultTargetPlatform)), | |
darkTheme: ThemeData( | |
brightness: Brightness.dark, | |
typography: Typography.material2018(platform: defaultTargetPlatform), | |
), | |
home: Scaffold( | |
body: Center( | |
child: HomePage( | |
darkMode: themeMode == ThemeMode.dark, | |
onChangedDarkMode: (bool value) { | |
setState(() { | |
if (value) { | |
themeMode = ThemeMode.dark; | |
} else { | |
themeMode = ThemeMode.light; | |
} | |
}); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} | |
class HomePage extends StatelessWidget { | |
const HomePage( | |
{super.key, required this.darkMode, required this.onChangedDarkMode}); | |
final bool darkMode; | |
final ValueChanged<bool> onChangedDarkMode; | |
@override | |
Widget build(BuildContext context) { | |
return ListView( | |
children: [ | |
Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8.0), | |
child: Text( | |
'Typography theme toggle issue', | |
style: Theme.of(context).textTheme.headlineSmall, | |
), | |
), | |
SwitchListTile( | |
title: const Text('Use dark mode'), | |
value: darkMode, | |
onChanged: onChangedDarkMode, | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment