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

  1. import 'package:flutter/material.dart';
  2. import 'package:image_picker/image_picker.dart';
  3. class FilePicker extends StatelessWidget {
  4. FilePicker({
  5. Key? key,
  6. this.cameraHandle,
  7. this.galleryHandleSingle,
  8. this.galleryHandleMultiple,
  9. this.fileHandle,
  10. }) : super(key: key);
  11. final Function()? cameraHandle;
  12. final Function()? galleryHandleSingle;
  13. final Function(List<XFile> images)? galleryHandleMultiple;
  14. final Function()? fileHandle;
  15. final ImagePicker _picker = ImagePicker();
  16. @override
  17. Widget build(BuildContext context) {
  18. return Padding(
  19. padding: const EdgeInsets.only(top: 10, bottom: 10, left: 5, right: 5),
  20. child: Row(
  21. mainAxisAlignment: MainAxisAlignment.center,
  22. children: [
  23. _filePickerSelection(
  24. hasHandle: cameraHandle != null,
  25. icon: Icons.camera_alt,
  26. onTap: () {
  27. },
  28. context: context,
  29. ),
  30. _filePickerSelection(
  31. hasHandle: galleryHandleSingle != null,
  32. icon: Icons.image,
  33. onTap: () async {
  34. final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
  35. print(image);
  36. },
  37. context: context,
  38. ),
  39. _filePickerSelection(
  40. hasHandle: galleryHandleMultiple != null,
  41. icon: Icons.image,
  42. onTap: () async {
  43. final List<XFile>? images = await _picker.pickMultiImage();
  44. if (images == null) {
  45. return;
  46. }
  47. galleryHandleMultiple!(images);
  48. },
  49. context: context,
  50. ),
  51. _filePickerSelection(
  52. hasHandle: fileHandle != null,
  53. icon: Icons.file_present_sharp,
  54. onTap: () {
  55. },
  56. context: context,
  57. ),
  58. ],
  59. )
  60. );
  61. }
  62. Widget _filePickerSelection({
  63. required bool hasHandle,
  64. required IconData icon,
  65. required Function() onTap,
  66. required BuildContext context
  67. }) {
  68. if (!hasHandle) {
  69. return const SizedBox.shrink();
  70. }
  71. return Padding(
  72. padding: const EdgeInsets.only(left: 5, right: 5),
  73. child: GestureDetector(
  74. onTap: onTap,
  75. child: Container(
  76. height: 75,
  77. width: 75,
  78. decoration: BoxDecoration(
  79. color: Theme.of(context).primaryColor,
  80. borderRadius: BorderRadius.circular(25),
  81. ),
  82. child: Icon(
  83. icon,
  84. size: 40,
  85. ),
  86. ),
  87. ),
  88. );
  89. }
  90. }