'Hot reload was rejected: Const class cannot become non-const
I want to remove debug banner and top bar with battery level and wifi icons. but it displays an error. where should I correct my code? here I have included my main. dart and home. dart.
error>> Hot reload was rejected: Const class cannot become non-const: Library:'package:groceries_app/main.dart' Class: MyApp. Try performing a hot restart instead.
main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:groceries_app/home.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent));
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Groceries App',
home: HomePage(),
);
}
}
home.dart
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget{
@override
_HomePageState createState() => _HomePageState();}
class _HomePageState extends State <HomePage>{
@override
Widget build (BuildContext context){
return Scaffold(
body: Center(
child: Text("Home Page"),
),
);
}
}
Solution 1:[1]
Just stop running the app. Then run afresh.
It means you changed a class constructor from being const to not, or vice-versa. Hot reloading will not understand it. Stop execution of the app and run again
Solution 2:[2]
If the apps has already been running, the main class has been registered. So, if this class has been changed as const or not const from one to another, it is showing this problem.
In this case, we need to restart it to make it resolved the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Md. Majharul Haque |