jas*_*dhi 3 themes dart flutter
我按以下方式使用 ThemeData():
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterrequirements/ModelClasses/note.dart';
class CreateNewNote extends StatefulWidget {
@override
_CreateNewNoteState createState() => _CreateNewNoteState();
}
class _CreateNewNoteState extends State<CreateNewNote> {
bool isStoringInDatabase = false;
//var obj = Note.nothing();
var _formKey = GlobalKey<FormState>();
saveLocally() async {
//storing data in sqflite
}
String titleNote;
String descriptionNote;
//var appTheme=//
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: Colors.white,
appBarTheme: AppBarTheme(
color: Color.fromRGBO(90, 50, 142, 1),
textTheme: TextTheme(
//rgb(136,252,254)
title: TextStyle(
color: Color.fromRGBO(136, 252, 254, 1),
fontSize: 20,
fontStyle: FontStyle.italic),
),
),
primaryTextTheme: TextTheme(
title: TextStyle(),
button: TextStyle(),
).apply(
bodyColor: Color.fromRGBO(136, 252, 254, 1),
displayColor: Color.fromRGBO(136, 252, 254, 1),
)),
home: Scaffold(
appBar: AppBar(
title: Text(
"MemoNotes",
),
),
body: Form(
key: _formKey,
child: Container(
margin: EdgeInsets.fromLTRB(5, 20, 30, 60),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Flexible(
child: FractionallySizedBox(
heightFactor: 0.3,
),
),
Text("Title:"),
TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.purpleAccent)),
prefixIcon: Icon(Icons.text_fields),
hintText: "Enter the title",
prefixText:
" " //to show gap between icon and title
),
validator: (_) => null,
onSaved: (val) => titleNote = val,
),
Flexible(
child: FractionallySizedBox(
heightFactor: 0.3,
),
),
Text("Description:"),
TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.purpleAccent)),
prefixIcon: Icon(Icons.description),
hintText: "Enter the description",
prefixText: " "),
validator: (_) => null,
onSaved: (val) => descriptionNote = val,
),
Builder(
builder: (context) {
return RaisedButton(
child: Text("SAVE THIS NOTE"),
color: Colors.greenAccent,
onPressed: () {
saveLocally();
setState(() {
isStoringInDatabase = true;
});
});
},
),
],
)),
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试了如何更改主题的文本颜色?但这对我不起作用。
我的颜色和文本主题确实适用于应用程序栏,但我使用的主要文本主题不适用于其余应用程序。
如何使文本“标题”和“描述”具有我在主题中指定的颜色?
您可以在 Material 应用程序中设置 textTheme 属性。这适用于整个应用程序
MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
bodyText1: TextStyle(),
bodyText2: TextStyle(),
).apply(
bodyColor: Colors.orange,
displayColor: Colors.blue,
),
),
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7846 次 |
| 最近记录: |