INDEX / JOURNAL / LOG-012
VOL. 2026 · ENGINEERING
SERIES 5 / 8
LOG-012 · THEME & L10N

見た目と文言を一箇所に集める

PUBLISHED
2026 · 08 · 28
AUTHOR
MIGIWAYA
READ
約 5 分
TAGS
#flutter#dart

§ 01THEME

lib/app.dartDART
MaterialApp.router(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF2A6DF4)),
textTheme: const TextTheme(
titleMedium: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
bodyMedium: TextStyle(fontSize: 14, height: 1.7),
),
),
routerConfig: router,
)
DART
final theme = Theme.of(context);
 
Text('在庫', style: theme.textTheme.titleMedium);
Container(color: theme.colorScheme.surface);

§ 02COLORSCHEME

役割使いどころ
主要なボタン、強調したい要素
補助的な強調
カードやシートなど、面の背景
エラー表示
その色の上に載せる文字やアイコンの色

§ 03DARK

lib/app.dartDART
MaterialApp.router(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: brandSeed),
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: brandSeed,
brightness: Brightness.dark,
),
),
themeMode: ThemeMode.system, // 端末の設定に従う
routerConfig: router,
)
lib/providers/theme_mode_provider.dartDART
final themeModeProvider =
NotifierProvider<ThemeModeNotifier, ThemeMode>(ThemeModeNotifier.new);
 
class ThemeModeNotifier extends Notifier<ThemeMode> {
@override
ThemeMode build() => ThemeMode.system;
 
void select(ThemeMode mode) => state = mode;
}

§ 04TOKENS

lib/theme/app_tokens.dartDART
class AppTokens extends ThemeExtension<AppTokens> {
const AppTokens({required this.gutter, required this.cardRadius});
 
final double gutter;
final double cardRadius;
 
@override
AppTokens copyWith({double? gutter, double? cardRadius}) => AppTokens(
gutter: gutter ?? this.gutter,
cardRadius: cardRadius ?? this.cardRadius,
);
 
@override
AppTokens lerp(AppTokens? other, double t) {
if (other == null) return this;
return AppTokens(
gutter: lerpDouble(gutter, other.gutter, t)!,
cardRadius: lerpDouble(cardRadius, other.cardRadius, t)!,
);
}
}
DART
ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: brandSeed),
extensions: const [AppTokens(gutter: 16, cardRadius: 12)],
)

§ 05ASSETS

pubspec.yamlYAML
flutter:
assets:
- assets/images/
fonts:
- family: NotoSansJP
fonts:
- asset: assets/fonts/NotoSansJP-Regular.ttf
- asset: assets/fonts/NotoSansJP-Bold.ttf
weight: 700

§ 06L10N

l10n.yamlYAML
arb-dir: lib/l10n
template-arb-file: app_ja.arb
output-localization-file: app_localizations.dart
lib/l10n/app_ja.arbJSON
{
"@@locale": "ja",
"save": "保存",
"stockCount": "{count} 件の在庫",
"@stockCount": {
"placeholders": {
"count": { "type": "int" }
}
}
}
lib/app.dartDART
MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routerConfig: router,
)
DART
final l10n = AppLocalizations.of(context)!;
 
Text(l10n.save);
Text(l10n.stockCount(items.length));
lib/l10n/app_en.arbJSON
{
"stockCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}"
}

§ 07LOCALE

lib/app.dartDART
MaterialApp.router(
locale: ref.watch(localeProvider), // null なら端末設定に従う
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routerConfig: router,
)
DART
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'); // 簡体字
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'); // 繁体字

§ 08SUMMARY

脚注 · NOTES
  1. [1]
  2. [2]
  3. [3]
  4. [4]
  5. [5]
同シリーズ · Flutter の基礎を実コードで学ぶ II
§ + RELATED すべて見る →
INQUIRY
CONTACT
LOCATION
STATUS
Active / Open
ESTABLISHED
2024 · 5 · 5
FORM