-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Tencent/feature/td_loading_dismiss
add: 加载添加显示与隐藏的方法
- Loading branch information
Showing
3 changed files
with
118 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tdesign-component/lib/src/components/loading/td_loading_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'td_loading.dart'; | ||
|
||
class TDLoadingController { | ||
static BuildContext? _context; | ||
static OverlayEntry? _overlayEntry; | ||
|
||
static bool _isShowing = false; | ||
|
||
// 展示 | ||
static void show(BuildContext context, | ||
{Widget? child, | ||
TDLoadingSize size = TDLoadingSize.medium, | ||
TDLoadingIcon? icon = TDLoadingIcon.circle, | ||
Color? iconColor, | ||
String text = '加载中', | ||
Widget? refreshWidget, | ||
Color textColor = Colors.black, | ||
Axis axis = Axis.vertical, | ||
Widget? customIcon, | ||
int duration = 2000}) { | ||
|
||
if (_isShowing) { | ||
print('warn: TDLoading is showing!'); | ||
return; | ||
} | ||
|
||
_overlayEntry = OverlayEntry(builder: (context) { | ||
return Center( | ||
child: child ?? | ||
TDLoading( | ||
size: size, | ||
icon: icon, | ||
customIcon: customIcon, | ||
text: text, | ||
textColor: textColor, | ||
refreshWidget: refreshWidget, | ||
duration: duration, | ||
iconColor: iconColor, | ||
axis: axis, | ||
), | ||
); | ||
}); | ||
|
||
_context = context; | ||
if (_context == null || _overlayEntry == null) { | ||
print('error: TDLoading is not init!:${_context} ${_overlayEntry}'); | ||
return; | ||
} | ||
_isShowing = true; | ||
Overlay.of(_context!).insert(_overlayEntry!); | ||
} | ||
|
||
// 消失 | ||
static void dismiss() { | ||
if (_isShowing) { | ||
if (_overlayEntry != null && _overlayEntry!.mounted) { | ||
_overlayEntry?.remove(); | ||
_overlayEntry = null; | ||
} | ||
_isShowing = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters