lukehutch / flutter_reactive_value Goto Github PK
View Code? Open in Web Editor NEWUltra-simple state management and reactivity for Flutter UIs
License: Other
Ultra-simple state management and reactivity for Flutter UIs
License: Other
From the README.md:
Now whenever counter.value changes (here using counter.value++ in the onPressed handler), the enclosing widget (here HomeView) will be scheduled for rebuilding.
(The only place you're not allowed to update counter.value is the build method of a widget, since state changes are disallowed in build methods.)
That's all there is to it!
"Upon reading this in your documentation, I am curious: wouldn't we only want the Text widget to rebuild instead of the enclosing widget (in this case, HomeView)?"
What's the best way to dispose a listener?
...
@override
void dispose() {
// on dispose
super.dispose();
}
...
// reactive value is in nested child
child: Builder(builder: (context) {
final val = value.reactiveValue(context);
return Text(val);
})
Based on the code, a new listener is registered on every rebuild and removed when the callback runs. There's is a bug when the widget is rebuilt is triggered from another ValueNotifier.
We have 2 ValueNotifiers: age
and username
Profile widget is watching both thus resulting in 1 listener being registered for each ValueNotifier
username
is modified causing ProfileWidget to rebuild, another listener is registered for each but the old listener for age
is still registered. It will register an unlimited amount of listeners until its value has changed.
Hi! I'm a Flutter beginner coming from Android development. I have tried serveral state management approaches in Flutter offical document. I come from here. Most of them are not very easy to use(high learning cost), and not friendly to beginners. Thanks god, the last one in the document saves my day! Yes, this tool is soooo awesome!
Advantages:
Starred! Keep forward :D
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 library (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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.