Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Aug 13, 2023
1 parent cceacd9 commit 60c2e12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
18 changes: 11 additions & 7 deletions example/integration_test/test_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)',
),
Expand Down Expand Up @@ -101,6 +98,13 @@ class App extends StatelessWidget {
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file.path;
}

Future<Uint8List> 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 {
Expand Down
13 changes: 9 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ class _AppState extends State<App> {
),
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);
},
Expand Down Expand Up @@ -171,4 +169,11 @@ class _AppState extends State<App> {
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file.path;
}

Future<Uint8List> getBytesData(String path) async {
final byteData = await rootBundle.load(path);
final uint8List = byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes);
return Uint8List.fromList(uint8List);
}
}

0 comments on commit 60c2e12

Please sign in to comment.