LoginSignup
0
0

More than 1 year has passed since last update.

FlutterでListTileの文字のデフォルトのフォントサイズを変更する

Posted at

ListTileクラスの文字のデフォルトのフォントサイズを変更したい。

ListTitleクラスでつかTextクラスのフォントサイズはTextThemaクラスのsubtitle1プロパティで設定されておりsizeは16だ。
なぜsubtitle1のプロパティなのかはドキュメントを探しても見当たらないのでわかる人がいたら教えてほしい。

よってTextクラスのデフォルトのフォントサイズを変えるには以下のように記載する。

textTheme: TextTheme(
  subtitle1: TextStyle(fontSize: 180.0),
),

コードの全体も記載する。

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        textTheme: TextTheme(
          subtitle1: TextStyle(fontSize: 180.0),
        ),
      ),
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const Center(
          child: MyStatefulWidget(),
        ),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  bool _lights = false;

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      ListTile(title: Text("ListTitle"), leading: Icon(Icons.ac_unit)),
    ]);
  }
}


image.png

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