「Flutter/UI/ダークモード」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==公式== https://github.com/Norbert515/dynamic_theme ==インストール== pubspec.yaml <pre> dependencies: dynamic_theme: ^1.0.1 </pre> ==サンプル== <pre> imp...」) |
(→サンプル) |
||
行11: | 行11: | ||
==サンプル== | ==サンプル== | ||
<pre> | <pre> | ||
− | import 'package:dynamic_theme/dynamic_theme.dart';class MyApp extends StatelessWidget { | + | import 'package:dynamic_theme/dynamic_theme.dart'; |
+ | class MyApp extends StatelessWidget { | ||
@override | @override | ||
Widget build(BuildContext context) { | Widget build(BuildContext context) { |
2023年8月29日 (火) 09:45時点における最新版
公式
https://github.com/Norbert515/dynamic_theme
インストール
pubspec.yaml
dependencies: dynamic_theme: ^1.0.1
サンプル
import 'package:dynamic_theme/dynamic_theme.dart'; class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new DynamicTheme( defaultBrightness: Brightness.light, data: (brightness) => new ThemeData( primarySwatch: Colors.indigo, brightness: brightness, ), themedWidgetBuilder: (context, theme) { return new MaterialApp( title: 'Flutter Demo', theme: theme, home: new MyHomePage(title: 'Flutter Demo Home Page'), ); } ); } }
設定切り替え
void changeBrightness() { DynamicTheme.of(context).setBrightness(Theme.of(context).brightness == Brightness.dark? Brightness.light: Brightness.dark); }