Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Text and text color not updated after Hot reload

I am trying to change the text and it's color in hot reload

void main() {
  runApp(new getMyView();
}

Center getMyView() {
  return Center(
    child: Text("Nepali",
        style: TextStyle(color: Colors.amber),
        textDirection: TextDirection.ltr),
  );
}

But when I change "Nepali" to "Nepal" or I change Colors.amber to Colors.white and hot reload, it does not get reflected in the emulator.

I have to "Full Restart" the app to see the changes

like image 514
erluxman Avatar asked May 27 '18 16:05

erluxman


1 Answers

Problem : As @JonahWilliams described main() is executed only once in the whole app session.

Solution : Do the UI change inside Widget

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

class MyView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Center(
      child: Text("Nepali",
          style: TextStyle(color: Colors.white),
          textDirection: TextDirection.ltr),
    );
  }
}
like image 126
erluxman Avatar answered Sep 20 '22 05:09

erluxman