From a8ece76392527099adc37562b56dc0e1ee11e31f Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Wed, 5 Apr 2023 19:21:37 +0530 Subject: [PATCH] Added dart support code --- lib/modal_progress_hud_nsn.dart | 19 ++++++++---- ...modal_progress_hud_nsn_method_channel.dart | 17 +++++++++++ ...l_progress_hud_nsn_platform_interface.dart | 29 +++++++++++++++++++ lib/modal_progress_hud_nsn_web.dart | 26 +++++++++++++++++ 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 lib/modal_progress_hud_nsn_method_channel.dart create mode 100644 lib/modal_progress_hud_nsn_platform_interface.dart create mode 100644 lib/modal_progress_hud_nsn_web.dart diff --git a/lib/modal_progress_hud_nsn.dart b/lib/modal_progress_hud_nsn.dart index de20ed3..4a2d95e 100644 --- a/lib/modal_progress_hud_nsn.dart +++ b/lib/modal_progress_hud_nsn.dart @@ -1,7 +1,14 @@ -library modal_progress_hud; +library modal_progress_hud_nsn; -import 'package:flutter/material.dart'; -import 'dart:ui'; +import "modal_progress_hud_nsn_platform_interface.dart"; +import "package:flutter/material.dart"; +import "dart:ui"; + +class ModalProgressHudNsn { + Future getPlatformVersion() { + return ModalProgressHudNsnPlatform.instance.getPlatformVersion(); + } +} /// /// Wrap around any widget that makes an async call to show a modal progress @@ -32,7 +39,7 @@ class ModalProgressHUD extends StatelessWidget { /// A [Widget] which should be the the widget to be shown behind the loading barrier. final Widget child; - /// A [double] value specifying the amount of background blur of the progress. + /// A [double] value specifying the amount of background blur when progress hud is active. final double blur; const ModalProgressHUD({ @@ -56,9 +63,9 @@ class ModalProgressHUD extends StatelessWidget { layOutProgressIndicator = Center(child: progressIndicator); } else { layOutProgressIndicator = Positioned( - child: progressIndicator, left: offset!.dx, top: offset!.dy, + child: progressIndicator, ); } @@ -68,8 +75,8 @@ class ModalProgressHUD extends StatelessWidget { BackdropFilter( filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur), child: Opacity( - child: ModalBarrier(dismissible: dismissible, color: color), opacity: opacity, + child: ModalBarrier(dismissible: dismissible, color: color), ), ), layOutProgressIndicator, diff --git a/lib/modal_progress_hud_nsn_method_channel.dart b/lib/modal_progress_hud_nsn_method_channel.dart new file mode 100644 index 0000000..77793d8 --- /dev/null +++ b/lib/modal_progress_hud_nsn_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'modal_progress_hud_nsn_platform_interface.dart'; + +/// An implementation of [ModalProgressHudNsnPlatform] that uses method channels. +class MethodChannelModalProgressHudNsn extends ModalProgressHudNsnPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('modal_progress_hud_nsn'); + + @override + Future getPlatformVersion() async { + final version = await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/lib/modal_progress_hud_nsn_platform_interface.dart b/lib/modal_progress_hud_nsn_platform_interface.dart new file mode 100644 index 0000000..56cd746 --- /dev/null +++ b/lib/modal_progress_hud_nsn_platform_interface.dart @@ -0,0 +1,29 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'modal_progress_hud_nsn_method_channel.dart'; + +abstract class ModalProgressHudNsnPlatform extends PlatformInterface { + /// Constructs a ModalProgressHudNsnPlatform. + ModalProgressHudNsnPlatform() : super(token: _token); + + static final Object _token = Object(); + + static ModalProgressHudNsnPlatform _instance = MethodChannelModalProgressHudNsn(); + + /// The default instance of [ModalProgressHudNsnPlatform] to use. + /// + /// Defaults to [MethodChannelModalProgressHudNsn]. + static ModalProgressHudNsnPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [ModalProgressHudNsnPlatform] when + /// they register themselves. + static set instance(ModalProgressHudNsnPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/lib/modal_progress_hud_nsn_web.dart b/lib/modal_progress_hud_nsn_web.dart new file mode 100644 index 0000000..3a921ff --- /dev/null +++ b/lib/modal_progress_hud_nsn_web.dart @@ -0,0 +1,26 @@ +// In order to *not* need this ignore, consider extracting the "web" version +// of your plugin as a separate package, instead of inlining it in the same +// package as the core of your plugin. +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as html show window; + +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; + +import 'modal_progress_hud_nsn_platform_interface.dart'; + +/// A web implementation of the ModalProgressHudNsnPlatform of the ModalProgressHudNsn plugin. +class ModalProgressHudNsnWeb extends ModalProgressHudNsnPlatform { + /// Constructs a ModalProgressHudNsnWeb + ModalProgressHudNsnWeb(); + + static void registerWith(Registrar registrar) { + ModalProgressHudNsnPlatform.instance = ModalProgressHudNsnWeb(); + } + + /// Returns a [String] containing the version of the platform. + @override + Future getPlatformVersion() async { + final version = html.window.navigator.userAgent; + return version; + } +}