From 60c2e1243dbfb24ca7a3beec2f1a8969e26eef92 Mon Sep 17 00:00:00 2001 From: Midori Date: Sun, 13 Aug 2023 11:50:34 +0900 Subject: [PATCH] Refactor --- example/integration_test/test_app.dart | 18 +++++++++++------- example/lib/main.dart | 13 +++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/example/integration_test/test_app.dart b/example/integration_test/test_app.dart index 3b595e12..62c2cb5f 100644 --- a/example/integration_test/test_app.dart +++ b/example/integration_test/test_app.dart @@ -26,11 +26,11 @@ class App extends StatelessWidget { label: 'Toggle toAlbum', ), buildButton( - onPressed: () async => Gal.hasAccess(), + onPressed: () async => Gal.hasAccess(toAlbum: toAlbum), label: 'hasAccess(toAlbum: $toAlbum)', ), buildButton( - onPressed: () async => Gal.requestAccess(), + onPressed: () async => Gal.requestAccess(toAlbum: toAlbum), label: 'requestAccess(toAlbum: $toAlbum)', ), buildButton( @@ -42,11 +42,8 @@ class App extends StatelessWidget { ), buildButton( onPressed: () async { - final byteData = await rootBundle.load('assets/done.jpg'); - final uint8List = byteData.buffer.asUint8List( - byteData.offsetInBytes, byteData.lengthInBytes); - await Gal.putImageBytes(Uint8List.fromList(uint8List), - album: album); + final bytes = await getBytesData('assets/done.jpg'); + await Gal.putImageBytes(bytes, album: album); }, label: 'putImageBytes(toAlbum: $toAlbum)', ), @@ -101,6 +98,13 @@ class App extends StatelessWidget { .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes)); return file.path; } + + Future getBytesData(String path) async { + final byteData = await rootBundle.load(path); + final uint8List = byteData.buffer + .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes); + return Uint8List.fromList(uint8List); + } } class Logger { diff --git a/example/lib/main.dart b/example/lib/main.dart index 9763f90c..83382ee0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -93,10 +93,8 @@ class _AppState extends State { ), FilledButton( onPressed: () async { - final byteData = await rootBundle.load('assets/done.jpg'); - final uint8List = byteData.buffer.asUint8List( - byteData.offsetInBytes, byteData.lengthInBytes); - await Gal.putImageBytes(Uint8List.fromList(uint8List),album: album); + final bytes = await getBytesData('assets/done.jpg'); + await Gal.putImageBytes(bytes, album: album); if (!context.mounted) return; ScaffoldMessenger.of(context).showSnackBar(snackBar); }, @@ -171,4 +169,11 @@ class _AppState extends State { .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes)); return file.path; } + + Future getBytesData(String path) async { + final byteData = await rootBundle.load(path); + final uint8List = byteData.buffer + .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes); + return Uint8List.fromList(uint8List); + } }