Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.5 KiB

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class FilePicker extends StatelessWidget {
FilePicker({
Key? key,
this.cameraHandle,
this.galleryHandleSingle,
this.galleryHandleMultiple,
this.fileHandle,
}) : super(key: key);
final Function()? cameraHandle;
final Function()? galleryHandleSingle;
final Function(List<XFile> images)? galleryHandleMultiple;
final Function()? fileHandle;
final ImagePicker _picker = ImagePicker();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10, left: 5, right: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_filePickerSelection(
hasHandle: cameraHandle != null,
icon: Icons.camera_alt,
onTap: () {
},
context: context,
),
_filePickerSelection(
hasHandle: galleryHandleSingle != null,
icon: Icons.image,
onTap: () async {
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
print(image);
},
context: context,
),
_filePickerSelection(
hasHandle: galleryHandleMultiple != null,
icon: Icons.image,
onTap: () async {
final List<XFile>? images = await _picker.pickMultiImage();
if (images == null) {
return;
}
galleryHandleMultiple!(images);
},
context: context,
),
_filePickerSelection(
hasHandle: fileHandle != null,
icon: Icons.file_present_sharp,
onTap: () {
},
context: context,
),
],
)
);
}
Widget _filePickerSelection({
required bool hasHandle,
required IconData icon,
required Function() onTap,
required BuildContext context
}) {
if (!hasHandle) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.only(left: 5, right: 5),
child: GestureDetector(
onTap: onTap,
child: Container(
height: 75,
width: 75,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(25),
),
child: Icon(
icon,
size: 40,
),
),
),
);
}
}