Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate brn_loading to null safety #32

Merged
merged 2 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions lib/src/components/loading/brn_loading.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @dart=2.9

import 'package:bruno/src/constants/brn_strings_constants.dart';
import 'package:flutter/material.dart';

/// 页面或者弹窗中间的圆形加载框,左侧是可定制的加载文案[content],比如:加载中、提交中等等
Expand Down Expand Up @@ -31,7 +30,7 @@ import 'package:flutter/material.dart';
class BrnPageLoading extends StatelessWidget {
final String content;

BrnPageLoading({this.content});
const BrnPageLoading({this.content = BrnStrings.loadingContent});

@override
Widget build(BuildContext context) {
Expand All @@ -40,9 +39,7 @@ class BrnPageLoading extends StatelessWidget {
height: 50,
width: 130,
decoration: BoxDecoration(
color: Color(0xff222222),
border: null,
borderRadius: BorderRadius.circular(5)),
color: Color(0xff222222), borderRadius: BorderRadius.circular(5)),
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -58,7 +55,7 @@ class BrnPageLoading extends StatelessWidget {
Container(
margin: EdgeInsets.only(left: 8),
child: Text(
content ?? "加载中...",
content,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
Expand All @@ -80,7 +77,8 @@ class BrnLoadingDialog extends Dialog {
/// 加载时的提示文案,默认为 `加载中...`
final String content;

BrnLoadingDialog({Key key, this.content = "加载中..."}) : super(key: key);
const BrnLoadingDialog({Key? key, this.content = BrnStrings.loadingContent})
: super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -94,13 +92,13 @@ class BrnLoadingDialog extends Dialog {
/// * [barrierDismissible] 点击蒙层背景是否关闭弹窗,默认为 true,可关闭,详见 [showDialog] 中的 [barrierDismissible]
/// * [useRootNavigator] 把弹窗添加到 [context] 中的 rootNavigator 还是最近的 [Navigator],默认为 true,添加到
/// rootNavigator,详见 [showDialog] 中的 [useRootNavigator]。
static void show(
static Future<T?> show<T>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉 这个地方貌似不太需要一个结果
就是关闭loading嘛

Copy link
Contributor Author

@laiiihz laiiihz Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这样可以区分用户关闭的Loading和加载完成关闭Loading,和下面的dismiss相对应

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得这段代码没问题,面对各种场景,适用性更广,考虑的很全面~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢点评🥳

BuildContext context, {
String content,
String content = BrnStrings.loadingContent,
bool barrierDismissible = true,
bool useRootNavigator = true,
}) {
showDialog(
return showDialog<T>(
context: context,
barrierDismissible: barrierDismissible,
useRootNavigator: useRootNavigator,
Expand All @@ -112,7 +110,7 @@ class BrnLoadingDialog extends Dialog {
/// 关闭弹窗。
///
/// * [context] 上下文。
static void dismiss(BuildContext context) {
Navigator.pop(context);
static void dismiss<T extends Object?>(BuildContext context, [T? result]) {
Navigator.pop(context, result);
}
}
1 change: 1 addition & 0 deletions lib/src/constants/brn_strings_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class BrnStrings {
static const String noData = "暂无数据";
static const String noSearchData = "暂无搜索结果";
static const String clickPageRetry = "请点击页面重试";
static const String loadingContent = '加载中...';
}