import 'package:flutter/material.dart';
void main(){
runApp(const Center(
child: Text("你好Flutter",textDirection: TextDirection.ltr,
style: TextStyle(
color: Color.fromRGBO(244, 244, 123, 1),
fontSize: 40
),)
));
}
- 每次写都需要利用MaterialApp 和Scaffold作为根组件
import 'package:flutter/material.dart';
void main(){
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("你好Flutter")),
body:const Center(
child: Text("你好Flutter",textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.red,
fontSize: 40
),)
) ,
),
));
}
- 对body内容进行剥离,继承StatelessWidget或StatefulWidget,做自定义组件
import 'package:flutter/material.dart';
void main(){
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("你好Flutter")),
body:const MyApp(),
),
));
}
class MyApp extends StatelessWidget{
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const Center(
child: Text("你好Flutter,我是一个自定义组件",textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.red,
fontSize: 40
)
)
);
}
}
- analysis_options.yaml 是用来检查代码语法错误的注释掉后不会自动检测