官网示例:
复制过来的代码:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
// import 'package:flutter/foundation.dart';
// import 'dart:developer';
// void main() {
// runApp(const MyApp());
// }
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
print('测试1111 ${MyApp}');
return MaterialApp(
title: '33333 Demo',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to myapp11'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}
如果和官网一样不写const MyApp({Key? key}) : super(key: key);
就会报错
我把这行代码加上就不会报错,而且不太理解为什么MyApp类里又const一个MyApp变量
这是构造方法,就是别的语言中的 init