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

✨ new InstaAssetPickerBuilderOptions options class #48

Merged
merged 1 commit into from
Jul 9, 2024
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
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
Loading