Skip to content

Commit e7af2bf

Browse files
committed
feat: Khusus super admin, tambahkan fitur preview original screenshot jika pengaturan blur-nya hidup
Jika pengaturan blur-nya mati maka, fitur preview original screenshot ini tidak akan tersedia. Dan fitur ini hanya dibuat khusus untuk super admin.
1 parent 21f7972 commit e7af2bf

File tree

1 file changed

+79
-29
lines changed

1 file changed

+79
-29
lines changed

lib/feature/presentation/page/photo_view/photo_view_page.dart

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'dart:io';
22

3+
import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart';
4+
import 'package:dipantau_desktop_client/core/util/enum/user_role.dart';
35
import 'package:dipantau_desktop_client/core/util/images.dart';
6+
import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart';
47
import 'package:dipantau_desktop_client/feature/data/model/track_user/track_user_response.dart';
58
import 'package:easy_localization/easy_localization.dart';
69
import 'package:flutter/material.dart';
@@ -11,7 +14,6 @@ class PhotoViewPage extends StatefulWidget {
1114
static const routePath = '/photo-view';
1215
static const routeName = 'photo-view';
1316
static const parameterListPhotos = 'list_photos';
14-
static const parameterListPhotosBlur = 'list_photos_blur';
1517

1618
final List<ItemFileTrackUserResponse>? listPhotos;
1719

@@ -29,12 +31,19 @@ class _PhotoViewPageState extends State<PhotoViewPage> {
2931
final listPhotos = <ItemFileTrackUserResponse>[];
3032

3133
var indexSelectedPhoto = 0;
34+
UserRole? userRole;
35+
var isBlurSettingEnabled = false;
36+
var isBlurPreviewEnabled = false;
3237

3338
@override
3439
void initState() {
40+
final strUserRole = sharedPreferencesManager.getString(SharedPreferencesManager.keyUserRole) ?? '';
41+
userRole = strUserRole.fromStringUserRole;
3542
if (widget.listPhotos != null) {
3643
listPhotos.addAll(widget.listPhotos ?? []);
3744
}
45+
isBlurSettingEnabled = listPhotos.where((element) => (element.urlBlur ?? '').isNotEmpty).isNotEmpty;
46+
isBlurPreviewEnabled = isBlurSettingEnabled;
3847
super.initState();
3948
}
4049

@@ -50,8 +59,10 @@ class _PhotoViewPageState extends State<PhotoViewPage> {
5059
pageController: pageController,
5160
scrollPhysics: const BouncingScrollPhysics(),
5261
builder: (BuildContext context, int index) {
53-
var photo = listPhotos[index].urlBlur ?? '';
54-
if (photo.isEmpty) {
62+
var photo = '';
63+
if (isBlurPreviewEnabled) {
64+
photo = listPhotos[index].urlBlur ?? '';
65+
} else {
5566
photo = listPhotos[index].url ?? '';
5667
}
5768
return photo.startsWith('http')
@@ -86,29 +97,8 @@ class _PhotoViewPageState extends State<PhotoViewPage> {
8697
setState(() => indexSelectedPhoto = index);
8798
},
8899
),
89-
Align(
90-
alignment: Alignment.topLeft,
91-
child: Container(
92-
decoration: BoxDecoration(
93-
shape: BoxShape.circle,
94-
color: Colors.black.withOpacity(.5),
95-
),
96-
margin: const EdgeInsets.only(
97-
left: 8,
98-
top: 8,
99-
),
100-
child: IconButton(
101-
onPressed: () {
102-
Navigator.pop(context);
103-
},
104-
icon: const Icon(
105-
Icons.clear,
106-
color: Colors.white,
107-
),
108-
padding: const EdgeInsets.all(8),
109-
),
110-
),
111-
),
100+
buildWidgetIconClose(),
101+
buildWidgetIconPreviewSetting(),
112102
Align(
113103
alignment: Alignment.bottomCenter,
114104
child: buildWidgetSliderPreviewPhoto(),
@@ -117,6 +107,64 @@ class _PhotoViewPageState extends State<PhotoViewPage> {
117107
);
118108
}
119109

110+
Widget buildWidgetIconPreviewSetting() {
111+
if (!isBlurSettingEnabled || (userRole != UserRole.superAdmin)) {
112+
return Container();
113+
}
114+
115+
return Align(
116+
alignment: Alignment.topRight,
117+
child: Container(
118+
decoration: BoxDecoration(
119+
shape: BoxShape.circle,
120+
color: Colors.black.withOpacity(.5),
121+
),
122+
margin: const EdgeInsets.only(
123+
right: 8,
124+
top: 8,
125+
),
126+
child: IconButton(
127+
onPressed: () {
128+
setState(() {
129+
isBlurPreviewEnabled = !isBlurPreviewEnabled;
130+
});
131+
},
132+
icon: Icon(
133+
isBlurPreviewEnabled ? Icons.visibility_off : Icons.visibility,
134+
color: Colors.white,
135+
),
136+
padding: const EdgeInsets.all(8),
137+
),
138+
),
139+
);
140+
}
141+
142+
Widget buildWidgetIconClose() {
143+
return Align(
144+
alignment: Alignment.topLeft,
145+
child: Container(
146+
decoration: BoxDecoration(
147+
shape: BoxShape.circle,
148+
color: Colors.black.withOpacity(.5),
149+
),
150+
margin: const EdgeInsets.only(
151+
left: 8,
152+
top: 8,
153+
),
154+
child: IconButton(
155+
onPressed: () {
156+
Navigator.pop(context);
157+
},
158+
icon: const Icon(
159+
Icons.clear,
160+
color: Colors.white,
161+
),
162+
padding: const EdgeInsets.all(8),
163+
),
164+
),
165+
);
166+
}
167+
120168
Widget buildWidgetSliderPreviewPhoto() {
121169
if (listPhotos.length == 1) {
122170
return Container();
@@ -139,9 +187,11 @@ class _PhotoViewPageState extends State<PhotoViewPage> {
139187
if (elementId != null || selectedId != null) {
140188
isSelected = elementId == selectedId;
141189
}
142-
var photo = element.urlBlur ?? '';
143-
if (photo.isEmpty) {
144-
photo = element.url ?? '';
190+
var photo = '';
191+
if (isBlurPreviewEnabled) {
192+
photo = listPhotos[index].urlBlur ?? '';
193+
} else {
194+
photo = listPhotos[index].url ?? '';
145195
}
146196

147197
final widgetImage = SizedBox(

0 commit comments

Comments
 (0)