235 lines
8.4 KiB
Dart
235 lines
8.4 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/models/clients/memoryListResponse/MemoryListData.dart';
|
|
import 'package:ftc_mobile_app/models/profileData/user_data.dart';
|
|
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
|
import 'package:ftc_mobile_app/view/custom_widgets/custom_app_bar_with_action.dart';
|
|
import 'package:ftc_mobile_app/view/custom_widgets/my_network_image.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:video_thumbnail/video_thumbnail.dart';
|
|
import '../../../ftc_mobile_app.dart';
|
|
import 'addEditMemoryBox/add_edit_memory_box_screen.dart';
|
|
|
|
class PhotoGalleryScreen extends StatefulWidget {
|
|
final UserData userData;
|
|
|
|
const PhotoGalleryScreen({Key? key, required this.userData})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<PhotoGalleryScreen> createState() => _PhotoGalleryScreenState();
|
|
}
|
|
|
|
class _PhotoGalleryScreenState extends State<PhotoGalleryScreen> {
|
|
final controller = Get.put(PhotoGalleryScreenController());
|
|
|
|
@override
|
|
void initState() {
|
|
controller.serviceUserId = widget.userData.id!;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomScaffold(
|
|
backgroundColor: CustomAppColors.kPrimaryColor,
|
|
screenKey: controller.screenKey,
|
|
onScreenTap: controller.removeFocus,
|
|
// sideDrawer: const CustomDrawer(),
|
|
showAppBar: true,
|
|
appBar: _appBar(context),
|
|
body: SafeArea(child: Obx(() {
|
|
if (controller.memoryList.isEmpty) {
|
|
return FrequentFunctions.centerText(text: "No data found");
|
|
}
|
|
|
|
return listView(controller.memoryList());
|
|
})),
|
|
);
|
|
}
|
|
|
|
AppBar _appBar(BuildContext context) {
|
|
return CustomAppBarWithAction(
|
|
context,
|
|
titleText: 'Photo Gallery',
|
|
actionText: '+ Add New',
|
|
onActionTap: () async {
|
|
final result = await _gotoAddEditMemoryBoxScreen();
|
|
|
|
if (result == true) {
|
|
controller.getMemoryList();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
listView(List<MemoryListData> list) {
|
|
return ListView.separated(
|
|
itemCount: list.length,
|
|
padding: REdgeInsets.symmetric(horizontal: 16),
|
|
separatorBuilder: (_, index) => 12.verticalSpace,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return listItem(index: index, data: list[index]);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget listItem({required int index, required MemoryListData data}) {
|
|
return InkWell(
|
|
onTap: () {
|
|
_gotoAddEditMemoryBoxScreen(data, true);
|
|
},
|
|
child: Container(
|
|
height: 130.h,
|
|
clipBehavior: Clip.antiAlias,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color: CustomAppColors.kSecondaryColor),
|
|
borderRadius: 16.toRadius(),
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
flex: 4,
|
|
child: Container(
|
|
width: double.maxFinite,
|
|
height: double.maxFinite,
|
|
clipBehavior: Clip.antiAlias,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
borderRadius:
|
|
const BorderRadius.horizontal(left: Radius.circular(16)),
|
|
),
|
|
child: (data.filePath.isNullOrEmpty())
|
|
? const Center(
|
|
child: Icon(Icons.image_not_supported_outlined),
|
|
)
|
|
: (data.filePath!.isImageFileName)
|
|
? MyNetworkImage(
|
|
url: WebUrls.baseUrl + data.filePath!,
|
|
fit: BoxFit.cover,
|
|
errorWidget: const Icon(
|
|
Icons.image_not_supported_outlined,
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: FutureBuilder(
|
|
future: VideoThumbnail.thumbnailFile(
|
|
video: WebUrls.baseUrl + data.filePath!,
|
|
imageFormat: ImageFormat.WEBP,
|
|
maxHeight: 150,
|
|
quality: 75,
|
|
),
|
|
builder: (_, snap) {
|
|
if (snap.connectionState ==
|
|
ConnectionState.waiting) {
|
|
return Center(
|
|
child: SizedBox.square(
|
|
dimension: 32.r,
|
|
child: const CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
if (snap.connectionState ==
|
|
ConnectionState.done) {
|
|
if (snap.data != null) {
|
|
return Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: Image.file(
|
|
File(snap.data!),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
Center(
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
blurRadius: 2,
|
|
spreadRadius: 2,
|
|
color: Colors.black
|
|
.withOpacity(0.2)),
|
|
],
|
|
),
|
|
child: Icon(
|
|
Icons.play_circle_outline_rounded,
|
|
color: Colors.white,
|
|
size: 32.r,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
return FrequentFunctions.noWidget;
|
|
}),
|
|
),
|
|
),
|
|
12.horizontalSpace,
|
|
Expanded(
|
|
flex: 8,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
CustomTextWidget(
|
|
text: data.note ?? "",
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w400,
|
|
maxLines: 3,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
8.verticalSpace,
|
|
CustomTextWidget(
|
|
text: "Staff Member: ${data.addedBy?.name ?? ""}",
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w400,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
],
|
|
).addPaddingVertical(12),
|
|
),
|
|
// EditIcon(
|
|
// onTap: () async {
|
|
// final result = await _gotoAddEditMemoryBoxScreen(data);
|
|
//
|
|
// if (result == true) {
|
|
// controller.getMemoryList();
|
|
// }
|
|
// },
|
|
// ).addPaddingVertical(12),
|
|
// 12.horizontalSpace,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future _gotoAddEditMemoryBoxScreen([data, bool viewOnly = false]) async {
|
|
final res = await Navigator.pushNamed(
|
|
context,
|
|
CustomRouteNames.kAddEditMemoryBoxScreen,
|
|
arguments: AddEditMemoryBoxScreenArgs(
|
|
userData: widget.userData,
|
|
data: data,
|
|
viewOnly: viewOnly,
|
|
),
|
|
);
|
|
|
|
if (res == true) {
|
|
controller.getMemoryList();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|