import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child:
Container(
height: 200,
width: 100,
color: Colors.yellow,
),
),
);
}
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("asset/image/Bestone.jpg")))));
}
}
无论我使用什么,当我试图运行或编码时都会遇到问题。我得到这个错误。
缺少'StatefulWidget. createState'的具体实现。尝试实现缺少的方法,或者使类为MyApp()抽象
1条答案
按热度按时间wvyml7n51#
StatefulWidget
需要重写方法createState
,因此必须重写该方法。删除构建方法并在MyApp中指定以下行完整的例子与适当的StateFulWidget