| 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:flutter/material.dart'; |
| 6 | |
| 7 | /// Flutter code sample for [DefaultTextStyle]. |
| 8 | |
| 9 | void main() => runApp(const DefaultTextStyleApp()); |
| 10 | |
| 11 | class DefaultTextStyleApp extends StatelessWidget { |
| 12 | const DefaultTextStyleApp({super.key}); |
| 13 | |
| 14 | @override |
| 15 | Widget build(BuildContext context) { |
| 16 | return MaterialApp( |
| 17 | theme: ThemeData(brightness: Brightness.light, colorSchemeSeed: Colors.purple), |
| 18 | home: const DefaultTextStyleExample(), |
| 19 | ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | class DefaultTextStyleExample extends StatelessWidget { |
| 24 | const DefaultTextStyleExample({super.key}); |
| 25 | |
| 26 | @override |
| 27 | Widget build(BuildContext context) { |
| 28 | return Scaffold( |
| 29 | appBar: AppBar(title: const Text('DefaultTextStyle.merge Sample' )), |
| 30 | // Inherit MaterialApp text theme and override font size and font weight. |
| 31 | body: DefaultTextStyle.merge( |
| 32 | style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold), |
| 33 | child: const Center(child: Text('Flutter' )), |
| 34 | ), |
| 35 | ); |
| 36 | } |
| 37 | } |
| 38 | |