Issue
I am new to Android Development. I created a flutter project and just returned a Text Widget using a stateless class but I am getting this error. I tried reading about it on the blogs regarding this error. I think its related to calling an instance of a stateless widget in the same class itself but I am not sure.
Here's my code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text('Hello'),
);
}
}
What to do ?
Solution
You must use MaterialApp Widget in the beginning. If you do this, the problem will be solved. But I recommend you to wrap the Text Widget with Scaffold too.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Text('Hello'),
);
}
}
Answered By - Hazar Belge
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.