-
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 example code of lifecycle to show as tabs
- Loading branch information
1 parent
2955abe
commit c8e7820
Showing
18 changed files
with
543 additions
and
160 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
41 changes: 41 additions & 0 deletions
41
website/src/examples/lifecycle_event_handler/lib/counter.dart
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'; | ||
|
||
import 'counter_controller.dart'; | ||
|
||
class Counter extends StatelessWidget { | ||
const Counter({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// Provides the `CounterController` dependency to the widget tree | ||
return ReactterProvider<CounterController>( | ||
() => CounterController(), | ||
builder: (context, counterController, child) { | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
ElevatedButton( | ||
onPressed: counterController.decrement, | ||
child: const Icon(Icons.remove), | ||
), | ||
const SizedBox(width: 8), | ||
// Observes the `count` property of the `counterController` | ||
// and rebuilds the widget tree when the `count` value changes | ||
ReactterConsumer<CounterController>( | ||
listenStates: (counterController) => [counterController.count], | ||
builder: (context, counterController, child) { | ||
return Text("${counterController.count}"); | ||
}, | ||
), | ||
const SizedBox(width: 8), | ||
ElevatedButton( | ||
onPressed: counterController.increment, | ||
child: const Icon(Icons.add), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
website/src/examples/lifecycle_event_handler/lib/counter_controller.dart
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,39 @@ | ||
import 'package:flutter_reactter/flutter_reactter.dart'; | ||
|
||
class CounterController { | ||
final count = Signal(0); | ||
|
||
CounterController() { | ||
Reactter.on(this, Lifecycle.willMount, (_, __) { | ||
print('CounterController will mount'); | ||
}); | ||
|
||
Reactter.on(this, Lifecycle.didMount, (_, __) { | ||
print('CounterController did mount'); | ||
}); | ||
|
||
Reactter.on(this, Lifecycle.willUpdate, (_, state) { | ||
print('CounterController will update by ${state.runtimeType}'); | ||
}); | ||
|
||
Reactter.on(this, Lifecycle.didUpdate, (_, state) { | ||
print('CounterController did updated by ${state.runtimeType}'); | ||
}); | ||
|
||
Reactter.on(this, Lifecycle.willUnmount, (_, __) { | ||
print('CounterController will unmount'); | ||
}); | ||
|
||
Reactter.on(this, Lifecycle.didUnmount, (_, __) { | ||
print('CounterController did unmount'); | ||
}); | ||
} | ||
|
||
void increment() { | ||
count.value++; | ||
} | ||
|
||
void decrement() { | ||
count.value--; | ||
} | ||
} |
Oops, something went wrong.