I have just started using Flutter and i'm having this problem while running my code "Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'". And the interesting part is that i dont even have this 'StatelessWidget' in my code.
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(),
)
],
)),
);
}
}
I am really lost and would aprecciate some help!
Thanks,
MyApp
from a StatelessWidget to a StatefulWidget you need to hot restart, since it is invoked inmain