我刚刚开始使用 Flutter,在运行代码时遇到了这个问题“引发了另一个异常:类型‘MyApp’不是‘StatelessWidget’类型的子类型”。有趣的是,我的代码中什至没有这个“StatelessWidget”。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
List<String> _bars = ['Olivio bar'];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Drinkzz'),
),
body: Column(
children: [
Container(
margin: EdgeInsets.all(10.0),
child: RaisedButton(
onPressed: () {
_bars.add('Riviera Bar');
},
child: Text('Add new Bar!'),
),
),
Column(
children: _bars
.map((element) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/olivio.jpg'),
Text(element)
],
),
))
.toList(),
)
],
)),
);
}
}
我真的迷路了,希望能得到一些帮助!
谢谢,