-
Notifications
You must be signed in to change notification settings - Fork 1
/
quiz_page_actions_nested.dart
63 lines (58 loc) · 2.13 KB
/
quiz_page_actions_nested.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';
import '../demo_page.dart';
class QuizActionsNestedPage extends StatelessWidget {
const QuizActionsNestedPage({
super.key,
});
static const String route = 'quiz-actions-nested';
static const String title = 'Actions - Nested';
static const String subtitle = 'Two nested Actions widgets that both map the same Intent.';
@override
Widget build(BuildContext context) {
return DemoPage(
title: 'Quiz - Actions Nested',
codeUri: Uri.parse('https://github.com/justinmc/flutter_shortcut_intent_action_talk/blob/main/lib/quiz_page/quiz_page_actions_nested.dart'),
child: Center(
child: Actions(
actions: <Type, Action<Intent>>{
MyIntent: CallbackAction<MyIntent>(onInvoke: (MyIntent intent) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Invoked Actions higher in the tree.', style: TextStyle(fontSize: 32.0)),
));
return;
}),
},
child: Actions(
actions: <Type, Action<Intent>>{
MyIntent: CallbackAction<MyIntent>(onInvoke: (MyIntent intent) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Invoked Actions lower in the tree.', style: TextStyle(fontSize: 32.0)),
));
return;
}),
},
child: Builder(
builder: (BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Will the Actions higher or lower in the tree be invoked, or both?'),
TextButton(
onPressed: () {
Actions.invoke<MyIntent>(context, const MyIntent());
},
child: const Text('Tap me'),
),
],
);
},
),
),
),
),
);
}
}
class MyIntent extends Intent {
const MyIntent();
}