mirror of
https://github.com/Iconica-Development/flutter_media_picker.git
synced 2025-05-19 00:43: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,
|
||||
),
|
||||
MediaPicker(
|
||||
buttonType: ButtonType.icons,
|
||||
mediaPickerInputs: [
|
||||
MediaPickerInputPhoto(
|
||||
pickFile: mediaService.pickImageFile,
|
||||
|
|
|
@ -9,6 +9,7 @@ export './src/inputs/inputs.dart';
|
|||
export './src/service/services.dart';
|
||||
export './src/media_result.dart';
|
||||
export './src/media_picker.dart';
|
||||
export './src/enums/enums.dart';
|
||||
|
||||
import 'package:flutter_media_picker/flutter_media_picker.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_media_picker/src/enums/button_type.dart';
|
||||
import 'package:flutter_media_picker/src/media_result.dart';
|
||||
|
||||
/// 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.
|
||||
///
|
||||
|
@ -21,6 +24,8 @@ import 'package:flutter_media_picker/src/media_result.dart';
|
|||
abstract class MediaPickerInput {
|
||||
String label = "Media Picker input";
|
||||
|
||||
Widget icon = const Icon(Icons.image);
|
||||
|
||||
Future<MediaResult> onPressed(BuildContext context);
|
||||
|
||||
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 {
|
||||
MediaPickerInputAudio({
|
||||
this.label = "Audio",
|
||||
this.icon = const Icon(Icons.audio_file),
|
||||
this.checkPageSettings,
|
||||
this.onComplete,
|
||||
required this.audioService,
|
||||
|
@ -29,6 +30,9 @@ class MediaPickerInputAudio implements MediaPickerInput {
|
|||
@override
|
||||
String label;
|
||||
|
||||
@override
|
||||
Widget icon;
|
||||
|
||||
@override
|
||||
Future<MediaResult> onPressed(BuildContext context) async {
|
||||
MediaResult audio = MediaResult();
|
||||
|
|
|
@ -16,6 +16,7 @@ import '../../flutter_media_picker.dart';
|
|||
class MediaPickerInputFile implements MediaPickerInput {
|
||||
MediaPickerInputFile({
|
||||
this.label = "File",
|
||||
this.icon = const Icon(Icons.file_copy),
|
||||
this.fileExtensions = const ['pdf', 'jpg', 'png'],
|
||||
this.checkPageSettings,
|
||||
this.onComplete,
|
||||
|
@ -28,6 +29,9 @@ class MediaPickerInputFile implements MediaPickerInput {
|
|||
@override
|
||||
String label;
|
||||
|
||||
@override
|
||||
Widget icon;
|
||||
|
||||
@override
|
||||
Future<MediaResult> onPressed(BuildContext context) async {
|
||||
var file = await pickFile?.call(fileExtensions);
|
||||
|
@ -64,7 +68,7 @@ class MediaPickerInputFile implements MediaPickerInput {
|
|||
case '.txt':
|
||||
return const DisplayText();
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Container();
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:flutter_media_picker/src/media_result.dart';
|
|||
class MediaPickerInputPhoto implements MediaPickerInput {
|
||||
MediaPickerInputPhoto({
|
||||
this.label = "Photo",
|
||||
this.icon = const Icon(Icons.image),
|
||||
this.checkPageSettings,
|
||||
this.onComplete,
|
||||
this.pickFile,
|
||||
|
@ -23,6 +24,9 @@ class MediaPickerInputPhoto implements MediaPickerInput {
|
|||
@override
|
||||
String label;
|
||||
|
||||
@override
|
||||
Widget icon;
|
||||
|
||||
@override
|
||||
Future<MediaResult> onPressed(BuildContext context) async {
|
||||
var image = await pickFile?.call();
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
class MediaPickerInputText implements MediaPickerInput {
|
||||
MediaPickerInputText({
|
||||
this.label = "Text",
|
||||
this.icon = const Icon(Icons.text_fields),
|
||||
this.checkPageSettings,
|
||||
this.onComplete,
|
||||
});
|
||||
|
@ -19,6 +20,9 @@ class MediaPickerInputText implements MediaPickerInput {
|
|||
@override
|
||||
String label;
|
||||
|
||||
@override
|
||||
Widget icon;
|
||||
|
||||
@override
|
||||
Future<MediaResult> onPressed(BuildContext context) async {
|
||||
return MediaResult();
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:flutter_media_picker/flutter_media_picker.dart';
|
|||
class MediaPickerInputVideo implements MediaPickerInput {
|
||||
MediaPickerInputVideo({
|
||||
this.label = "Video",
|
||||
this.icon = const Icon(Icons.video_camera_front),
|
||||
this.checkPageSettings,
|
||||
this.onComplete,
|
||||
this.pickFile,
|
||||
|
@ -23,6 +24,9 @@ class MediaPickerInputVideo implements MediaPickerInput {
|
|||
@override
|
||||
String label;
|
||||
|
||||
@override
|
||||
Widget icon;
|
||||
|
||||
@override
|
||||
Future<MediaResult> onPressed(BuildContext context) async {
|
||||
var image = await pickFile?.call();
|
||||
|
|
|
@ -104,14 +104,19 @@ class MediaPicker extends ConsumerWidget {
|
|||
const MediaPicker({
|
||||
this.mediaPickerInputs,
|
||||
this.header,
|
||||
this.iconButton,
|
||||
this.onComplete,
|
||||
this.mediaCheckPage,
|
||||
this.buttonType = ButtonType.text,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
final List<MediaPickerInput>? mediaPickerInputs;
|
||||
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 ButtonType buttonType;
|
||||
final Widget Function(
|
||||
Widget displayResult,
|
||||
Map<String, dynamic>? inputSettings,
|
||||
|
@ -136,40 +141,58 @@ class MediaPicker extends ConsumerWidget {
|
|||
|
||||
return Column(
|
||||
children: [
|
||||
for (final input in inputs) ...[
|
||||
const SizedBox(height: 2.5),
|
||||
header?.call(input.label, (BuildContext ct) async {
|
||||
await onPressedMediaType(ct, input);
|
||||
}) ??
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await onPressedMediaType(context, input);
|
||||
},
|
||||
child: Container(
|
||||
height: 55,
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Color(0xFF979797),
|
||||
width: 1,
|
||||
if (buttonType == ButtonType.text) ...[
|
||||
for (final input in inputs) ...[
|
||||
const SizedBox(height: 2.5),
|
||||
header?.call(input.label, (BuildContext ct) async {
|
||||
await onPressedMediaType(ct, input);
|
||||
}) ??
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await onPressedMediaType(context, input);
|
||||
},
|
||||
child: Container(
|
||||
height: 55,
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Color(0xFF979797),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Text(
|
||||
input.label,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Text(
|
||||
input.label,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2.5),
|
||||
],
|
||||
)
|
||||
],
|
||||
]
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue