Sachihiro
Sachihiro

Reputation: 1793

Creating default values t.d <style> </style> at flutter

i want to create some default values like text size, background color etc, can i use the same logic as it is in android, is anyone that can help me. thanks

`<style name="Style">
  <item name="android:textSize">10pt</item>
</style>` 

Upvotes: 0

Views: 370

Answers (1)

Razvan Cristian Lung
Razvan Cristian Lung

Reputation: 6071

Regarding text style we have TextTheme and the TextStyle classes that can help you with that.

You can set up a const TextStyle value in your main.dart file like this:

const style = const TextStyle(
  fontSize: 10.0,
  fontWeight: FontWeight.bold,
);

You can use this in any file that imports the main file:

import 'package:<you package name>/main.dart';

If you want a global style specific to your need depending on the text type, you can use a TextTheme. You have to pass this values to you MaterialApp widget like this:

    new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        textTheme: const TextTheme(
          //the styles you want
        )
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    )

Then in you code, especially in your build methods where you have a BuildContext reference, you can call:

Theme.of(context).textTheme.body1;

Upvotes: 2

Related Questions