I've got a stateful widget that has a type parameter, and code-changes within it are not picked up by hot reload.
I can replicate the behaviour in a newly created project (see example below). If I change the text in "MyDummy" and save, hot reload will pick it up and show the change on the device. If I change the text in "MyTypedDummy", it will not be displayed until I do a restart, or change something in "MyDummy" and "MyTypedDummy" at the same time and then do a hot reload.
I'm using text in my example for simplicity, but other changes like wrapping the text in a container with a color will also not be shown with hot reload.
I've tried playing around with the "const" declarations and with keys, to no avail. Why does hot reload not work, and how can I fix this?
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => const MaterialApp(home: Column(children: [MyDummy(), MyTypedDummy<String>()]));
}
class MyDummy extends StatefulWidget {
const MyDummy({super.key});
@override
State<MyDummy> createState() => _MyDummyState();
}
class _MyDummyState extends State<MyDummy> {
@override
Widget build(BuildContext context) => const Text("Dummy 3");
}
class MyTypedDummy<T> extends StatefulWidget {
const MyTypedDummy({super.key});
@override
State<MyTypedDummy<T>> createState() => _MyTypedDummyState<T>();
}
class _MyTypedDummyState<T> extends State<MyTypedDummy<T>> {
@override
Widget build(BuildContext context) => const Text("Typed Dummy 5");
}
Im using Flutter 3.10.6 with Visual Studio Code and an Android device for testing.
I've been using
git checkout 3.10.6to upgrade Flutter, and even though this points to the exact same commit asstable, for some reason that causes this problem. Once I useflutter upgradeFlutter will stay at the same version, but Hot Reload works for typed classes again.