From b7c71beaa0ee2d988d61623456efa31f30045932 Mon Sep 17 00:00:00 2001 From: Sanjay Soni Date: Sat, 1 Jul 2023 02:20:45 +0530 Subject: [PATCH] Add builder constructor and update version to 0.0.2 --- .dart_tool/package_config.json | 4 +- .dart_tool/package_config_subset | 2 +- CHANGELOG.md | 2 +- README.md | 71 ++++++++++++++++++--- example/lib/main.dart | 40 +++++++++++- example/pubspec.lock | 2 +- lib/src/widget.dart | 103 +++++++++++++++++++------------ pubspec.lock | 2 +- pubspec.yaml | 10 ++- screenshots/logo.png | Bin 0 -> 5063 bytes 10 files changed, 175 insertions(+), 61 deletions(-) create mode 100644 screenshots/logo.png diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index e9f1ad0..257488a 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -137,10 +137,10 @@ "name": "obscure_widget", "rootUri": "../", "packageUri": "lib/", - "languageVersion": "2.18" + "languageVersion": "2.14" } ], - "generated": "2023-06-29T15:04:42.862450Z", + "generated": "2023-06-30T20:48:57.301279Z", "generator": "pub", "generatorVersion": "2.18.6" } diff --git a/.dart_tool/package_config_subset b/.dart_tool/package_config_subset index f2c0bbf..049d113 100644 --- a/.dart_tool/package_config_subset +++ b/.dart_tool/package_config_subset @@ -75,7 +75,7 @@ vector_math file:///Users/sanjaysoni/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/ file:///Users/sanjaysoni/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/lib/ obscure_widget -2.18 +2.14 file:///Users/sanjaysoni/Documents/GitHub/ObscureWidget/ file:///Users/sanjaysoni/Documents/GitHub/ObscureWidget/lib/ sky_engine diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc7d8..3906b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ ## 0.0.1 -* TODO: Describe initial release. +- Add ObscureWidget(), ObscureWidget.builder() and obscure() extension on widget. diff --git a/README.md b/README.md index 86bfd7e..d026ecb 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,66 @@ -# obscure_widget +# ObscureWidget blur its child when screen is being captured -A new Flutter plugin project. +## Usages -## Getting Started +Lets take a look at how to use `ObscureWidget`, `ObscureWidget.builder()` and `.obscured()` extension. -This project is a starting point for a Flutter -[plug-in package](https://flutter.dev/developing-packages/), -a specialized package that includes platform-specific implementation code for -Android and/or iOS. +### ObscureWidget -For help getting started with Flutter development, view the -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +supported parameters **blur**, **blurColor**, **borderRadius**, and **colorOpacity** +```dart +ObscureWidget( + child: Container( + width: double.infinity, + color: Colors.amber, + padding: const EdgeInsets.all(18.0), + child: Text( + 'Secure Text', + style: Theme.of(context).textTheme.headline6, + ), + ), +) +``` + +### with .obscured() extension + +```dart + Container( + width: double.infinity, + color: Colors.amber, + padding: const EdgeInsets.all(18.0), + child: Text( + 'Other Secure Text with extension', + style: Theme.of(context).textTheme.headline6, + ), +).obscured(blur: 2, blurColor: Colors.red), +``` + +### ObscureWidget.builder() + +use this for custom implementation + +```dart +ObscureWidget.builder( + obscureBuilder: (context, isCaptured, child) { + return Container( + decoration: BoxDecoration( + border: Border.all( + width: 4, + color: isCaptured ? Colors.red : Colors.green, + ), + ), + child: child, + ); + }, + child: Container( + width: double.infinity, + color: Colors.black, + padding: const EdgeInsets.all(18.0), + child: Text( + 'Other Secure Text with builder constructor', + style: Theme.of(context).textTheme.headline6?.copyWith(color: Colors.white), + ), + ), +) +``` diff --git a/example/lib/main.dart b/example/lib/main.dart index 45bb8cb..230da56 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,9 +11,13 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + theme: ThemeData.dark(), home: Scaffold( - body: Column( - mainAxisAlignment: MainAxisAlignment.center, + appBar: AppBar( + title: const Text('ObscureWidget examples'), + ), + body: ListView( + padding: const EdgeInsets.all(16.0), children: [ ObscureWidget( child: Container( @@ -26,7 +30,9 @@ class MyApp extends StatelessWidget { ), ), ), + const SizedBox(height: 20), + Container( width: double.infinity, color: Colors.grey, @@ -36,16 +42,44 @@ class MyApp extends StatelessWidget { style: Theme.of(context).textTheme.headline6, ), ), + const SizedBox(height: 20), + Container( width: double.infinity, color: Colors.amber, padding: const EdgeInsets.all(18.0), child: Text( - 'Other Secure Text', + 'Other Secure Text with extension', style: Theme.of(context).textTheme.headline6, ), ).obscured(blur: 2, blurColor: Colors.red), + + const SizedBox(height: 20), + + // builder example + ObscureWidget.builder( + obscureBuilder: (context, isCaptured, child) { + return Container( + decoration: BoxDecoration( + border: Border.all( + width: 4, + color: isCaptured ? Colors.red : Colors.green, + ), + ), + child: child, + ); + }, + child: Container( + width: double.infinity, + color: Colors.black, + padding: const EdgeInsets.all(18.0), + child: Text( + 'Other Secure Text with builder constructor', + style: Theme.of(context).textTheme.headline6?.copyWith(color: Colors.white), + ), + ), + ) ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index cb0deee..c638b9c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -101,7 +101,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "0.0.2" path: dependency: transitive description: diff --git a/lib/src/widget.dart b/lib/src/widget.dart index 907010b..40a9ab6 100644 --- a/lib/src/widget.dart +++ b/lib/src/widget.dart @@ -23,58 +23,81 @@ class ObscureWidgetController { } /// blur it's **child** when screen is being captured/recorded. -/// -///* **[blur]** is the value of blur effect, higher the blur more the blur effect (default value = 5) -/// -///* **[blurColor]** is the color of blur effect (default value = Colors.white) -/// -///* **[borderRadius]** is the radius of the child to be blurred -/// -///* **[colorOpacity]** is the opacity of the blurColor (default value = 0.5) - class ObscureWidget extends StatelessWidget { + /// + ///* **[blur]** is the value of blur effect, higher the blur more the blur effect (default value = 5) + /// + ///* **[blurColor]** is the color of blur effect (default value = Colors.white) + /// + ///* **[borderRadius]** is the radius of the child to be blurred + /// + ///* **[colorOpacity]** is the opacity of the blurColor (default value = 0.5) + /// const ObscureWidget({ - super.key, - required this.child, - this.blur = 5, - this.blurColor = Colors.white, - this.borderRadius, - this.colorOpacity = 0.5, - }); + Key? key, + required Widget child, + double blur = 5, + Color blurColor = Colors.white, + BorderRadius? borderRadius, + double colorOpacity = 0.5, + }) : _builder = null, + _child = child, + _blur = blur, + _blurColor = blurColor, + _colorOpacity = colorOpacity, + _borderRadius = borderRadius, + super(key: key); + + /// + ///* use **[obscureBuilder]** to create custom obscure implementation + /// + const ObscureWidget.builder({ + Key? key, + Widget? child, + required Widget Function(BuildContext context, bool isCaptured, Widget? child) obscureBuilder, + }) : _builder = obscureBuilder, + _child = child, + _blur = 5, + _blurColor = Colors.white, + _colorOpacity = 0.5, + _borderRadius = null, + super(key: key); - final Widget child; - final double blur; - final Color blurColor; - final BorderRadius? borderRadius; - final double colorOpacity; + final Widget? _child; + final double _blur; + final Color _blurColor; + final BorderRadius? _borderRadius; + final double _colorOpacity; + final Widget Function(BuildContext, bool, Widget?)? _builder; @override Widget build(BuildContext context) { return ValueListenableBuilder( - builder: (_, isCaptured, child) { - if (isCaptured == false) return child!; + builder: _builder ?? + (_, isCaptured, child) { + if (isCaptured == false) return child!; - return ClipRRect( - borderRadius: borderRadius ?? BorderRadius.zero, - child: Stack( - children: [ - child!, - Positioned.fill( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur), - child: Container( - decoration: BoxDecoration( - color: blurColor.withOpacity(colorOpacity), + return ClipRRect( + borderRadius: _borderRadius ?? BorderRadius.zero, + child: Stack( + children: [ + child!, + Positioned.fill( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: _blur, sigmaY: _blur), + child: Container( + decoration: BoxDecoration( + color: _blurColor.withOpacity(_colorOpacity), + ), + ), ), ), - ), + ], ), - ], - ), - ); - }, + ); + }, valueListenable: ObscureWidgetController.isCaptured, - child: child, + child: _child, ); } } diff --git a/pubspec.lock b/pubspec.lock index 1c9ac04..a688057 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -150,5 +150,5 @@ packages: source: hosted version: "2.1.2" sdks: - dart: ">=2.18.6 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=2.5.0" diff --git a/pubspec.yaml b/pubspec.yaml index 85e285b..2b5f173 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,10 +2,12 @@ name: obscure_widget description: ObscureWidget blur its child when screen is being captured. version: 0.0.1 homepage: https://github.com/imSanjaySoni/ObscureWidget -repository: https://github.com/imSanjaySoni/ObscureWidget.git +repository: https://github.com/imSanjaySoni/ObscureWidget/tree/main +issue_tracker: https://github.com/imSanjaySoni/ObscureWidget/issues +documentation: https://github.com/imSanjaySoni/ObscureWidget/tree/main#readme environment: - sdk: '>=2.18.6 <3.0.0' + sdk: '>=2.14.0 <4.0.0' flutter: ">=2.5.0" dependencies: @@ -25,3 +27,7 @@ flutter: ios: pluginClass: ObscureWidgetPlugin sharedDarwinSource: true + +screenshots: + - description: The obscure_widget plugin logo. + path: screenshots/logo.png \ No newline at end of file diff --git a/screenshots/logo.png b/screenshots/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..a71da5d054ee73518fbae8c72ebc8f72ceff19d2 GIT binary patch literal 5063 zcmeI0`CAj$8pnqKMMOa0wkT4t>XnMfs#s(R3e=UwtzZKtmJ6xui-<^Iz&@q5)>;=N z0U=V0tOBw_l%%LcLt;|dgaD~%g2)nJ5<>C9u;=ePuO!T82}8-G?x~Te`6J9)Ji_I zdlyjs)N&kq(IM~j-w6PBFB!lmbOFFDbg%EuBWJXxhW)ET#To3`D~7F&11^^iuRA7f0*d@av&HroxkZvIL9u;5DPK>+vY|{O^8t5!-sr)SPuWU-7pi+WTGS4B^e2Qn(?3YB(t zcK*RzV|X>?h5J|m+X(-xr$sg$n7^J)|CVY6@gtF*857pSFvfA>bTD4!_h2hc(<%o5 zvb-@e;q|+|7>7rO2Ju8R=MaW=64Ff=F%H)v74MpFHlNtl>R^MA1*<)H}9Gh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