Skip to content

Commit 394ee5b

Browse files
Fix: broken pop dialog (#293)
* fix: broken pop dialog In `feedback-widget`, replaced the wrap around the `theme` with an Overlay widget instead of the `navigation`. The Navigation widget intercept the back action in general app navigation and prevent dialogs from popping * fix: feedback-builder request a navigator ancestor Wrap the feedback-builder with a Navigation ancestor to avoid error * example: add buttons to open dialog in example Add two buttons to open a test alert-dialog. - The first one in the base screen to handle the `normal` flow of navigation and test the open/close option with back action - The second one in the custom-feedback to test the behavior of open a dialog with a custom navigator
1 parent f159819 commit 394ee5b

File tree

4 files changed

+208
-166
lines changed

4 files changed

+208
-166
lines changed

feedback/example/lib/custom_feedback.dart

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,41 @@ class _CustomFeedbackFormState extends State<CustomFeedbackForm> {
9090
child: Text('*'),
9191
),
9292
Flexible(
93-
child: DropdownButton<FeedbackType>(
94-
value: _customFeedback.feedbackType,
95-
items: FeedbackType.values
96-
.map(
97-
(type) => DropdownMenuItem<FeedbackType>(
98-
value: type,
99-
child: Text(type
100-
.toString()
101-
.split('.')
102-
.last
103-
.replaceAll('_', ' ')),
104-
),
105-
)
106-
.toList(),
107-
onChanged: (feedbackType) => setState(() =>
108-
_customFeedback.feedbackType = feedbackType),
93+
child: Row(
94+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
95+
children: [
96+
DropdownButton<FeedbackType>(
97+
value: _customFeedback.feedbackType,
98+
items: FeedbackType.values
99+
.map(
100+
(type) => DropdownMenuItem<FeedbackType>(
101+
value: type,
102+
child: Text(type
103+
.toString()
104+
.split('.')
105+
.last
106+
.replaceAll('_', ' ')),
107+
),
108+
)
109+
.toList(),
110+
onChanged: (feedbackType) => setState(() =>
111+
_customFeedback.feedbackType = feedbackType),
112+
),
113+
ElevatedButton(
114+
child: const Text('Open Dialog #2'),
115+
onPressed: () {
116+
showDialog<dynamic>(
117+
context: context,
118+
builder: (_) {
119+
return AlertDialog(
120+
title: const Text("Dialog #2"),
121+
content: Container(),
122+
);
123+
},
124+
);
125+
},
126+
),
127+
],
109128
),
110129
),
111130
],

feedback/example/lib/main.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ class MyHomePage extends StatelessWidget {
9292
child: Container(color: Colors.blue),
9393
),
9494
body: Padding(
95-
padding: const EdgeInsets.all(24),
95+
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
9696
child: SingleChildScrollView(
9797
child: Column(
9898
children: <Widget>[
99-
const SizedBox(height: 10),
10099
const MarkdownBody(
101100
data: '# How does it work?\n'
102101
'1. Just press the `Provide feedback` button.\n'
@@ -189,6 +188,21 @@ class MyHomePage extends StatelessWidget {
189188
launchUrl(Uri.parse('https://pub.dev/packages/feedback'));
190189
},
191190
),
191+
const SizedBox(height: 10),
192+
ElevatedButton(
193+
child: const Text('Open Dialog #1'),
194+
onPressed: () {
195+
showDialog<dynamic>(
196+
context: context,
197+
builder: (_) {
198+
return AlertDialog(
199+
title: const Text("Dialog #1"),
200+
content: Container(),
201+
);
202+
},
203+
);
204+
},
205+
),
192206
],
193207
),
194208
),

feedback/lib/src/feedback_bottom_sheet.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import 'package:feedback/src/better_feedback.dart';
44
import 'package:feedback/src/theme/feedback_theme.dart';
55
import 'package:feedback/src/utilities/back_button_interceptor.dart';
6-
76
import 'package:flutter/material.dart';
87

98
/// Shows the text input in which the user can describe his feedback.
@@ -39,7 +38,17 @@ class FeedbackBottomSheet extends StatelessWidget {
3938
color: FeedbackTheme.of(context).feedbackSheetColor,
4039
// Pass a null scroll controller because the sheet is not drag
4140
// enabled.
42-
child: feedbackBuilder(context, onSubmit, null),
41+
child: Navigator(
42+
onGenerateRoute: (_) {
43+
return MaterialPageRoute<void>(
44+
builder: (_) => feedbackBuilder(
45+
context,
46+
onSubmit,
47+
null,
48+
),
49+
);
50+
},
51+
),
4352
),
4453
),
4554
);
@@ -122,10 +131,16 @@ class _DraggableFeedbackSheetState extends State<_DraggableFeedbackSheet> {
122131
color: FeedbackTheme.of(context).feedbackSheetColor,
123132
// A `ListView` makes the content here disappear.
124133
child: DefaultTextEditingShortcuts(
125-
child: widget.feedbackBuilder(
126-
context,
127-
widget.onSubmit,
128-
scrollController,
134+
child: Navigator(
135+
onGenerateRoute: (_) {
136+
return MaterialPageRoute<void>(
137+
builder: (_) => widget.feedbackBuilder(
138+
context,
139+
widget.onSubmit,
140+
scrollController,
141+
),
142+
);
143+
},
129144
),
130145
),
131146
),

0 commit comments

Comments
 (0)