0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Flutterのダークモード対応

Posted at

コード

title_list_view.dart
import 'package:flutter/material.dart';

class TitleListView extends StatelessWidget {
  const TitleListView({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
      ),
      darkTheme: ThemeData.dark(), // ここを追加
      home: Scaffold(
        floatingActionButton: FloatingActionButton(onPressed: null, child: const Icon(Icons.add),),
      )
    );
  }
}
title_list_view.dart
darkTheme: ThemeData.dark()
  • MaterialAppを定義している最上位のViewにてdarkThemeThemeData.dark()を適用するだけで自動的にダークモードの色変更対応をしてくれる。

注意

  • MaterialAppにはdarkTheme を定義出来るプロパティがあるが、Scaffoldからは変更できない。これはMaterialAppがアプリのベースのUIを管理するWidgetだからである。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?