第2节:Flutter的Hello World
一、本节内容介绍
1、本节代码
1.1、其中完整的main.dart代码如下:
main.dart代码如下:import 'package:flutter/material.dart';
// 方法①
// >>>>>>>>>>>>> start >>>>>>>>>>>>>
// void main() => runApp(const Center(
// child: Text('1.Hello, world! in Main', textDirection: TextDirection.ltr)));
// <<<<<<<<<<<<< end <<<<<<<<<<<<<
// 方法②
// >>>>>>>>>>>>> 方法② >>>>>>>>>>>>>
// void main() => runApp(MyApp());
// class MyApp extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return const Center(
// child: Text('2.Hello, world! in MyApp return!', textDirection: TextDirection.ltr));
// }
// }
// <<<<<<<<<<<<< 方法② <<<<<<<<<<<<<
// 方法③
// >>>>>>>>>>>>> 方法③ >>>>>>>>>>>>>
// void main() => runApp(MyApp());
// class MyApp extends StatelessWidget {
// helloWorldPage() {
// return Center(
// child: Text('3.Hello world! in helloWorldPage',
// textDirection: TextDirection.ltr),
// );
// }
// @override
// Widget build(BuildContext context) {
// return helloWorldPage();
// }
// }
// <<<<<<<<<<<<< 方法③ <<<<<<<<<<<<<
// 方法④
// >>>>>>>>>>>>> 方法④ >>>>>>>>>>>>>
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return HelloWorldPage();
}
}
class HelloWorldPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Text('4.Hello world! in HelloWorldPage',
textDirection: TextDirection.ltr),
);
}
}
// <<<<<<<<<<<<< 方法④ <<<<<<<<<<<<<2、代码说明
Last updated
Was this helpful?