I followed the instructions for installing flutter_reactive_value as described here.
flutter pub add flutter_reactive_value
And I added the import on my main.dart:
import 'package:flutter_reactive_value/flutter_reactive_value.dart';
That's as far as I get.
I am on dart 2.18. I tried it with all versions of this package (1.0.0 - 1.0.3). Also, I downloaded the example (the entire project folder) located here and got the same error listed below. I tried this both as a Flutter web (chrome) and a Flutter Windows app.
Flutter web (Chrome) Error:
Launching lib\main.dart on Chrome in debug mode...
main.dart:1
: Error: The getter 'mounted' isn't defined for the class 'Element'.
reactive_value_notifier.dart:30
- 'Element' is from 'package:flutter/src/widgets/framework.dart' ('../flutter/packages/flutter/lib/src/widgets/framework.dart').
framework.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'mounted'.
if (elementRef.target?.mounted ?? false) {
^^^^^^^
Failed to compile application.
Exited (sigterm)
Flutter Windows Error:
Launching lib\main.dart on Windows in debug mode...
../lib/src/reactive_value_notifier.dart(30,30): error G4127D1E8: The getter 'mounted' isn't defined for the class 'Element'. [C:\workspace\flutter_reactive_value\example\build\windows\flutter\flutter_assemble.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(247,5): error MSB8066: Custom build for 'C:\workspace\flutter_reactive_value\example\build\windows\CMakeFiles\6f135da36535027a04cd8738f00853c4\flutter_windows.dll.rule;C:\workspace\flutter_reactive_value\example\build\windows\CMakeFiles\335e6badeb606c6fb4bbef90392b261d\flutter_assemble.rule;C:\workspace\flutter_reactive_value\example\windows\flutter\CMakeLists.txt' exited with code 1. [C:\workspace\flutter_reactive_value\example\build\windows\flutter\flutter_assemble.vcxproj]
Exception: Build process failed.
Exited (sigterm)
Any ideas? I am really hoping to use the simple state management that flutter_reactive_value offers. Thanks!
You get this error because of this line in flutter_reactive_value package.
The getter mounted
, as the error says, isn't defined for the class Element
.
Why it is not defined? Because this getter was added to the BuildContext
and Element
only in flutter 3.7.0
(more precisely, in 3.4.0-27.0-pre), and you are using some version below. Here are the release notes.
What can you do?
1.0.1
or below, because the getter mounted
was added to this package in version 1.0.2
.ValueListenableBuilder
, which comes out-of-the-box.