From 54ceda944c70bbc1e640e0cabb9a82f1e592e1dc Mon Sep 17 00:00:00 2001 From: Berkan Aslan Date: Mon, 20 Dec 2021 13:13:21 +0300 Subject: [PATCH] #111 Blurred mask added. Example brackets issue fixed. --- example/lib/main.dart | 16 +++------ example/pubspec.lock | 46 ++++++++++++------------- lib/src/easy_loading.dart | 2 ++ lib/src/widgets/container.dart | 62 ++++++++++++++++++---------------- pubspec.lock | 40 +++++++++++----------- pubspec.yaml | 2 +- 6 files changed, 83 insertions(+), 85 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 8eb8727..2018982 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -41,7 +41,6 @@ class MyApp extends StatelessWidget { ), home: MyHomePage(title: 'Flutter EasyLoading'), builder: EasyLoading.init(), - ), ); } } @@ -157,10 +156,8 @@ class _MyHomePageState extends State { 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) { @@ -245,8 +242,7 @@ class _MyHomePageState extends State { Text('Toast Positon'), Padding( padding: EdgeInsets.only(top: 10.0), - child: - CupertinoSegmentedControl( + child: CupertinoSegmentedControl( selectedColor: Colors.blue, children: { EasyLoadingToastPosition.top: Padding( @@ -277,8 +273,7 @@ class _MyHomePageState extends State { Text('Animation Style'), Padding( padding: EdgeInsets.only(top: 10.0), - child: - CupertinoSegmentedControl( + child: CupertinoSegmentedControl( selectedColor: Colors.blue, children: { EasyLoadingAnimationStyle.opacity: Padding( @@ -316,8 +311,7 @@ class _MyHomePageState extends State { Text('IndicatorType(total: 23)'), Padding( padding: EdgeInsets.only(top: 10.0), - child: - CupertinoSegmentedControl( + child: CupertinoSegmentedControl( selectedColor: Colors.blue, children: { EasyLoadingIndicatorType.circle: Padding( diff --git a/example/pubspec.lock b/example/pubspec.lock index 28c3787..f66286e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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 @@ -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: @@ -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: diff --git a/lib/src/easy_loading.dart b/lib/src/easy_loading.dart index ac70d3d..b3d831d 100644 --- a/lib/src/easy_loading.dart +++ b/lib/src/easy_loading.dart @@ -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, } diff --git a/lib/src/widgets/container.dart b/lib/src/widgets/container.dart index 1b47161..44df9a6 100644 --- a/lib/src/widgets/container.dart +++ b/lib/src/widgets/container.dart @@ -21,6 +21,7 @@ // IN THE SOFTWARE. import 'dart:async'; +import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; @@ -52,17 +53,15 @@ class EasyLoadingContainer extends StatefulWidget { EasyLoadingContainerState createState() => EasyLoadingContainerState(); } -class EasyLoadingContainerState extends State - with SingleTickerProviderStateMixin { +class EasyLoadingContainerState extends State 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() { @@ -72,11 +71,10 @@ class EasyLoadingContainerState extends State _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, @@ -98,8 +96,8 @@ class EasyLoadingContainerState extends State Future show(bool animation) { if (isPersistentCallbacks) { Completer completer = Completer(); - 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); @@ -109,8 +107,8 @@ class EasyLoadingContainerState extends State Future dismiss(bool animation) { if (isPersistentCallbacks) { Completer completer = Completer(); - 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); @@ -141,20 +139,8 @@ class EasyLoadingContainerState extends State 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(), ), ); }, @@ -175,6 +161,24 @@ class EasyLoadingContainerState extends State ], ); } + + 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 { @@ -205,9 +209,7 @@ class _Indicator extends StatelessWidget { children: [ 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) diff --git a/pubspec.lock b/pubspec.lock index 5091533..ad3aef9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,49 +5,49 @@ 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" 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: @@ -59,9 +59,9 @@ packages: dependency: "direct main" 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 @@ -71,21 +71,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: @@ -97,56 +97,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: diff --git a/pubspec.yaml b/pubspec.yaml index 20fd73f..a4501b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_easyloading description: ✨A clean and lightweight loading/toast widget for Flutter, Easy to use without context, Support iOS、Android and Web -version: 3.0.3 +version: 3.0.4 homepage: https://github.com/nslog11/flutter_easyloading environment: