Flutter hot reloading is not working to display changes

こ雲淡風輕ζ 提交于 2019-12-24 18:54:16

问题


I have two files, main.dart and sections.dart.

I have defined a few widgets in section.dart and used them in main.dart file, when I run flutter run command changes are displayed on screen, but when I press R to hot reload, nothing changes on screen.

main.dart:

import 'package:flutter/material.dart';
import 'sections.dart';

void main() {
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
  return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Share IDEASS',
      home: Scaffold(
        appBar: AppBar(
          title: Text('IDEASs'),
        ),
        body: ListView(
          children: [
           labelsSection,
          ],
        ),
      ),
    );
  }
}

Sections.dart:

import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {

  Widget build(BuildContext context) {
   return MaterialApp(
      title: 'Share IDEAS',

    );
  }
}

Column labelSectionMethod(color,IconData icon, String label,String numbers){
  return Column(
    children: <Widget>[
      Icon(icon, color:color),
      Container(
        child: Text(label,
        style: TextStyle(color: color
        ),
        ),
      ),
      Container(
        child:Text(numbers,
      style:TextStyle(color:color
      ),
      ),
      ),
    ],
  );
}

    Widget labelsSection=Container(
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        labelSectionMethod(Colors.red,Icons.supervised_user_circle,"IDEASS","35"),
        labelSectionMethod(Colors.red,Icons.favorite,"LIKE","22"),
        labelSectionMethod(Colors.red,Icons.data_usage,"STREAK","12"),
      ],
    ),
    );

Maybe because I am repeating:

 return MaterialApp(
title: 'Share IDEAS',
    );

in sections.dart, or something to do with main function.

UPDATE:

i moved content of sections.dart file in main.dart file still hot reload is not working.


回答1:


This usually happens when you have change a lot of code, added states, changed a widget from stateless to state full, etc. Preforming a hot restart (ctrl +F5) will fix this issue. If this seems to not work still, try removing the app from your phone/simulator/emulator (closing the app, and deleting it) and running debug/flutter run again. This should fix your issue




回答2:


Sometimes flutter gets confused with large amounts of changes, and you need to perform a restart, especially when interacting with the entire App or main function.

You can pressCtrl+C to kill the flutter run process, and try launching it again. Additionally, if you run Flutter through IntelliJ or Android Studio, the flutter plugin includes a "Hot Restart" feature which accomplishes the same thing.



来源:https://stackoverflow.com/questions/59275023/flutter-hot-reloading-is-not-working-to-display-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!