Flutter中的编写样式
flutter中的编写样式,是通过dart语法中定义函数的可选命名参数来实现的,且在传入实体对象时,可省略new关键字
Flutter定义的程序入口函数
在main方法中被调用,参数接收一个widget
runApp(Widget widget);
示例
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main(){
//flutter中定义的入口方法,参数接收一个widget
runApp(MyApp());
}
//自定义的app主体
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
//系统自带的Material样式app
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('标题'),
),
body: HomeBody()
),
theme: ThemeData(
primarySwatch: Colors.yellow
),
);
}
}
//自定义的home中的body
class HomeBody extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Text(
"hello flutter",
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.red,
fontSize: 40,
),
),
);
}
}