mirror of
https://github.com/Iconica-Development/flutter_media_picker.git
synced 2025-05-19 08:53:45 +02:00
feat: added icon support
This commit is contained in:
parent
7952b3af89
commit
114443fb57
11 changed files with 84 additions and 29 deletions
|
@ -59,6 +59,7 @@ class _MediaPickerState extends ConsumerState<MediaPickerPage> {
|
||||||
height: 15,
|
height: 15,
|
||||||
),
|
),
|
||||||
MediaPicker(
|
MediaPicker(
|
||||||
|
buttonType: ButtonType.icons,
|
||||||
mediaPickerInputs: [
|
mediaPickerInputs: [
|
||||||
MediaPickerInputPhoto(
|
MediaPickerInputPhoto(
|
||||||
pickFile: mediaService.pickImageFile,
|
pickFile: mediaService.pickImageFile,
|
||||||
|
|
|
@ -9,6 +9,7 @@ export './src/inputs/inputs.dart';
|
||||||
export './src/service/services.dart';
|
export './src/service/services.dart';
|
||||||
export './src/media_result.dart';
|
export './src/media_result.dart';
|
||||||
export './src/media_picker.dart';
|
export './src/media_picker.dart';
|
||||||
|
export './src/enums/enums.dart';
|
||||||
|
|
||||||
import 'package:flutter_media_picker/flutter_media_picker.dart';
|
import 'package:flutter_media_picker/flutter_media_picker.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
|
@ -3,11 +3,14 @@
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_media_picker/src/enums/button_type.dart';
|
||||||
import 'package:flutter_media_picker/src/media_result.dart';
|
import 'package:flutter_media_picker/src/media_result.dart';
|
||||||
|
|
||||||
/// Abstract class for inputs used by [MediaPicker].
|
/// Abstract class for inputs used by [MediaPicker].
|
||||||
///
|
///
|
||||||
/// The [label] is used as the title in the header.
|
/// The [label] is used as the title in the header and under the icon, based on which [ButtonType] you chose.
|
||||||
|
///
|
||||||
|
/// The [icon] is used as the icon in the iconButton if [ButtonType] is icon.
|
||||||
///
|
///
|
||||||
/// [onPressed] is called when the user has chosen the input to use.
|
/// [onPressed] is called when the user has chosen the input to use.
|
||||||
///
|
///
|
||||||
|
@ -21,6 +24,8 @@ import 'package:flutter_media_picker/src/media_result.dart';
|
||||||
abstract class MediaPickerInput {
|
abstract class MediaPickerInput {
|
||||||
String label = "Media Picker input";
|
String label = "Media Picker input";
|
||||||
|
|
||||||
|
Widget icon = const Icon(Icons.image);
|
||||||
|
|
||||||
Future<MediaResult> onPressed(BuildContext context);
|
Future<MediaResult> onPressed(BuildContext context);
|
||||||
|
|
||||||
Future<Widget> displayResult(MediaResult result);
|
Future<Widget> displayResult(MediaResult result);
|
||||||
|
|
4
lib/src/enums/button_type.dart
Normal file
4
lib/src/enums/button_type.dart
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
enum ButtonType {
|
||||||
|
icons,
|
||||||
|
text,
|
||||||
|
}
|
1
lib/src/enums/enums.dart
Normal file
1
lib/src/enums/enums.dart
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export 'button_type.dart';
|
|
@ -16,6 +16,7 @@ import 'package:intl/intl.dart';
|
||||||
class MediaPickerInputAudio implements MediaPickerInput {
|
class MediaPickerInputAudio implements MediaPickerInput {
|
||||||
MediaPickerInputAudio({
|
MediaPickerInputAudio({
|
||||||
this.label = "Audio",
|
this.label = "Audio",
|
||||||
|
this.icon = const Icon(Icons.audio_file),
|
||||||
this.checkPageSettings,
|
this.checkPageSettings,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
required this.audioService,
|
required this.audioService,
|
||||||
|
@ -29,6 +30,9 @@ class MediaPickerInputAudio implements MediaPickerInput {
|
||||||
@override
|
@override
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget icon;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MediaResult> onPressed(BuildContext context) async {
|
Future<MediaResult> onPressed(BuildContext context) async {
|
||||||
MediaResult audio = MediaResult();
|
MediaResult audio = MediaResult();
|
||||||
|
|
|
@ -16,6 +16,7 @@ import '../../flutter_media_picker.dart';
|
||||||
class MediaPickerInputFile implements MediaPickerInput {
|
class MediaPickerInputFile implements MediaPickerInput {
|
||||||
MediaPickerInputFile({
|
MediaPickerInputFile({
|
||||||
this.label = "File",
|
this.label = "File",
|
||||||
|
this.icon = const Icon(Icons.file_copy),
|
||||||
this.fileExtensions = const ['pdf', 'jpg', 'png'],
|
this.fileExtensions = const ['pdf', 'jpg', 'png'],
|
||||||
this.checkPageSettings,
|
this.checkPageSettings,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
|
@ -28,6 +29,9 @@ class MediaPickerInputFile implements MediaPickerInput {
|
||||||
@override
|
@override
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget icon;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MediaResult> onPressed(BuildContext context) async {
|
Future<MediaResult> onPressed(BuildContext context) async {
|
||||||
var file = await pickFile?.call(fileExtensions);
|
var file = await pickFile?.call(fileExtensions);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import 'package:flutter_media_picker/src/media_result.dart';
|
||||||
class MediaPickerInputPhoto implements MediaPickerInput {
|
class MediaPickerInputPhoto implements MediaPickerInput {
|
||||||
MediaPickerInputPhoto({
|
MediaPickerInputPhoto({
|
||||||
this.label = "Photo",
|
this.label = "Photo",
|
||||||
|
this.icon = const Icon(Icons.image),
|
||||||
this.checkPageSettings,
|
this.checkPageSettings,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
this.pickFile,
|
this.pickFile,
|
||||||
|
@ -23,6 +24,9 @@ class MediaPickerInputPhoto implements MediaPickerInput {
|
||||||
@override
|
@override
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget icon;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MediaResult> onPressed(BuildContext context) async {
|
Future<MediaResult> onPressed(BuildContext context) async {
|
||||||
var image = await pickFile?.call();
|
var image = await pickFile?.call();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
class MediaPickerInputText implements MediaPickerInput {
|
class MediaPickerInputText implements MediaPickerInput {
|
||||||
MediaPickerInputText({
|
MediaPickerInputText({
|
||||||
this.label = "Text",
|
this.label = "Text",
|
||||||
|
this.icon = const Icon(Icons.text_fields),
|
||||||
this.checkPageSettings,
|
this.checkPageSettings,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
});
|
});
|
||||||
|
@ -19,6 +20,9 @@ class MediaPickerInputText implements MediaPickerInput {
|
||||||
@override
|
@override
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget icon;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MediaResult> onPressed(BuildContext context) async {
|
Future<MediaResult> onPressed(BuildContext context) async {
|
||||||
return MediaResult();
|
return MediaResult();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import 'package:flutter_media_picker/flutter_media_picker.dart';
|
||||||
class MediaPickerInputVideo implements MediaPickerInput {
|
class MediaPickerInputVideo implements MediaPickerInput {
|
||||||
MediaPickerInputVideo({
|
MediaPickerInputVideo({
|
||||||
this.label = "Video",
|
this.label = "Video",
|
||||||
|
this.icon = const Icon(Icons.video_camera_front),
|
||||||
this.checkPageSettings,
|
this.checkPageSettings,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
this.pickFile,
|
this.pickFile,
|
||||||
|
@ -23,6 +24,9 @@ class MediaPickerInputVideo implements MediaPickerInput {
|
||||||
@override
|
@override
|
||||||
String label;
|
String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget icon;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MediaResult> onPressed(BuildContext context) async {
|
Future<MediaResult> onPressed(BuildContext context) async {
|
||||||
var image = await pickFile?.call();
|
var image = await pickFile?.call();
|
||||||
|
|
|
@ -104,14 +104,19 @@ class MediaPicker extends ConsumerWidget {
|
||||||
const MediaPicker({
|
const MediaPicker({
|
||||||
this.mediaPickerInputs,
|
this.mediaPickerInputs,
|
||||||
this.header,
|
this.header,
|
||||||
|
this.iconButton,
|
||||||
this.onComplete,
|
this.onComplete,
|
||||||
this.mediaCheckPage,
|
this.mediaCheckPage,
|
||||||
|
this.buttonType = ButtonType.text,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final List<MediaPickerInput>? mediaPickerInputs;
|
final List<MediaPickerInput>? mediaPickerInputs;
|
||||||
final Widget Function(String label, Function onPressed)? header;
|
final Widget Function(String label, Function onPressed)? header;
|
||||||
|
final Widget Function(String label, Widget icon, Function onPressed)?
|
||||||
|
iconButton;
|
||||||
final void Function(MediaResult result)? onComplete;
|
final void Function(MediaResult result)? onComplete;
|
||||||
|
final ButtonType buttonType;
|
||||||
final Widget Function(
|
final Widget Function(
|
||||||
Widget displayResult,
|
Widget displayResult,
|
||||||
Map<String, dynamic>? inputSettings,
|
Map<String, dynamic>? inputSettings,
|
||||||
|
@ -136,6 +141,7 @@ class MediaPicker extends ConsumerWidget {
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
if (buttonType == ButtonType.text) ...[
|
||||||
for (final input in inputs) ...[
|
for (final input in inputs) ...[
|
||||||
const SizedBox(height: 2.5),
|
const SizedBox(height: 2.5),
|
||||||
header?.call(input.label, (BuildContext ct) async {
|
header?.call(input.label, (BuildContext ct) async {
|
||||||
|
@ -170,6 +176,23 @@ class MediaPicker extends ConsumerWidget {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 2.5),
|
const SizedBox(height: 2.5),
|
||||||
],
|
],
|
||||||
|
] else ...[
|
||||||
|
for (final input in inputs) ...[
|
||||||
|
iconButton?.call(input.label, input.icon, (BuildContext ct) async {
|
||||||
|
await onPressedMediaType(ct, input);
|
||||||
|
}) ?? GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
await onPressedMediaType(context, input);
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
input.icon,
|
||||||
|
Text(input.label),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
]
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue