Hive generated file Error - "control-flow-collections" experiment is not enabled - Flutter/Dart
1,692
I found a solution, run the following command in the root folder of your flutter app(not flutter SDK):
flutter analyze
And you will see multiple warning, saying that there is no experiment defined for "control-flow-collections", the problem is that the SDK defined in the pubspec.yaml of your Flutter App folder contains
environment:
sdk: ">=2.1.0 <3.0.0"
There is not supported experiment before the 2.3.0 version so you have to change the version to:
environment:
sdk: ">=2.3.0 <3.0.0"
then run:
flutter pub get
in the root of your flutter app and rerun, "flutter analyze", and the issue goes away.
Author by
Somanshu Singh
Updated on December 17, 2022Comments
-
Somanshu Singh over 1 year
// GENERATED CODE - DO NOT MODIFY BY HAND part of 'dbmodel.dart'; // ************************************************************************** // TypeAdapterGenerator // ************************************************************************** class CacheAdapter extends TypeAdapter<Cache> { @override final typeId = 4; @override Cache read(BinaryReader reader) { var numOfFields = reader.readByte(); var fields = <int, dynamic>{ for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), }; return Cache( isDarkMode: fields[0] as bool, ); } @override void write(BinaryWriter writer, Cache obj) { writer ..writeByte(1) ..writeByte(0) ..write(obj.isDarkMode); } }
There is an error in the for loop of the Hive generated file, where it says that the "control-flow-collections" experiment is not enabled.
for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
Can anyone help me with it?