Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter hot reloading is not working to display changes

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.

like image 551
Fayakon Avatar asked Dec 05 '22 09:12

Fayakon


2 Answers

After moving a file to another directory, Android Studio changed my imports to absolute paths.

import 'file:///C:/Users/svenv/AndroidStudioProjects/sample_screen_collection/lib/welcome/reading_list_card.dart';

i had to change it to this

import 'package:samplescreencollection/components/reading_list_card.dart';
like image 169
snowman Avatar answered Feb 14 '23 23:02

snowman


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

like image 23
mrgnhnt96 Avatar answered Feb 14 '23 23:02

mrgnhnt96