1

Flutter hot reload fails on the code below

import 'package:flutter/material.dart';

void main() {
  runApp(
    Center(
      child: Text(
        'Hello, world!',
        textDirection: TextDirection.ltr,
      ),
    ),
  );
}

but it works if I extract a widget out of main method as below.

import 'package:flutter/material.dart';

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

class HelloWorldWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'Hello World 7',
        textDirection: TextDirection.ltr,
      ),
    );
  }
}

Why does hot reload work in one case but not the other?

ams
  • 60,316
  • 68
  • 200
  • 288
  • While this is not a one to one duplicate, https://stackoverflow.com/questions/53234825/what-is-the-difference-between-functions-and-classes-to-create-widgets should explain pretty clearly why it happens. – Rémi Rousselet Dec 02 '18 at 19:58

0 Answers0