DefaultTextStyle Widget in Flutter

The text style to apply to descendant Text widgets that don't have an explicit style.


Properies


  • textWidthBasis
  • textHeightBehavior
  • textAlign
  • style
  • softWrap
  • runtimeType
  • overflow
  • maxLines
  • key
  • hashCode
  • child

Example:


import 'package:flutter/material.dart';


void main() {

  runApp(

    MaterialApp(

      home: Scaffold(

        appBar: AppBar(

          title: const Text(

            'Sample App',

          ),

        ),

        body: Column(

          children: [

            DefaultTextStyle(

              style: const TextStyle(fontSize: 50, color: Colors.red),

              child: Column(

                children: const [

                  Text('First'),

                  Text('Second'),

                  Text('Third'),

                  Text('Fourth'),

                ],

              ),

            ),

          ],

        ),

      ),

    ),

  );

}


Example:


Column(

                children: const [

                  Text('First'),

                  Text(

                    'Second',

                    style: TextStyle(fontSize: 10, color: Colors.blue),

                  ), // Text

                  Text(

                    'Third',

                    style: TextStyle(fontSize: 80, color: Colors.green),

                  ),

                  Text('Fourth'),

                ],

              ),


Video Link:

Post a Comment (0)
Previous Post Next Post