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

#111 #146

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

#111 #146

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
16 changes: 5 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MyApp extends StatelessWidget {
),
home: MyHomePage(title: 'Flutter EasyLoading'),
builder: EasyLoading.init(),
),
);
}
}
Expand Down Expand Up @@ -157,10 +156,8 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () {
_progress = 0;
_timer?.cancel();
_timer = Timer.periodic(const Duration(milliseconds: 100),
(Timer timer) {
EasyLoading.showProgress(_progress,
status: '${(_progress * 100).toStringAsFixed(0)}%');
_timer = Timer.periodic(const Duration(milliseconds: 100), (Timer timer) {
EasyLoading.showProgress(_progress, status: '${(_progress * 100).toStringAsFixed(0)}%');
_progress += 0.03;

if (_progress >= 1) {
Expand Down Expand Up @@ -245,8 +242,7 @@ class _MyHomePageState extends State<MyHomePage> {
Text('Toast Positon'),
Padding(
padding: EdgeInsets.only(top: 10.0),
child:
CupertinoSegmentedControl<EasyLoadingToastPosition>(
child: CupertinoSegmentedControl<EasyLoadingToastPosition>(
selectedColor: Colors.blue,
children: {
EasyLoadingToastPosition.top: Padding(
Expand Down Expand Up @@ -277,8 +273,7 @@ class _MyHomePageState extends State<MyHomePage> {
Text('Animation Style'),
Padding(
padding: EdgeInsets.only(top: 10.0),
child:
CupertinoSegmentedControl<EasyLoadingAnimationStyle>(
child: CupertinoSegmentedControl<EasyLoadingAnimationStyle>(
selectedColor: Colors.blue,
children: {
EasyLoadingAnimationStyle.opacity: Padding(
Expand Down Expand Up @@ -316,8 +311,7 @@ class _MyHomePageState extends State<MyHomePage> {
Text('IndicatorType(total: 23)'),
Padding(
padding: EdgeInsets.only(top: 10.0),
child:
CupertinoSegmentedControl<EasyLoadingIndicatorType>(
child: CupertinoSegmentedControl<EasyLoadingIndicatorType>(
selectedColor: Colors.blue,
children: {
EasyLoadingIndicatorType.circle: Padding(
Expand Down
46 changes: 23 additions & 23 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flutter:
Expand All @@ -66,16 +66,16 @@ packages:
dependency: "direct main"
description:
name: flutter_easyloading
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
version: "3.0.3"
flutter_spinkit:
dependency: transitive
description:
name: flutter_spinkit
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
version: "5.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -85,21 +85,21 @@ packages:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
sky_engine:
Expand All @@ -111,56 +111,56 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
sdks:
Expand Down
2 changes: 2 additions & 0 deletions lib/src/easy_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ enum EasyLoadingAnimationStyle {
/// [none] default mask type, allow user interactions while loading is displayed
/// [clear] don't allow user interactions while loading is displayed
/// [black] don't allow user interactions while loading is displayed
/// [blur] don't allow user interactions while loading is displayed
/// [custom] while mask type is custom, maskColor should not be null
enum EasyLoadingMaskType {
none,
clear,
black,
blur,
custom,
}

Expand Down
62 changes: 32 additions & 30 deletions lib/src/widgets/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// IN THE SOFTWARE.

import 'dart:async';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
Expand Down Expand Up @@ -52,17 +53,15 @@ class EasyLoadingContainer extends StatefulWidget {
EasyLoadingContainerState createState() => EasyLoadingContainerState();
}

class EasyLoadingContainerState extends State<EasyLoadingContainer>
with SingleTickerProviderStateMixin {
class EasyLoadingContainerState extends State<EasyLoadingContainer> with SingleTickerProviderStateMixin {
String? _status;
Color? _maskColor;
late EasyLoadingMaskType? _maskType;
late AnimationController _animationController;
late AlignmentGeometry _alignment;
late bool _dismissOnTap, _ignoring;

bool get isPersistentCallbacks =>
SchedulerBinding.instance?.schedulerPhase ==
SchedulerPhase.persistentCallbacks;
bool get isPersistentCallbacks => SchedulerBinding.instance?.schedulerPhase == SchedulerPhase.persistentCallbacks;

@override
void initState() {
Expand All @@ -72,11 +71,10 @@ class EasyLoadingContainerState extends State<EasyLoadingContainer>
_alignment = (widget.indicator == null && widget.status?.isNotEmpty == true)
? EasyLoadingTheme.alignment(widget.toastPosition)
: AlignmentDirectional.center;
_dismissOnTap =
widget.dismissOnTap ?? (EasyLoadingTheme.dismissOnTap ?? false);
_ignoring =
_dismissOnTap ? false : EasyLoadingTheme.ignoring(widget.maskType);
_dismissOnTap = widget.dismissOnTap ?? (EasyLoadingTheme.dismissOnTap ?? false);
_ignoring = _dismissOnTap ? false : EasyLoadingTheme.ignoring(widget.maskType);
_maskColor = EasyLoadingTheme.maskColor(widget.maskType);
_maskType = widget.maskType;
_animationController = AnimationController(
vsync: this,
duration: EasyLoadingTheme.animationDuration,
Expand All @@ -98,8 +96,8 @@ class EasyLoadingContainerState extends State<EasyLoadingContainer>
Future<void> show(bool animation) {
if (isPersistentCallbacks) {
Completer<void> completer = Completer<void>();
SchedulerBinding.instance?.addPostFrameCallback((_) => completer
.complete(_animationController.forward(from: animation ? 0 : 1)));
SchedulerBinding.instance
?.addPostFrameCallback((_) => completer.complete(_animationController.forward(from: animation ? 0 : 1)));
return completer.future;
} else {
return _animationController.forward(from: animation ? 0 : 1);
Expand All @@ -109,8 +107,8 @@ class EasyLoadingContainerState extends State<EasyLoadingContainer>
Future<void> dismiss(bool animation) {
if (isPersistentCallbacks) {
Completer<void> completer = Completer<void>();
SchedulerBinding.instance?.addPostFrameCallback((_) => completer
.complete(_animationController.reverse(from: animation ? 1 : 0)));
SchedulerBinding.instance
?.addPostFrameCallback((_) => completer.complete(_animationController.reverse(from: animation ? 1 : 0)));
return completer.future;
} else {
return _animationController.reverse(from: animation ? 1 : 0);
Expand Down Expand Up @@ -141,20 +139,8 @@ class EasyLoadingContainerState extends State<EasyLoadingContainer>
child: IgnorePointer(
ignoring: _ignoring,
child: _dismissOnTap
? GestureDetector(
onTap: _onTap,
behavior: HitTestBehavior.translucent,
child: Container(
width: double.infinity,
height: double.infinity,
color: _maskColor,
),
)
: Container(
width: double.infinity,
height: double.infinity,
color: _maskColor,
),
? GestureDetector(onTap: _onTap, behavior: HitTestBehavior.translucent, child: _buildMaskContainer())
: _buildMaskContainerByMaskType(),
),
);
},
Expand All @@ -175,6 +161,24 @@ class EasyLoadingContainerState extends State<EasyLoadingContainer>
],
);
}

Widget _buildMaskContainerByMaskType() {
if (_maskType == EasyLoadingMaskType.blur)
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: _buildMaskContainer(),
);

return _buildMaskContainer();
}

Container _buildMaskContainer() {
return Container(
width: double.infinity,
height: double.infinity,
color: _maskColor,
);
}
}

class _Indicator extends StatelessWidget {
Expand Down Expand Up @@ -205,9 +209,7 @@ class _Indicator extends StatelessWidget {
children: <Widget>[
if (indicator != null)
Container(
margin: status?.isNotEmpty == true
? EasyLoadingTheme.textPadding
: EdgeInsets.zero,
margin: status?.isNotEmpty == true ? EasyLoadingTheme.textPadding : EdgeInsets.zero,
child: indicator,
),
if (status != null)
Expand Down
Loading