runapp in flutter
runapp in flutter

In Flutter, The runApp() function is used to initialize the application and start it. It’s basically a starting point on any flutter application, The runApp(<arg>) as an argument it accept a widget, which is the top-level widget that will be used as the root of the app’s widget tree. This runApp in flutter is should be called in main() function of flutter code and it will kick off the process and render the UI of flutter app on the user screen.

If you have a root-level widget called MyApp, you can run the flutter app using the following code:

void main() {
  runApp(MyApp());
}

Typically runApp() function is called within main() function of flutter app, As I said above it’s an staring point of any flutter app execution. You can say it as entry point of app, it is the first method that execute when user start your flutter app.

Complete Example on flutter runApp()

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      home: Scaffold(
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

In Above Example, MyApp is the root widget passed to runApp(), which initializes and runs the Flutter app.

Basically runApp is responsible to create the WidgetsFlutterBinding that binds the framework and the flutter engine together, and is also responsible of creating RendererBinding object, whose task is to render the given widget on user screen.