'what is the difference between creating widget using widget class, and creating class widget that extend statelessWidget?
so i have this code:
import 'package:flutter/material.dart';
void main() {
runApp(const 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) {
return MaterialApp(
home: Home()
);
}
}
Widget Home() {
return Container(child: Text('aa'),);
}
class Home2 extends StatelessWidget {
const Home2({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(child: Text('aa'));
}
}
what is the difference between Home() and Home2()? will they work the same or they have something special?
Solution 1:[1]
Usually 'Home' function is called 'Helper method'.
Here is a official flutter video that exlain difference between helper method and widget.
https://www.youtube.com/watch?v=IOyq-eTRhvo&ab_channel=Flutter
- The widgets in helper method is not detected in widget tree structure
- performance: Helper method is all rebuilded when it needs refresh.
- When the code is changed in Helper method, hot reload is not worked
...and so on..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KuKu |
