Skip to content

Commit

Permalink
process #200
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Jun 29, 2024
1 parent 476aeef commit 9868590
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Reconstruct the implementation of initialization
* Show Debug Paint: fix [#109](https://github.com/fluttercandies/flutter_smart_dialog/issues/109), [#115](https://github.com/fluttercandies/flutter_smart_dialog/issues/115)
* fix [#183](https://github.com/fluttercandies/flutter_smart_dialog/issues/183)
* 4.9.7 bugfix: [#188](https://github.com/fluttercandies/flutter_smart_dialog/issues/188), [#189](https://github.com/fluttercandies/flutter_smart_dialog/issues/189), [#190](https://github.com/fluttercandies/flutter_smart_dialog/issues/190), [#191](https://github.com/fluttercandies/flutter_smart_dialog/issues/191), [#192](https://github.com/fluttercandies/flutter_smart_dialog/issues/192)
* 4.9.7 bugfix: [#188](https://github.com/fluttercandies/flutter_smart_dialog/issues/188), [#189](https://github.com/fluttercandies/flutter_smart_dialog/issues/189), [#190](https://github.com/fluttercandies/flutter_smart_dialog/issues/190), [#191](https://github.com/fluttercandies/flutter_smart_dialog/issues/191), [#192](https://github.com/fluttercandies/flutter_smart_dialog/issues/192), [#200](https://github.com/fluttercandies/flutter_smart_dialog/issues/200)

# [4.9.x]
* fix [#132](https://github.com/fluttercandies/flutter_smart_dialog/issues/132)
Expand Down
231 changes: 231 additions & 0 deletions example/lib/demo/issue200_toast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
home: const DemoPage(),
navigatorObservers: [FlutterSmartDialog.observer],
builder: FlutterSmartDialog.init(),
);
}
}


/// @Describe: 测试
///
/// @Author: LiWeNHuI
/// @Date: 2024/6/28
class DemoPage extends StatefulWidget {
const DemoPage({super.key});

/// 构造
static Widget structure(BuildContext context) {
return const DemoPage();
}

@override
State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(onPressed: _show, child: const Text('Test')),
TextButton(onPressed: _showToast, child: const Text('ShowToast')),
TextButton(onPressed: _showLoading, child: const Text('ShowLoading')),
],
),
);
}

Future<void> _showToast() async {
await SmartDialog.showToast(
'message',
alignment: Alignment.center,
debounce: true,
displayType: SmartToastType.last,
);
}

Future<void> _showLoading() async {
await SmartDialog.showLoading<void>(
maskColor: Colors.transparent,
clickMaskDismiss: false,
displayTime: const Duration(milliseconds: 1500),
backDismiss: false,
);
}

Future<void> _show() async {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext ctx) {
return Dialog(
insetPadding:
const EdgeInsets.symmetric(vertical: 24, horizontal: 32),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
child: PopScope(
canPop: false,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 24, horizontal: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: TextButton(
onPressed: () {
Navigator.pop(ctx);

SmartDialog.dismiss<void>(status: SmartStatus.toast);
SmartDialog.dismiss<void>(status: SmartStatus.loading);

SmartDialog.show<void>(
builder: (_) => Container(
alignment: Alignment.bottomCenter,
width: 200,
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 24,
),
decoration: BoxDecoration(
color: const Color(0xA6000000),
borderRadius: BorderRadius.circular(4),
),
constraints: const BoxConstraints(maxWidth: 420),
margin: const EdgeInsets.fromLTRB(30, 140, 30, 140),
child: const Text('Demo'),
),
),
clickMaskDismiss: false,
animationBuilder: (_, Widget child, ___) =>
TestAnimation(animationParam: ___, child: child),
displayTime: const Duration(milliseconds: 2300),
backDismiss: false,
keepSingle: true,
);
},
child: const Text('Show'),
),
),
),
),
);
},
);
}
}

class TestAnimation extends StatefulWidget {
const TestAnimation({
super.key,
required this.child,
required this.animationParam,
});

/// 子布局
final Widget child;

/// 动画参数
final AnimationParam animationParam;

@override
State<TestAnimation> createState() => _TestAnimationState();
}

class _TestAnimationState extends State<TestAnimation>
with TickerProviderStateMixin {
/// 缩放+显隐动画控制器
late AnimationController controller;

/// 缩放动画
late Animation<double> _scaleAnimation;

/// 旋转动画控制器
late AnimationController bodyController;

/// 旋转动画是否开始
bool isStart = false;

@override
void initState() {
controller = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
)..addListener(() {
if (controller.value > .3 && !isStart) {
isStart = true;

bodyController.forward();
}
});

bodyController = AnimationController(
duration: const Duration(milliseconds: 8000),
vsync: this,
);

_scaleAnimation = Tween<double>(begin: .5, end: 1).animate(controller);

animationParam
..onForward = () {
controller.forward();
}
..onDismiss = () {
controller.reverse();
};

super.initState();
}

