Skip to content

Commit

Permalink
value protected for vm
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonaCodes committed Nov 22, 2024
1 parent 5767135 commit 03e43ff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 425 deletions.
51 changes: 40 additions & 11 deletions lib/src/implements/notifier_impl.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:flutter/foundation.dart';

@protected
abstract class NotifierImpl<T> extends ChangeNotifier
implements ValueListenable<T> {
/// value return.
abstract class NotifierImpl<T> extends ChangeNotifier implements ValueListenable<T> {
T _value;
NotifierImpl(this._value) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}


@override
T get value => _value;

Expand All @@ -36,12 +37,40 @@ abstract class NotifierImpl<T> extends ChangeNotifier
String toString() => '${describeIdentity(this)}($value)';
}

// abstract class ValueListenable<T> extends Listenable {
// /// Abstract const constructor. This constructor enables subclasses to provide
// /// const constructors so that they can be used in const expressions.
// const ValueListenable();
//
// /// The current value of the object. When the value changes, the callbacks
// /// registered with [addListener] will be invoked.
// T get state;
// }

@protected
abstract class StateNotifierImpl<T> extends ChangeNotifier implements ValueListenable<T> {
T _value;
StateNotifierImpl(this._value) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}


@protected
@override
T get value => _value;

/// [updateState]
/// Updates the state and notifies listeners if the value has changed.
///
void updateState(T newState) {
if (_value == newState) {
return;
}

_value = newState;
notifyListeners();
}

/// [updateSilently]
/// Updates the value silently without notifying listeners.
///
void updateSilently(T newState) {
_value = newState;
}

@override
String toString() => '${describeIdentity(this)}($value)';
}
Loading

0 comments on commit 03e43ff

Please sign in to comment.