2022-12-29 08:45:28 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2023-07-15 16:44:35 +03:00
|
|
|
|
2022-12-29 08:45:28 +03:00
|
|
|
import '../../controller/gallery_controller.dart';
|
|
|
|
import '../../models/config.dart';
|
2022-12-31 16:43:05 +03:00
|
|
|
import '../../models/gallery_album.dart';
|
2022-12-29 08:45:28 +03:00
|
|
|
import '../../models/media_file.dart';
|
|
|
|
import '../album_categories_view/album_categories_view.dart';
|
|
|
|
import '../album_view/album_medias_view.dart';
|
2023-07-15 16:44:35 +03:00
|
|
|
import '../album_view/album_page.dart';
|
2023-01-20 09:58:21 +03:00
|
|
|
import 'permission_denied_view.dart';
|
2022-12-29 08:45:28 +03:00
|
|
|
import 'picker_appbar.dart';
|
|
|
|
import 'reload_gallery.dart';
|
|
|
|
|
|
|
|
class GalleryPickerView extends StatefulWidget {
|
2022-12-30 05:18:18 +03:00
|
|
|
final Config? config;
|
2022-12-31 16:43:05 +03:00
|
|
|
final Function(List<MediaFile> selectedMedia) onSelect;
|
2022-12-30 05:18:18 +03:00
|
|
|
final Widget Function(String tag, MediaFile media, BuildContext context)?
|
2022-12-29 08:45:28 +03:00
|
|
|
heroBuilder;
|
2022-12-31 16:43:05 +03:00
|
|
|
final Widget Function(List<MediaFile> media, BuildContext context)?
|
|
|
|
multipleMediaBuilder;
|
2022-12-30 05:18:18 +03:00
|
|
|
final bool startWithRecent;
|
2023-01-20 09:58:21 +03:00
|
|
|
final bool isBottomSheet;
|
2024-02-24 22:33:52 +03:00
|
|
|
final Locale? locale;
|
2022-12-31 16:43:05 +03:00
|
|
|
final List<MediaFile>? initSelectedMedia;
|
|
|
|
final List<MediaFile>? extraRecentMedia;
|
2022-12-30 05:18:18 +03:00
|
|
|
final bool singleMedia;
|
|
|
|
const GalleryPickerView(
|
2022-12-29 08:45:28 +03:00
|
|
|
{super.key,
|
|
|
|
this.config,
|
|
|
|
required this.onSelect,
|
2022-12-31 16:43:05 +03:00
|
|
|
this.initSelectedMedia,
|
|
|
|
this.extraRecentMedia,
|
2022-12-30 05:18:18 +03:00
|
|
|
this.singleMedia = false,
|
2023-01-20 09:58:21 +03:00
|
|
|
this.isBottomSheet = false,
|
2022-12-29 08:45:28 +03:00
|
|
|
this.heroBuilder,
|
2024-02-24 22:33:52 +03:00
|
|
|
this.locale,
|
2022-12-31 16:43:05 +03:00
|
|
|
this.multipleMediaBuilder,
|
2022-12-29 08:45:28 +03:00
|
|
|
this.startWithRecent = false});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<GalleryPickerView> createState() => _GalleryPickerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GalleryPickerState extends State<GalleryPickerView> {
|
|
|
|
late PhoneGalleryController galleryController;
|
|
|
|
bool noPhotoSeleceted = true;
|
|
|
|
late Config config;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
if (GetInstance().isRegistered<PhoneGalleryController>()) {
|
|
|
|
galleryController = Get.find<PhoneGalleryController>();
|
2023-01-20 09:58:21 +03:00
|
|
|
if (galleryController.configurationCompleted) {
|
|
|
|
galleryController.updateConfig(widget.config);
|
|
|
|
} else {
|
|
|
|
galleryController.configuration(widget.config,
|
|
|
|
onSelect: widget.onSelect,
|
|
|
|
startWithRecent: widget.startWithRecent,
|
|
|
|
heroBuilder: widget.heroBuilder,
|
|
|
|
multipleMediasBuilder: widget.multipleMediaBuilder,
|
|
|
|
initSelectedMedias: widget.initSelectedMedia,
|
|
|
|
extraRecentMedia: widget.extraRecentMedia,
|
|
|
|
isRecent: widget.startWithRecent);
|
|
|
|
}
|
2022-12-29 08:45:28 +03:00
|
|
|
} else {
|
2023-01-20 09:58:21 +03:00
|
|
|
galleryController = Get.put(PhoneGalleryController());
|
|
|
|
galleryController.configuration(widget.config,
|
2022-12-29 08:45:28 +03:00
|
|
|
onSelect: widget.onSelect,
|
2023-01-20 09:58:21 +03:00
|
|
|
startWithRecent: widget.startWithRecent,
|
2022-12-29 08:45:28 +03:00
|
|
|
heroBuilder: widget.heroBuilder,
|
2022-12-31 16:43:05 +03:00
|
|
|
multipleMediasBuilder: widget.multipleMediaBuilder,
|
|
|
|
initSelectedMedias: widget.initSelectedMedia,
|
|
|
|
extraRecentMedia: widget.extraRecentMedia,
|
2023-01-20 09:58:21 +03:00
|
|
|
isRecent: widget.startWithRecent);
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
2023-01-20 09:58:21 +03:00
|
|
|
config = galleryController.config;
|
2022-12-29 08:45:28 +03:00
|
|
|
if (!galleryController.isInitialized) {
|
2024-02-24 22:33:52 +03:00
|
|
|
galleryController.initializeAlbums(locale: widget.locale);
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2022-12-31 16:43:05 +03:00
|
|
|
GalleryAlbum? selectedAlbum;
|
2023-01-20 09:58:21 +03:00
|
|
|
|
2022-12-29 08:45:28 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
|
|
return GetBuilder<PhoneGalleryController>(builder: (controller) {
|
|
|
|
return GetInstance().isRegistered<PhoneGalleryController>()
|
2023-01-21 03:43:51 +03:00
|
|
|
? controller.permissionGranted != false
|
2023-01-20 09:58:21 +03:00
|
|
|
? PageView(
|
|
|
|
controller: controller.pageController,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
children: [
|
2024-02-24 22:33:52 +03:00
|
|
|
PopScope(
|
|
|
|
canPop: true,
|
|
|
|
onPopInvoked: (value) {
|
|
|
|
if (!widget.isBottomSheet) {
|
|
|
|
controller.disposeController();
|
|
|
|
}
|
|
|
|
},
|
2023-01-21 03:43:51 +03:00
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: config.backgroundColor,
|
|
|
|
appBar: PickerAppBar(
|
|
|
|
controller: controller,
|
|
|
|
isBottomSheet: widget.isBottomSheet,
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: width,
|
|
|
|
height: 48,
|
|
|
|
color: config.appbarColor,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.spaceAround,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: controller.isRecent
|
|
|
|
? BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: config.underlineColor,
|
|
|
|
width: 3.0,
|
|
|
|
),
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
height: 48,
|
|
|
|
width: width / 2,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
controller.pickerPageController
|
|
|
|
.animateToPage(0,
|
|
|
|
duration: const Duration(
|
|
|
|
milliseconds: 50),
|
|
|
|
curve: Curves.easeIn);
|
|
|
|
setState(() {
|
|
|
|
controller.isRecent = true;
|
|
|
|
controller
|
|
|
|
.switchPickerMode(false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text(config.recents,
|
|
|
|
style: controller.isRecent
|
|
|
|
? config.selectedMenuStyle
|
|
|
|
: config
|
|
|
|
.unselectedMenuStyle)),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
decoration: !controller.isRecent
|
|
|
|
? BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: config.underlineColor,
|
|
|
|
width: 3.0,
|
|
|
|
),
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
height: 48,
|
|
|
|
width: width / 2,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
controller.pickerPageController
|
|
|
|
.animateToPage(1,
|
|
|
|
duration: const Duration(
|
|
|
|
milliseconds: 50),
|
|
|
|
curve: Curves.easeIn);
|
|
|
|
controller.isRecent = false;
|
|
|
|
controller.switchPickerMode(false);
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
config.gallery,
|
|
|
|
style: controller.isRecent
|
|
|
|
? config.unselectedMenuStyle
|
|
|
|
: config.selectedMenuStyle,
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
],
|
2023-01-20 09:58:21 +03:00
|
|
|
),
|
2023-01-21 03:43:51 +03:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: PageView(
|
|
|
|
controller: controller.pickerPageController,
|
|
|
|
onPageChanged: (value) {
|
|
|
|
if (value == 0) {
|
|
|
|
controller.isRecent = true;
|
|
|
|
controller.switchPickerMode(false);
|
|
|
|
} else {
|
2023-01-20 09:58:21 +03:00
|
|
|
controller.isRecent = false;
|
|
|
|
controller.switchPickerMode(false);
|
2023-01-21 03:43:51 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
children: [
|
|
|
|
controller.isInitialized &&
|
|
|
|
controller.recent != null
|
|
|
|
? AlbumMediasView(
|
|
|
|
galleryAlbum: controller.recent!,
|
|
|
|
controller: controller,
|
|
|
|
isBottomSheet:
|
|
|
|
widget.isBottomSheet,
|
|
|
|
singleMedia: widget.singleMedia)
|
|
|
|
: const Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: Colors.grey,
|
|
|
|
)),
|
|
|
|
AlbumCategoriesView(
|
|
|
|
controller: controller,
|
|
|
|
isBottomSheet: widget.isBottomSheet,
|
|
|
|
singleMedia: widget.singleMedia,
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
],
|
2023-01-20 09:58:21 +03:00
|
|
|
),
|
2024-02-24 22:33:52 +03:00
|
|
|
)),
|
2023-01-20 09:58:21 +03:00
|
|
|
AlbumPage(
|
|
|
|
album: controller.selectedAlbum,
|
|
|
|
controller: controller,
|
|
|
|
singleMedia: widget.singleMedia,
|
|
|
|
isBottomSheet: widget.isBottomSheet)
|
|
|
|
],
|
2022-12-29 08:45:28 +03:00
|
|
|
)
|
2023-01-21 03:43:51 +03:00
|
|
|
: Material(
|
|
|
|
child: controller.config.permissionDeniedPage ??
|
|
|
|
PermissionDeniedView(
|
|
|
|
config: controller.config,
|
|
|
|
),
|
|
|
|
)
|
2022-12-29 08:45:28 +03:00
|
|
|
: ReloadGallery(
|
|
|
|
config,
|
|
|
|
onpressed: () async {
|
2023-01-20 09:58:21 +03:00
|
|
|
galleryController = Get.put(PhoneGalleryController());
|
|
|
|
galleryController.configuration(widget.config,
|
2022-12-29 08:45:28 +03:00
|
|
|
onSelect: widget.onSelect,
|
2023-01-20 09:58:21 +03:00
|
|
|
startWithRecent: widget.startWithRecent,
|
2022-12-29 08:45:28 +03:00
|
|
|
heroBuilder: widget.heroBuilder,
|
2023-01-20 09:58:21 +03:00
|
|
|
multipleMediasBuilder: widget.multipleMediaBuilder,
|
2022-12-31 16:43:05 +03:00
|
|
|
initSelectedMedias: widget.initSelectedMedia,
|
|
|
|
extraRecentMedia: widget.extraRecentMedia,
|
2023-01-20 09:58:21 +03:00
|
|
|
isRecent: widget.startWithRecent);
|
|
|
|
if (!controller.isInitialized) {
|
2024-02-24 22:33:52 +03:00
|
|
|
await controller.initializeAlbums(locale: widget.locale);
|
2022-12-29 08:45:28 +03:00
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|