Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
71c6f1b9
Unverified
Commit
71c6f1b9
authored
Jan 07, 2021
by
Oscar Robles
Committed by
GitHub
Jan 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AdoptAWidget - Update ActionListener with an example (#69717)
Adds an example to the docs for ActionListener.
parent
c6aa20d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
actions.dart
packages/flutter/lib/src/widgets/actions.dart
+96
-0
No files found.
packages/flutter/lib/src/widgets/actions.dart
View file @
71c6f1b9
...
...
@@ -241,6 +241,102 @@ abstract class Action<T extends Intent> with Diagnosticable {
/// If you listen to an [Action] widget in a widget hierarchy, you should use
/// this widget. If you are using an [Action] outside of a widget context, then
/// you must call removeListener yourself.
///
/// {@tool dartpad --template=stateful_widget_scaffold_center}
/// This example shows how ActionListener handles adding and removing of
/// the [listener] in the widget lifecycle.
///
/// ```dart preamble
/// class ActionListenerExample extends StatefulWidget {
/// @override
/// _ActionListenerExampleState createState() => _ActionListenerExampleState();
/// }
///
/// class _ActionListenerExampleState extends State<ActionListenerExample> {
/// bool _on = false;
/// late final MyAction _myAction;
///
/// @override
/// void initState() {
/// super.initState();
/// _myAction = MyAction();
/// }
///
/// void _toggleState() {
/// setState(() {
/// _on = !_on;
/// });
/// }
///
/// @override
/// Widget build(BuildContext context) {
/// return Row(
/// crossAxisAlignment: CrossAxisAlignment.center,
/// mainAxisAlignment: MainAxisAlignment.center,
/// children: <Widget>[
/// Padding(
/// padding: const EdgeInsets.all(8.0),
/// child: OutlinedButton(
/// onPressed: _toggleState,
/// child: Text(_on ? 'Disable' : 'Enable'),
/// ),
/// ),
/// _on
/// ? Padding(
/// padding: const EdgeInsets.all(8.0),
/// child: ActionListener(
/// listener: (Action<Intent> action) {
/// if (action.intentType == MyIntent) {
/// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
/// content: const Text('Action Listener Called'),
/// ));
/// }
/// },
/// action: _myAction,
/// child: ElevatedButton(
/// onPressed: () =>
/// ActionDispatcher().invokeAction(_myAction, MyIntent()),
/// child: const Text('Call Action Listener'),
/// ),
/// ),
/// )
/// : Container(),
/// ],
/// );
/// }
/// }
///
/// class MyAction extends Action<MyIntent> {
/// @override
/// void addActionListener(listener) {
/// super.addActionListener(listener);
/// print('Action Listener was added');
/// }
///
/// @override
/// void removeActionListener(listener) {
/// super.removeActionListener(listener);
/// print('Action Listener was removed');
/// }
///
/// @override
/// void invoke(covariant MyIntent intent) {
/// notifyActionListeners();
/// }
/// }
///
/// class MyIntent extends Intent {
/// const MyIntent();
/// }
/// ```
///
/// ```dart
/// Widget build(BuildContext context) {
/// return ActionListenerExample();
/// }
/// ```
/// {@end-tool}
///
@immutable
class
ActionListener
extends
StatefulWidget
{
/// Create a const [ActionListener].
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment