Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
11d2055
-
polina-c Mar 24, 2026
484d839
-
polina-c Mar 24, 2026
545c6fc
-
polina-c Mar 24, 2026
ddf8027
Delete _error_dumper_web.dart
polina-c Mar 24, 2026
69b4f6b
-
polina-c Mar 24, 2026
1642123
-
polina-c Mar 24, 2026
27183f0
Update diagnostics.dart
polina-c Mar 24, 2026
824f099
-
polina-c Mar 24, 2026
711c89a
-
polina-c Mar 24, 2026
21fb0d6
-
polina-c Mar 24, 2026
a523c79
Update private_leak_tracking.dart
polina-c Mar 24, 2026
9fcd1b1
-
polina-c Mar 24, 2026
f1a2f9b
Update TEMP_README.md
polina-c Mar 24, 2026
9fd5d9d
Update README.md
polina-c Mar 24, 2026
92024f3
-
polina-c Mar 24, 2026
f445686
-
polina-c Mar 24, 2026
48e0b1f
-
polina-c Mar 24, 2026
44b5f4c
-
polina-c Mar 24, 2026
f122fb5
-
polina-c Mar 24, 2026
a51dc1c
-
polina-c Mar 24, 2026
a2cac58
Update ui_primitives.dart
polina-c Mar 24, 2026
37eab6d
Update pubspec.yaml
polina-c Mar 24, 2026
83535e1
Update smoke.dart
polina-c Mar 24, 2026
4e288d4
Update smoke.dart
polina-c Mar 24, 2026
42bcb79
-
polina-c Mar 24, 2026
6182ce2
-
polina-c Mar 24, 2026
05c349e
-
polina-c Mar 24, 2026
0a1ae42
-
polina-c Mar 24, 2026
0f765e2
Update diagnostics.dart
polina-c Mar 24, 2026
4e6452f
-
polina-c Mar 24, 2026
31c23ed
-
polina-c Mar 24, 2026
5fb832b
Update diagnostics.dart
polina-c Mar 24, 2026
c76611b
Update ui_primitives.dart
polina-c Mar 24, 2026
d115542
-
polina-c Mar 24, 2026
6cdfd11
-
polina-c Mar 24, 2026
2b0429a
-
polina-c Mar 25, 2026
f50ca2e
-
polina-c Mar 25, 2026
57d7958
-
polina-c Mar 25, 2026
edc1527
-
polina-c Mar 25, 2026
b07444d
Update TEMP_README.md
polina-c Mar 25, 2026
4840115
Update TEMP_README.md
polina-c Mar 25, 2026
65290be
Update pubspec.yaml
polina-c Mar 25, 2026
9b4426e
-
polina-c Mar 25, 2026
24cadcc
Update TEMP_README.md
polina-c Mar 25, 2026
f74a111
-
polina-c Mar 25, 2026
6621599
-
polina-c Mar 25, 2026
e733239
-
polina-c Mar 25, 2026
88b38da
Update packages/ui_primitives/TEMP_README.md
polina-c Mar 25, 2026
16f107b
-
polina-c Mar 25, 2026
09cc1b2
Merge remote-tracking branch 'refs/remotes/origin/listen' into listen
polina-c Mar 25, 2026
1faf24a
-
polina-c Mar 25, 2026
a340b19
-
polina-c Mar 25, 2026
a57086e
Update value_notifier.dart
polina-c Mar 25, 2026
f60d34d
-
polina-c Mar 25, 2026
8566e90
Update ui_primitives.dart
polina-c Mar 26, 2026
ec287de
Update ui_primitives.dart
polina-c Mar 26, 2026
06156e6
-
polina-c Mar 26, 2026
70e6228
Merge remote-tracking branch 'upstream' into uip
polina-c Mar 26, 2026
c14b912
Update TEMP_README.md
polina-c Mar 26, 2026
5d177d9
-
polina-c Mar 26, 2026
bac6ad6
Update value_notifier.dart
polina-c Mar 26, 2026
91bad8f
-
polina-c Mar 26, 2026
07d6d3b
Merge remote-tracking branch 'upstream' into uip
polina-c Mar 26, 2026
e766b16
-
polina-c Mar 26, 2026
c9cb419
Update value_notifier.dart
polina-c Mar 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions packages/ui_primitives/lib/src/foundation/value_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,33 @@ class _ChangeNotifier implements Listenable {
///
/// Because of this behavior, [ValueNotifier] is best used with immutable data
/// types.
interface class ValueNotifier<T> implements ValueListenable<T> {
class ValueNotifier<T> implements ValueListenable<T> {
final _ChangeNotifier _changeNotifier = _ChangeNotifier();

/// Creates a [_ChangeNotifier] that wraps this value.
ValueNotifier(this._value) {
if (kTrackMemoryLeaks) {
debugMaybeDispatchCreated(runtimeType.toString(), this);
}
assert(() {
if (kTrackMemoryLeaks) {
debugMaybeDispatchCreated(runtimeType.toString(), this);
}
return true;
}());
}

bool _debugDisposed = false;

static bool debugAssertNotDisposed<T>(ValueNotifier<T> notifier) {
assert(() {
if (notifier._debugDisposed) {
throw UiError(
'A ${notifier.runtimeType} was used after being disposed.\n'
'Once you have called dispose() on a ${notifier.runtimeType}, it '
'can no longer be used.',
);
}
return true;
}());
return true;
}

/// The current value stored in this notifier.
Expand All @@ -426,9 +445,12 @@ interface class ValueNotifier<T> implements ValueListenable<T> {
String toString() => '${describeIdentity(this)}($value)';

void dispose() {
if (kTrackMemoryLeaks) {
debugMaybeDispatchDisposed(this);
}
assert(() {
_debugDisposed = true;
if (kTrackMemoryLeaks) debugMaybeDispatchDisposed(this);
return true;
}());

_changeNotifier.dispose();
}

Expand All @@ -439,4 +461,10 @@ interface class ValueNotifier<T> implements ValueListenable<T> {
@override
void removeListener(VoidCallback listener) =>
_changeNotifier.removeListener(listener);

@protected
bool get hasListeners => _changeNotifier.hasListeners;

@protected
void notifyListeners() => _changeNotifier.notifyListeners();
}
2 changes: 1 addition & 1 deletion packages/ui_primitives/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: ui_primitives
description: Highly experimental package.
repository: https://github.com/flutter/genui/tree/main/packages/ui_primitives
version: 0.0.1-dev-003
version: 0.0.1-dev-005

resolution: workspace

Expand Down
13 changes: 12 additions & 1 deletion packages/ui_primitives/test/smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:test/test.dart';
import 'package:ui_primitives/ui_primitives.dart';

// ignore: unused_element, tests that ValueNotifier can be implemented.
class _ValueNotifierOtherImplementaion<T> implements ValueNotifier<T> {
class _ValueNotifierImplementaion<T> implements ValueNotifier<T> {
@override
void addListener(VoidCallback listener) {}

Expand All @@ -21,6 +21,17 @@ class _ValueNotifierOtherImplementaion<T> implements ValueNotifier<T> {

@override
set value(T newValue) {}

@override
bool get hasListeners => throw UnimplementedError();

@override
void notifyListeners() {}
}

// ignore: unused_element, tests that ValueNotifier can be extended.
class _ValueNotifierExtention<T> extends ValueNotifier<T> {
_ValueNotifierExtention(super.value);
}

void main() {
Expand Down
Loading