Skip to content

Commit

Permalink
Add WatchBuilder to ease migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rodydavis committed Nov 28, 2024
1 parent 7b3946a commit 2d23c8c
Show file tree
Hide file tree
Showing 33 changed files with 344 additions and 159 deletions.
56 changes: 31 additions & 25 deletions benchmark/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.19.0"
version: "1.18.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -103,18 +103,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.7"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.8"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -187,34 +187,40 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
preact_signals:
dependency: transitive
description:
name: preact_signals
sha256: a5b445796a02244b85fa43d79a7030fbfbbb08f7c48277ee93c636140a8fb2e0
url: "https://pub.dev"
source: hosted
version: "1.8.3"
signals:
dependency: "direct main"
description:
path: "../packages/signals"
relative: true
source: path
version: "5.5.0"
version: "6.0.0-rc.3"
signals_core:
dependency: transitive
dependency: "direct overridden"
description:
name: signals_core
sha256: f4af1dd285e89bf0bb268676c9d175ea6fb6a894d81260f6b564decad46ad240
url: "https://pub.dev"
source: hosted
version: "5.5.0"
path: "../packages/signals_core"
relative: true
source: path
version: "6.0.0-rc.3"
signals_flutter:
dependency: transitive
dependency: "direct overridden"
description:
name: signals_flutter
sha256: "2d9678e39d698ca633c8609872354797511f2af33b4d4ee7b6bfeb487aad6258"
url: "https://pub.dev"
source: hosted
version: "5.5.0"
path: "../packages/signals_flutter"
relative: true
source: path
version: "6.0.0-rc.3"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
version: "0.0.99"
solidart:
dependency: "direct main"
description:
Expand Down Expand Up @@ -267,10 +273,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -283,10 +289,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.3"
version: "0.7.2"
vector_math:
dependency: transitive
description:
Expand All @@ -304,5 +310,5 @@ packages:
source: hosted
version: "14.2.5"
sdks:
dart: ">=3.4.0 <4.0.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
2 changes: 1 addition & 1 deletion examples/animations_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _MyHomePageState extends State<MyHomePage> {
body: Stack(
children: [
for (final rect in circles)
Watch((context, _) {
Watch((context) {
return AnimatedPositioned.fromRect(
rect: rect.value!,
duration: kThemeAnimationDuration,
Expand Down
6 changes: 3 additions & 3 deletions examples/auth_flow/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class DarkModeToggle extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Watch((_, __) {
return Watch((_) {
final isDark = brightness() == Brightness.dark;
return IconButton(
onPressed: () {
Expand Down Expand Up @@ -195,7 +195,7 @@ class _HomeScreenState extends State<HomeScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Count value:'),
Watch((context, _) {
Watch((context) {
return Text(
'$counter',
style: Theme.of(context).textTheme.headlineMedium,
Expand Down Expand Up @@ -288,7 +288,7 @@ class ProfileScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Watch((context, _) {
return Watch((context) {
return Scaffold(
appBar: AppBar(
title: Text('Profile: ${auth.currentUserName()}'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _EditTodoState extends State<EditTodo> {
),
const SizedBox(height: 16),
Watch(
(context, _) => CheckboxListTile(
(context) => CheckboxListTile(
title: const Text('Completed'),
value: completed.value,
onChanged: (val) => completed.value = val!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _TodoListViewState extends State<TodoListView> {
),
],
),
body: Watch((context, _) {
body: Watch((context) {
if (widget.viewModel.todos.isEmpty) {
return const Center(
child: Text('No todos'),
Expand Down
2 changes: 1 addition & 1 deletion examples/crud_dio/lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Watch((context, _) {
body: Watch((context) {
final posts = postsService.posts;
if (posts.value.isLoading) {
return const Center(
Expand Down
2 changes: 1 addition & 1 deletion examples/crud_dio/lib/ui/home_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _DetailPostState extends State<HomeDetail> {

@override
Widget build(BuildContext context) {
return Watch((context, _) {
return Watch((context) {
final post = postsService.post.value;
return Scaffold(
appBar: AppBar(
Expand Down
2 changes: 1 addition & 1 deletion examples/drift_example/lib/screens/home/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _CategoriesDrawerState extends State<CategoriesDrawer> {
),
),
Flexible(
child: Watch((context, _) {
child: Watch((context) {
final value = stream.value.value;
final categories = value ?? <CategoryWithCount>[];
return ListView.builder(
Expand Down
4 changes: 2 additions & 2 deletions examples/eval_calculator/lib/screens/spreadsheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _SpreadsheetCalculatorState extends State<SpreadsheetCalculator> {

Widget valueToWidget(ValueRow valueRow, BuildContext context) {
final valueDisplay = Watch(
(context, _) => Text(valueRow.signalObject.value.toString(), style: _style),
(context) => Text(valueRow.signalObject.value.toString(), style: _style),
);

if (valueRow.type == ValueType.number) {
Expand Down Expand Up @@ -59,7 +59,7 @@ class _SpreadsheetCalculatorState extends State<SpreadsheetCalculator> {
@override
Widget build(BuildContext context) {
const cellSize = 30.0;
return Watch((context, _) {
return Watch((context) {
final selected = selectedCells();
return Scaffold(
appBar: AppBar(
Expand Down
4 changes: 2 additions & 2 deletions examples/eval_calculator/lib/screens/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _TextTableState extends State<TextTable> {

Widget valueToWidget(ValueRow valueRow, BuildContext context) {
final valueDisplay = Watch(
(context, _) => Text(valueRow.signalObject.value.toString(), style: _style),
(context) => Text(valueRow.signalObject.value.toString(), style: _style),
);

if (valueRow.type == ValueType.number) {
Expand Down Expand Up @@ -89,7 +89,7 @@ class _TextTableState extends State<TextTable> {

@override
Widget build(BuildContext context) {
return Watch((context, _) {
return Watch((context) {
return Padding(
padding: const EdgeInsets.all(20),
child: ListView(
Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_async/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class _ExampleState extends State<Example> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Watch((_, __) {
Watch((_) {
return SwitchListTile(
title: const Text('Throw Error'),
value: throwError.value,
onChanged: (value) => throwError.value = value,
);
}),
Watch((context, _) {
Watch((context) {
return ListTile(
title: const Text('Result (map)'),
subtitle: _futureSignal.value.map(
Expand Down Expand Up @@ -103,7 +103,7 @@ class _ExampleState extends State<Example> {
),
);
}),
Watch((context, _) {
Watch((context) {
return ListTile(
title: const Text('Result (switch)'),
subtitle: switch (_futureSignal.value) {
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_colorband/lib/color_scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ColorScale extends StatelessWidget {

@override
build(context) {
return Watch((context, _) {
return Watch((context) {
final conf = signals.confSignal.value;

final configValueStyle = TextStyle(
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_colorband/lib/color_scale_band.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ColorBandDisplay extends StatelessWidget {

@override
build(context) {
return Watch((builder, _) {
return Watch((builder) {
final conf = signals.confSignal.value;
final band = signals.bandSignal.value;

Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_colorband/lib/color_scale_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ColorName extends StatelessWidget {

@override
build(context) {
return Watch((context, _) {
return Watch((context) {
final color = signals.colorNameSignal.value;
final conf = signals.confSignal.value;

Expand Down Expand Up @@ -49,7 +49,7 @@ class ColorNameStream extends StatelessWidget {

@override
build(context) => Watch(
(context, _) {
(context) {
return signals.colorNameSignalStream.value.map(
data: (name) => Semantics(
label: 'Current color',
Expand Down Expand Up @@ -79,7 +79,7 @@ class ColorSelector extends StatelessWidget {
{super.key, required this.conf, required this.valueStyle});

@override
build(context) => Watch((context, _) {
build(context) => Watch((context) {
final band = signals.bandSignal.value;

return SizedBox.expand(
Expand Down
6 changes: 3 additions & 3 deletions examples/get_it_signals/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class DarkModeToggle extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Watch((_, __) {
return Watch((_) {
final isDark = brightness() == Brightness.dark;
return IconButton(
onPressed: () {
Expand Down Expand Up @@ -192,7 +192,7 @@ class _HomeScreenState extends State<HomeScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Count value:'),
Watch((context, _) {
Watch((context) {
return Text(
'$counter',
style: Theme.of(context).textTheme.headlineMedium,
Expand Down Expand Up @@ -303,7 +303,7 @@ class ProfileScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Profile'),
Watch((context, _) {
Watch((context) {
return Text(
getIt.get<Auth>().currentUserName(),
style: Theme.of(context).textTheme.headlineMedium,
Expand Down
2 changes: 1 addition & 1 deletion examples/infinite_scroll/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class InfiniteScroll extends StatelessWidget {
title: const Text('Infinite Scroll'),
),
body: Watch.builder(
builder: (context, _) {
builder: (context) {
final items = source.value.value ?? [];
final more = source.hasMore();
if (items.isEmpty) {
Expand Down
8 changes: 4 additions & 4 deletions examples/node_based_editor/lib/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ class _EditorState extends State<Editor> {
..scale(0.9, 0.9)
..translate(-(size.width / 2), -(size.height / 2))),
),
Watch((context, _) {
Watch((context) {
return IconButton(
onPressed: () => toolbox.set(!toolbox()),
icon: Icon(toolbox() ? Icons.visibility_off : Icons.visibility),
tooltip: toolbox() ? 'Hide Toolbox' : 'Show Toolbox',
);
}),
Watch((context, _) {
Watch((context) {
if (selection.isEmpty) return const SizedBox.shrink();
return IconButton(
onPressed: () => selection.clear(),
icon: const Icon(Icons.clear),
tooltip: 'Clear selection',
);
}),
Watch((context, _) {
Watch((context) {
if (nodes.isEmpty) return const SizedBox.shrink();
return IconButton(
onPressed: () {
Expand All @@ -95,7 +95,7 @@ class _EditorState extends State<Editor> {
],
),
body: Watch.builder(
builder: (context, _) => Stack(
builder: (context) => Stack(
children: [
Positioned.fill(
child: CodeView(
Expand Down
2 changes: 1 addition & 1 deletion examples/node_based_editor/lib/nodes/datetime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DateTimeNode extends ValueNode<DateTime> {
@override
Widget build() {
if (output is Signal<DateTime>) {
return Watch.builder(builder: (context, _) {
return Watch.builder(builder: (context) {
return InkWell(
onTap: () {
final now = DateTime.now();
Expand Down
Loading

0 comments on commit 2d23c8c

Please sign in to comment.