Skip to content

Commit

Permalink
Add builder constructor and update version to 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
imSanjaySoni committed Jun 30, 2023
1 parent 796e7d6 commit b7c71be
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion .dart_tool/package_config_subset
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
- Add ObscureWidget(), ObscureWidget.builder() and obscure() extension on widget.
71 changes: 61 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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),
),
),
)
```
40 changes: 37 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -26,7 +30,9 @@ class MyApp extends StatelessWidget {
),
),
),

const SizedBox(height: 20),

Container(
width: double.infinity,
color: Colors.grey,
Expand All @@ -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),
),
),
)
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.0.2"
path:
dependency: transitive
description:
Expand Down
103 changes: 63 additions & 40 deletions lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(
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,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 8 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,3 +27,7 @@ flutter:
ios:
pluginClass: ObscureWidgetPlugin
sharedDarwinSource: true

screenshots:
- description: The obscure_widget plugin logo.
path: screenshots/logo.png
Binary file added screenshots/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b7c71be

Please sign in to comment.