Giter VIP home page Giter VIP logo

flutter_reactive_value's People

Contributors

aturex1 avatar lukehutch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jinyus aturex1

flutter_reactive_value's Issues

Which widget should be scheduled to rebuild upon state change?

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)?"

How to dispose a listener

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);
})

Possible memory leak

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.

Explanation:

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.

Awesome! This is the best state management tool for flutter beginners!

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:

  • very easy to use, friendly to beginners
  • similar state management experience for those who come from Android Compose
  • easy to integrate into a viewmodel

Starred! Keep forward :D

Getting an Error with just Importing the Package

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.