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
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [DefaultTextStyle].
8
9void main() => runApp(const DefaultTextStyleApp());
10
11class 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
23class 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

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com