Skip to content

Commit

Permalink
🚑 Fix not pop after post published.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Feb 20, 2020
1 parent 0b3baca commit a7dab2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/pages/post/publish_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class PublishPostPageState extends State<PublishPostPage> {
'动态发布成功',
duration: 3.seconds,
customPop: () {
navigatorState.popUntil((_) => _.isFirst);
navigatorState.popUntil((Route<dynamic> route) => route.isFirst);
},
);
} else {
Expand Down
51 changes: 25 additions & 26 deletions lib/widgets/dialogs/loading_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class LoadingDialog extends StatefulWidget {
}

class LoadingDialogState extends State<LoadingDialog> {
Duration duration = 1500.milliseconds;
String type, text;
VoidCallback customPop;
Widget icon = const SpinKitWidget();
Duration _duration = 1500.milliseconds;
String _type, _text;
VoidCallback _customPop;
Widget _icon = const SpinKitWidget();

@override
void initState() {
super.initState();
widget.controller?.dialogState = this;
text = widget.text;
_text = widget.text;
if (mounted) {
setState(() {});
}
Expand All @@ -69,31 +69,31 @@ class LoadingDialogState extends State<LoadingDialog> {
Widget icon,
String text,
Duration duration,
Function customPop,
VoidCallback customPop,
}) {
this.type = type;
this.icon = icon;
this.text = text;
_type = type;
_icon = icon;
_text = text;
if (duration != null) {
duration = duration;
_duration = duration;
}
if (customPop != null) {
customPop = customPop;
_customPop = customPop;
}
if (mounted) {
setState(() {});
}
}

void updateIcon(Widget icon) {
this.icon = icon;
_icon = icon;
if (mounted) {
setState(() {});
}
}

void updateText(String text) {
this.text = text;
_text = text;
if (mounted) {
setState(() {});
}
Expand All @@ -102,22 +102,22 @@ class LoadingDialogState extends State<LoadingDialog> {
@override
Widget build(BuildContext context) {
if (!(widget.isGlobal ?? false)) {
if (type != null && type != 'loading') {
Future<void>.delayed(duration, () {
if (_type != null && _type != 'loading') {
Future<void>.delayed(_duration, () {
try {
if (customPop != null) {
customPop();
if (_customPop != null) {
_customPop();
} else {
Navigator.pop(context);
}
} catch (e) {
debugPrint('Error when running pop in loading dialog: $e');
}
});
} else if (type == 'dismiss') {
} else if (_type == 'dismiss') {
try {
if (customPop != null) {
customPop();
if (_customPop != null) {
_customPop();
} else {
Navigator.pop(context);
}
Expand All @@ -127,9 +127,8 @@ class LoadingDialogState extends State<LoadingDialog> {
}
}
Widget child = Center(
child: SizedBox(
width: suSetWidth(180.0),
height: suSetWidth(180.0),
child: SizedBox.fromSize(
size: Size.square(suSetWidth(180.0)),
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
Expand All @@ -141,12 +140,12 @@ class LoadingDialogState extends State<LoadingDialog> {
children: <Widget>[
SizedBox.fromSize(
size: Size.square(suSetWidth(50.0)),
child: Center(child: icon),
child: Center(child: _icon),
),
Container(
margin: EdgeInsets.only(top: suSetHeight(40.0)),
child: Text(
text,
_text,
style: TextStyle(fontSize: suSetSp(16.0)),
),
),
Expand Down Expand Up @@ -186,7 +185,7 @@ class LoadingDialogController {
String type,
String text, {
Duration duration,
Function customPop,
VoidCallback customPop,
}) {
switch (type) {
case 'success':
Expand Down

0 comments on commit a7dab2b

Please sign in to comment.