Flutterのテーマシステムを使うと、一貫した視覚的スタイリング(色、フォント、コンポーネントスタイル)をアプリ全体で定義でき、ライトモード/ダークモードのサポートがあります。テーマを通じてスタイリングを一元化することで、一貫性が保証され、アプリを簡単に再スタイリングできます。
テーマの定義
// define the app's theme in MaterialApp
MaterialApp(
theme: ThemeData( // LIGHT theme
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
textTheme: TextTheme(/* font styles */),
elevatedButtonTheme: /* button styling */,
useMaterial3: true,
),
darkTheme: ThemeData.dark(), // DARK theme
themeMode: ThemeMode.system, // follow the system setting (or .light/.dark)
)
テーマは色、タイポグラフィ、コンポーネントスタイルを一元的に定義し、アプリ全体に適用されます。
