-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Update
RtWatcher
widget documentation and examples.
- Loading branch information
1 parent
a14cbf1
commit 0684b62
Showing
5 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_reactter/flutter_reactter.dart'; | ||
|
||
class Counter extends StatelessWidget { | ||
const Counter({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final count = UseState(0); | ||
|
||
return RtWatcher.builder( | ||
// This widget remains static and does not rebuild when `count` changes. | ||
// It is passed as a `child` to the `builder` function. | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
ElevatedButton( | ||
child: const Icon(Icons.remove), | ||
onPressed: () => count.value--, | ||
), | ||
SizedBox(width: 8), | ||
ElevatedButton( | ||
child: const Icon(Icons.add), | ||
onPressed: () => count.value++, | ||
), | ||
], | ||
), | ||
// Rebuid the widget when `count` changes | ||
builder: (context, watch, child) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Text("Count: ${watch(count).value}"), | ||
SizedBox(height: 8), | ||
child!, | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'counter.dart'; | ||
|
||
class CounterView extends StatelessWidget { | ||
const CounterView({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text("Counter"), | ||
), | ||
body: const Center( | ||
child: Counter(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'counter_view.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: CounterView(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: RtWatcher | ||
description: RtWatcher example | ||
version: 0.1.0 | ||
|
||
environment: | ||
sdk: ">=2.19.0 <4.0.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter_reactter: ^7.3.1 | ||
|
||
flutter: | ||
uses-material-design: true |