flutterwidgetstatelesswidget

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

  • 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