@override
void dispose() {
controller.dispose();
bodyController.dispose();

super.dispose();
}

@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: <Widget>[
FadeTransition(
opacity: CurvedAnimation(parent: controller, curve: Curves.linear),
child: ScaleTransition(scale: _scaleAnimation, child: _buildBody),
),
widget.child,
],
);
}

Widget get _buildBody {
final Stack child = Stack(
alignment: Alignment.center,
clipBehavior: Clip.antiAliasWithSaveLayer,
children: <Widget>[
RotationTransition(
turns: CurvedAnimation(parent: bodyController, curve: Curves.linear),
child: const FlutterLogo(size: 120),
),
],
);

return Container(constraints: const BoxConstraints.expand(), child: child);
}

AnimationParam get animationParam => widget.animationParam;
}
1 change: 1 addition & 0 deletions lib/src/custom/custom_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class CustomLoading extends BaseDialog {
}
_canDismissCallback = () => _realDismiss(closeType: closeType);
if (_canDismiss) {
_canDismiss = false;
SmartDialog.config.loading.isExist = false;
await _canDismissCallback?.call();
}
Expand Down
59 changes: 31 additions & 28 deletions lib/src/widget/helper/smart_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SmartOverlay extends StatefulWidget {
class _SmartOverlayState extends State<SmartOverlay> {
bool isDebugModel = /*false*/ kDebugMode;
bool visible = true;
Completer? showCompleter;

@override
void initState() {
Expand All @@ -42,6 +43,8 @@ class _SmartOverlayState extends State<SmartOverlay> {
if (visible) {
return;
}
if (showCompleter?.isCompleted == false) showCompleter?.complete();
showCompleter = Completer();

var completer = Completer();
ViewUtils.addSafeUse(() {
Expand All @@ -50,18 +53,19 @@ class _SmartOverlayState extends State<SmartOverlay> {
});
await completer.future;

completer = Completer();
// await show isExist
widgetsBinding.addPostFrameCallback((timeStamp) {
completer.complete();
if (showCompleter?.isCompleted == false) showCompleter?.complete();
});
await completer.future;
await showCompleter?.future;
}

Future<void> onDismiss() async {
if (!visible) {
return;
}

await showCompleter?.future;
var dialogExist = SmartDialog.config.checkExist(dialogTypes: {
SmartAllDialogType.custom,
SmartAllDialogType.attach,
Expand Down Expand Up @@ -89,34 +93,33 @@ class _SmartOverlayState extends State<SmartOverlay> {
}

return Overlay(initialEntries: [
if (visible)
SmartOverlayEntry(
builder: (BuildContext context) {
if (widget.initType.contains(SmartInitType.custom)) {
DialogProxy.contextCustom = context;
}

if (widget.initType.contains(SmartInitType.attach)) {
DialogProxy.contextAttach = context;
}

if (widget.initType.contains(SmartInitType.notify)) {
DialogProxy.contextNotify = context;
}

if (widget.initType.contains(SmartInitType.toast)) {
DialogProxy.contextToast = context;
}

return const SizedBox.shrink();
},
),

if (visible && widget.initType.contains(SmartInitType.notify))
SmartOverlayEntry(
builder: (BuildContext context) {
if (widget.initType.contains(SmartInitType.custom)) {
DialogProxy.contextCustom = context;
}

if (widget.initType.contains(SmartInitType.attach)) {
DialogProxy.contextAttach = context;
}

if (widget.initType.contains(SmartInitType.notify)) {
DialogProxy.contextNotify = context;
}

if (widget.initType.contains(SmartInitType.toast)) {
DialogProxy.contextToast = context;
}

return const SizedBox.shrink();
},
),

if (widget.initType.contains(SmartInitType.notify))
DialogProxy.instance.entryNotify,

// loading
if (visible && widget.initType.contains(SmartInitType.loading))
if (widget.initType.contains(SmartInitType.loading))
DialogProxy.instance.entryLoading,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description:
An elegant Flutter Dialog solution,
Easily implement Toast, Loading and custom Dialog,
Make the use of the dialog easier!
version: 4.9.7+7
version: 4.9.7+8
homepage: https://github.com/fluttercandies/flutter_smart_dialog
# flutter pub publish --server=https://pub.dartlang.org
# flutter build web --release --base-href="/flutter_smart_dialog/web/"
Expand Down

0 comments on commit 9868590

Please sign in to comment.