Skip to content

Commit

Permalink
✨ new InstaAssetPickerBuilderOptions options class (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeGoffMael authored Jul 9, 2024
1 parent d08f083 commit 5da1987
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 225 deletions.
87 changes: 45 additions & 42 deletions example/lib/pages/camera/camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,50 +79,53 @@ class _CameraPickerState extends State<CameraPicker> {
context,
onPressed: () => InstaAssetPicker.pickAssets(
context,
title: widget.description.fullLabel,
maxAssets: 4,
pickerTheme: widget.getPickerTheme(context),
actionsBuilder: (
BuildContext context,
ThemeData? pickerTheme,
double height,
VoidCallback unselectAll,
) =>
[
InstaPickerCircleIconButton.unselectAll(
onTap: unselectAll,
theme: pickerTheme,
size: height,
),
const SizedBox(width: 8),
InstaPickerCircleIconButton(
onTap: () => _pickFromCamera(context),
theme: pickerTheme,
icon: const Icon(Icons.camera_alt),
size: height,
),
],
specialItemBuilder: (BuildContext context, _, __) {
// return a button that open the camera
return ElevatedButton(
onPressed: () => _pickFromCamera(context),
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(),
foregroundColor: Colors.white,
backgroundColor: Colors.transparent,
builderOptions: InstaAssetPickerBuilderOptions(
context,
title: widget.description.fullLabel,
pickerTheme: widget.getPickerTheme(context),
actionsBuilder: (
BuildContext context,
ThemeData? pickerTheme,
double height,
VoidCallback unselectAll,
) =>
[
InstaPickerCircleIconButton.unselectAll(
onTap: unselectAll,
theme: pickerTheme,
size: height,
),
child: FittedBox(
fit: BoxFit.cover,
child: Text(
InstaAssetPicker.defaultTextDelegate(context)
.sActionUseCameraHint,
textAlign: TextAlign.center,
),
const SizedBox(width: 8),
InstaPickerCircleIconButton(
onTap: () => _pickFromCamera(context),
theme: pickerTheme,
icon: const Icon(Icons.camera_alt),
size: height,
),
);
},
// since the list is revert, use prepend to be at the top
specialItemPosition: SpecialItemPosition.prepend,
],
specialItemBuilder: (BuildContext context, _, __) {
// return a button that open the camera
return ElevatedButton(
onPressed: () => _pickFromCamera(context),
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(),
foregroundColor: Colors.white,
backgroundColor: Colors.transparent,
),
child: FittedBox(
fit: BoxFit.cover,
child: Text(
InstaAssetPicker.defaultTextDelegate(context)
.sActionUseCameraHint,
textAlign: TextAlign.center,
),
),
);
},
// since the list is revert, use prepend to be at the top
specialItemPosition: SpecialItemPosition.prepend,
),
maxAssets: 4,
onCompleted: (cropStream) {
Navigator.push(
context,
Expand Down
111 changes: 57 additions & 54 deletions example/lib/pages/camera/wechat_camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,65 @@ class WeChatCameraPicker extends StatelessWidget with InstaPickerInterface {
context,
onPressed: () => InstaAssetPicker.pickAssets(
context,
title: description.fullLabel,
maxAssets: 4,
pickerTheme: getPickerTheme(context),
actionsBuilder: (
BuildContext context,
ThemeData? pickerTheme,
double height,
VoidCallback unselectAll,
) =>
[
InstaPickerCircleIconButton.unselectAll(
onTap: unselectAll,
theme: pickerTheme,
size: height,
),
const SizedBox(width: 8),
InstaPickerCircleIconButton(
onTap: () => _pickFromWeChatCamera(context),
theme: pickerTheme,
icon: const Icon(Icons.camera_alt),
size: height,
),
],
specialItemBuilder: (context, _, __) {
// return a button that open the camera
return ElevatedButton(
onPressed: () async {
Feedback.forTap(context);
final AssetEntity? entity =
await _pickFromWeChatCamera(context);
if (entity == null) return;

if (context.mounted) {
await InstaAssetPicker.refreshAndSelectEntity(
context,
entity,
);
}
},
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(),
foregroundColor: Colors.white,
backgroundColor: Colors.transparent,
builderOptions: InstaAssetPickerBuilderOptions(
context,
title: description.fullLabel,
pickerTheme: getPickerTheme(context),
actionsBuilder: (
BuildContext context,
ThemeData? pickerTheme,
double height,
VoidCallback unselectAll,
) =>
[
InstaPickerCircleIconButton.unselectAll(
onTap: unselectAll,
theme: pickerTheme,
size: height,
),
child: FittedBox(
fit: BoxFit.cover,
child: Text(
InstaAssetPicker.defaultTextDelegate(context)
.sActionUseCameraHint,
textAlign: TextAlign.center,
),
const SizedBox(width: 8),
InstaPickerCircleIconButton(
onTap: () => _pickFromWeChatCamera(context),
theme: pickerTheme,
icon: const Icon(Icons.camera_alt),
size: height,
),
);
},
// since the list is revert, use prepend to be at the top
specialItemPosition: SpecialItemPosition.prepend,
],
specialItemBuilder: (context, _, __) {
// return a button that open the camera
return ElevatedButton(
onPressed: () async {
Feedback.forTap(context);
final AssetEntity? entity =
await _pickFromWeChatCamera(context);
if (entity == null) return;

if (context.mounted) {
await InstaAssetPicker.refreshAndSelectEntity(
context,
entity,
);
}
},
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(),
foregroundColor: Colors.white,
backgroundColor: Colors.transparent,
),
child: FittedBox(
fit: BoxFit.cover,
child: Text(
InstaAssetPicker.defaultTextDelegate(context)
.sActionUseCameraHint,
textAlign: TextAlign.center,
),
),
);
},
// since the list is revert, use prepend to be at the top
specialItemPosition: SpecialItemPosition.prepend,
),
maxAssets: 4,
onCompleted: (cropStream) {
Navigator.push(
context,
Expand Down
9 changes: 6 additions & 3 deletions example/lib/pages/restorable_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ class _PickerScreenState extends State<RestorablePicker> {
final List<AssetEntity>? result =
await _instaAssetsPicker.restorableAssetsPicker(
context,
title: widget.description.fullLabel,
closeOnComplete: true,
builderOptions: InstaAssetPickerBuilderOptions(
context,
title: widget.description.fullLabel,
closeOnComplete: true,
pickerTheme: _pickerTheme,
),
provider: () => _provider,
pickerTheme: _pickerTheme,
onCompleted: (cropStream) {
// example withtout StreamBuilder
cropStream.listen((event) {
Expand Down
9 changes: 6 additions & 3 deletions example/lib/widgets/insta_picker_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ mixin InstaPickerInterface on Widget {
void pickAssets(BuildContext context, {required int maxAssets}) =>
InstaAssetPicker.pickAssets(
context,
title: description.fullLabel,
closeOnComplete: true,
builderOptions: InstaAssetPickerBuilderOptions(
context,
title: description.fullLabel,
closeOnComplete: true,
pickerTheme: getPickerTheme(context),
),
maxAssets: maxAssets,
pickerTheme: getPickerTheme(context),
onCompleted: (Stream<InstaAssetsExportDetails> cropStream) {
Navigator.push(
context,
Expand Down
Loading

0 comments on commit 5da1987

Please sign in to comment.