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

upgrade to V0.0.6 #14

Merged
merged 1 commit into from
Jul 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.3\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.3\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2023-07-12 19:41:51.168359","version":"3.10.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.3\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.3\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.8+4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"package_info_plus","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\package_info_plus-4.0.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2023-07-19 17:26:20.751085","version":"3.10.6"}
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.0.6

- Upgrade Packages.
- integrate `flutter_screenutil` package into the package to make widgets more responsive.
- Add new widget `OptimizedListTile` which is a widget that is enhanced version of list tile that
can display a card with title, subtitle, leading and trailing widgets.
- update `OptimizedCard` to enhance card shadows.
- add `radius` to `CenterLoading` widget.

## 0.0.5

- Upgrade Packages.
Expand Down Expand Up @@ -27,5 +36,4 @@
- Add lottie package.

## 0.0.1

- initial release
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ PlayX widget package for playx eco system that provide custom utility widgets to

## Features
- Common widgets that are needed in each project.
- Exports : packages like [`package_info_plus`](https://pub.dev/packages/package_info_plus) ,
[`flutter_svg`](https://pub.dev/packages/flutter_svg) , [`Lottie`](https://pub.dev/packages/lottie)
and [`cached_network_image`](https://pub.dev/packages/cached_network_image).
- Exports : packages like [`package_info_plus`](https://pub.dev/packages/package_info_plus) ,
[`flutter_svg`](https://pub.dev/packages/flutter_svg)
, [`Lottie`](https://pub.dev/packages/lottie)
, [`cached_network_image`](https://pub.dev/packages/cached_network_image)
and [`flutter_screenutil `](https://pub.dev/packages/flutter_screenutil).


## Widgets
Expand All @@ -25,6 +27,8 @@ and [`cached_network_image`](https://pub.dev/packages/cached_network_image).
- `OptimizedTextField` : OptimizedTextField is a customized text field with features like auto
validation with the ability to be customized.
- `OptimizedButton` : Widget that can be used to display any type of button.
- `OptimizedListTile` : Widget that is enhanced version of list tile that can display a card with
title, subtitle, leading and trailing widgets.
- `AnimatedVisibility` : Widget that animates the visibility of child widget by updating widget
opacity and hide the old widget.
It's different than `AnimatedOpacity` as it doesn't take any space when the widget is invisible.
Expand All @@ -40,7 +44,7 @@ Which comes prepackaged with this package and more features and is easy to use.
in `pubspec.yaml` add these lines to `dependencies`

```yaml
playx_widget: ^0.0.5
playx_widget: ^0.0.6
```

## See Also:
Expand Down
136 changes: 83 additions & 53 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,98 @@ import 'package:flutter/material.dart';
import 'package:playx_widget/playx_widget.dart';

void main() async {
runApp(const MyApp());
runApp(ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return const MaterialApp(title: 'Flutter Demo', home: MyApp());
}));
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: KeepAliveWrapper(
child: Scaffold(
appBar: AppBar(
title: const Text('Playx Example'),
),
body: OptimizedScrollView(
child: Column(
children: [
const SizedBox(
height: 100,
),
const SizedBox(
height: 100,
child: AppVersion(
prefix: 'Version ',
),
),
const SizedBox(
height: 100,
child: CenterLoading(
color: Colors.blue,
),
),
ImageViewer.cachedNetwork(
'https://avatars.githubusercontent.com/u/35397170?s=200&v=4',
height: 100,
),
SizedBox(
height: 100,
return Scaffold(
appBar: AppBar(
title: const Text('Playx Example'),
),
body: OptimizedScrollView(
child: Column(
children: [
const SizedBox(
height: 100,
),
const SizedBox(
height: 100,
child: AppVersion(
prefix: 'Version ',
),
),
const SizedBox(
height: 100,
child: CenterLoading(
color: Colors.blue,
),
),
const OptimizedCard(
margin: EdgeInsets.all(16),
innerCardShadowMargin: EdgeInsets.all(4),
width: double.infinity,
height: 200,
padding: EdgeInsets.all(12),
child: Center(child: Text('Ahmed Mohamed')),
),
OptimizedListTile(
leading: const Icon(Icons.speed),
title: SizedBox(
width: double.infinity,
child: AutoAnimatedList(
items: const ['Ahmed', 'Mohamed', 'Mohsen'],
itemBuilder:
(BuildContext context, String item, int index) {
return Text(item);
},
),
),
OptimizedButton.elevated(
child: Text('Confirm'),
onPressed: () {},
),
OptimizedCard(
child: Container(
width: double.infinity,
height: 100,
padding: const EdgeInsets.all(8),
child: const Text('Ahmed Mohamed')),
)
],
child: Text(
'Speed',
textAlign: TextAlign.start,
style: TextStyle(fontSize: 14.sp),
)),
subtitle: SizedBox(
width: double.infinity,
child: Text(
'30 km/h',
style: TextStyle(fontSize: 12.sp),
textAlign: TextAlign.start,
)),
trailing: const Icon(Icons.car_repair),
contentPadding:
EdgeInsets.symmetric(horizontal: 8.w, vertical: 6.h),
horizontalSpace: 8.w,
),
ImageViewer.cachedNetwork(
'https://avatars.githubusercontent.com/u/35397170?s=200&v=4',
height: 100,
),
SizedBox(
height: 100,
width: double.infinity,
child: AutoAnimatedList(
items: const ['Ahmed', 'Mohamed', 'Mohsen'],
itemBuilder: (BuildContext context, String item, int index) {
return Text(item);
},
),
),
OptimizedButton.elevated(
child: Text('Confirm'),
onPressed: () {
showConfirmDialog(
title: 'Are you sure',
message: 'Are you sure you want to exit ?',
lottie: '',
onConfirmed: () {},
context: context,
lottieAnimationHeight: 200);
},
),
),
],
),
),
);
Expand Down
14 changes: 11 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_screenutil:
dependency: transitive
description:
name: flutter_screenutil
sha256: "1b61f8c4cbf965104b6ca7160880ff1af6755aad7fec70b58444245132453745"
url: "https://pub.dev"
source: hosted
version: "5.8.4"
flutter_svg:
dependency: transitive
description:
Expand Down Expand Up @@ -204,10 +212,10 @@ packages:
dependency: transitive
description:
name: lottie
sha256: f461105d3a35887b27089abf9c292334478dd292f7b47ecdccb6ae5c37a22c80
sha256: "0793a5866062e5cc8a8b24892fa94c3095953ea914a7fdf790f550dd7537fe60"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.5.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -350,7 +358,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.4"
version: "0.0.6"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions lib/playx_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export 'package:playx_widget/src/widgets/optimized_button.dart';
export 'package:playx_widget/src/widgets/optimized_text_field.dart';
export 'package:playx_widget/src/widgets/timer_refresh_widget.dart';
export 'package:playx_widget/src/alerts/confirmation_dialog.dart';
export 'package:flutter_screenutil/flutter_screenutil.dart';
export 'package:playx_widget/src/widgets/optimized_list_tile.dart';
4 changes: 3 additions & 1 deletion lib/src/alerts/confirmation_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Future<bool> showConfirmDialog({
child: Container(
height: lottieAnimationHeight,
padding: lottieAnimationPadding,
child: Lottie.asset(lottie, width: double.infinity),
child: lottie.isEmpty
? Container()
: Lottie.asset(lottie, width: double.infinity),
),
),
const SizedBox(
Expand Down
98 changes: 87 additions & 11 deletions lib/src/utils/common_utils.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_svg/flutter_svg.dart';

Future<Uint8List> getUnit8ListFromSvgAsset(
String assetName, {
Size size = const Size(48, 48),
}) async {
final pictureInfo = await vg.loadPicture(SvgAssetLoader(assetName), null);
Future<Uint8List> getImageFromSvgAsset(String assetName,
{Size size = const Size(48, 48),
BuildContext? context,
ColorMapper? colorMapper}) async {
final pictureInfo = await vg.loadPicture(
SvgAssetLoader(
assetName,
colorMapper: colorMapper,
),
null,
);

// ignore: use_build_context_synchronously
final view = _getFlutterView(context: context);
if (view == null) throw Exception('Could not find flutter view');

final devicePixelRatio = WidgetsBinding.instance.platformDispatcher.views
.map((e) => e.devicePixelRatio)
.reduce((value, element) => max(value, element));
final devicePixelRatio = view.devicePixelRatio;
final width = (size.width * devicePixelRatio).toInt();
final height = (size.height * devicePixelRatio).toInt();

Expand All @@ -22,7 +31,7 @@ Future<Uint8List> getUnit8ListFromSvgAsset(
height / pictureInfo.size.height,
);

final recorder = PictureRecorder();
final recorder = ui.PictureRecorder();

Canvas(recorder)
..scale(scaleFactor)
Expand All @@ -31,7 +40,74 @@ Future<Uint8List> getUnit8ListFromSvgAsset(
final rasterPicture = recorder.endRecording();

final image = rasterPicture.toImageSync(width, height);
final bytes = (await image.toByteData(format: ImageByteFormat.png))!;
final bytes = (await image.toByteData(format: ui.ImageByteFormat.png))!;

return bytes.buffer.asUint8List();
}

// https://github.com/flutter/flutter/issues/40064
/// Creates an image from the given [widget] by
/// 1. Spinning up an element and render tree;
/// 2. Waiting for the given [delay];
/// 3. Creating an image via a [RepaintBoundary].
Future<Uint8List> getImagefromWidget(
Widget widget, {
Duration delay = const Duration(milliseconds: 100),
BuildContext? context,
}) async {
final view = _getFlutterView(context: context);
if (view == null) throw Exception('Could not find flutter view');

final devicePixelRatio = view.devicePixelRatio;
final repaintBoundary = RenderRepaintBoundary();
final renderView = RenderView(
child: RenderPositionedBox(child: repaintBoundary),
configuration: ViewConfiguration(
size: const Size.square(300.0),
devicePixelRatio: devicePixelRatio,
),
view: view,
);

final pipelineOwner = PipelineOwner()..rootNode = renderView;
renderView.prepareInitialFrame();

final buildOwner = BuildOwner(focusManager: FocusManager());

final rootElement = RenderObjectToWidgetAdapter(
container: repaintBoundary,
child: Directionality(
textDirection: ui.TextDirection.ltr,
child: IntrinsicHeight(child: IntrinsicWidth(child: widget)),
),
).attachToRenderTree(buildOwner);

buildOwner.buildScope(rootElement);

if (delay > Duration.zero) await Future.delayed(delay);

buildOwner
..buildScope(rootElement)
..finalizeTree();
pipelineOwner
..flushLayout()
..flushCompositingBits()
..flushPaint();

final image = await repaintBoundary.toImage(pixelRatio: devicePixelRatio);

final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
return byteData!.buffer.asUint8List();
}

ui.FlutterView? _getFlutterView({BuildContext? context}) {
if (context != null) {
return View.of(context);
}

final views = WidgetsBinding.instance.platformDispatcher.views;
if (views.isNotEmpty) {
return WidgetsBinding.instance.platformDispatcher.views.first;
}
return null;
}
Loading
Loading