Flutter热重装无法显示更改

问题描述 投票:0回答:1

我有两个文件,main.dartsections.dart

我在section.dart中定义了一些小部件,并在main.dart文件中使用了它们,当我运行flutter run时,命令更改会显示在屏幕上,但是当我按R进行热重装时,屏幕上没有任何变化。

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"),
      ],
    ),
    );

也许是因为我在重复:

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

sections.dart中,或与主要功能有关。

flutter flutter-layout
1个回答
0
投票

有时抖动会与大量更改混淆,您需要执行重新启动,尤其是在与整个Appmain函数进行交互时。

您可以按Ctrl+C取消flutter run进程,然后尝试再次启动它。另外,如果您通过IntelliJ或Android Studio运行Flutter,则flutter插件将包含“热重启”功能,可以完成相同的操作。

© www.soinside.com 2019 - 2024. All rights reserved.