Skip to content

Commit ba5741b

Browse files
committed
Perbaikan agar user yang terpilih langsung muncul ketika buka pilihan user di halaman report_screenshot_page.dart
Awalnya menggunakan widget dialog untuk menampilkan pilihan user-nya. Ternyata, dari widget tersebut belum tersedia fitur untuk auto scroll atau keep position scroll-nya berdasarkan item yang terpilih. Jadi, solusinya adalah ubah widget-nya dari dialog menjadi dropdown.
1 parent 1888e8c commit ba5741b

File tree

1 file changed

+74
-107
lines changed

1 file changed

+74
-107
lines changed

lib/feature/presentation/page/report_screenshot/report_screenshot_page.dart

Lines changed: 74 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class _ReportScreenshotPageState extends State<ReportScreenshotPage> {
3939
final listUserProfile = <UserProfileResponse>[];
4040
final controllerFilterDate = TextEditingController();
4141
final controllerFilterUser = TextEditingController();
42-
final focusNode = FocusNode();
4342

4443
var userId = '';
4544
var name = '';
@@ -87,61 +86,61 @@ class _ReportScreenshotPageState extends State<ReportScreenshotPage> {
8786

8887
@override
8988
Widget build(BuildContext context) {
90-
return Scaffold(
91-
appBar: AppBar(
92-
title: Focus(
93-
focusNode: focusNode,
94-
child: Text(
89+
return GestureDetector(
90+
onTap: () => widgetHelper.unfocus(context),
91+
child: Scaffold(
92+
appBar: AppBar(
93+
title: Text(
9594
'report_screenshot'.tr(),
9695
),
96+
centerTitle: false,
9797
),
98-
centerTitle: false,
99-
),
100-
body: MultiBlocProvider(
101-
providers: [
102-
BlocProvider<MemberBloc>(
103-
create: (context) => memberBloc,
104-
),
105-
BlocProvider<ReportScreenshotBloc>(
106-
create: (context) => reportScreenshotBloc,
107-
),
108-
],
109-
child: MultiBlocListener(
110-
listeners: [
111-
BlocListener<MemberBloc, MemberState>(
112-
listener: (context, state) {
113-
if (state is FailureMemberState) {
114-
final errorMessage = state.errorMessage.convertErrorMessageToHumanMessage();
115-
if (errorMessage.contains('401')) {
116-
widgetHelper.showDialog401(context);
117-
return;
118-
}
119-
} else if (state is SuccessLoadListMemberState) {
120-
listUserProfile.clear();
121-
listUserProfile.addAll(state.response.data ?? []);
122-
isPreparingDataSuccess = true;
123-
setState(() {});
124-
}
125-
},
98+
body: MultiBlocProvider(
99+
providers: [
100+
BlocProvider<MemberBloc>(
101+
create: (context) => memberBloc,
126102
),
127-
BlocListener<ReportScreenshotBloc, ReportScreenshotState>(
128-
listener: (context, state) {
129-
isLoading = state is LoadingCenterReportScreenshotState;
130-
if (state is FailureReportScreenshotState) {
131-
final errorMessage = state.errorMessage.convertErrorMessageToHumanMessage();
132-
if (errorMessage.contains('401')) {
133-
widgetHelper.showDialog401(context);
134-
return;
135-
}
136-
}
137-
},
103+
BlocProvider<ReportScreenshotBloc>(
104+
create: (context) => reportScreenshotBloc,
138105
),
139106
],
140-
child: Stack(
141-
children: [
142-
buildWidgetBody(),
143-
buildWidgetLoadingPreparingData(),
107+
child: MultiBlocListener(
108+
listeners: [
109+
BlocListener<MemberBloc, MemberState>(
110+
listener: (context, state) {
111+
if (state is FailureMemberState) {
112+
final errorMessage = state.errorMessage.convertErrorMessageToHumanMessage();
113+
if (errorMessage.contains('401')) {
114+
widgetHelper.showDialog401(context);
115+
return;
116+
}
117+
} else if (state is SuccessLoadListMemberState) {
118+
listUserProfile.clear();
119+
listUserProfile.addAll(state.response.data ?? []);
120+
isPreparingDataSuccess = true;
121+
setState(() {});
122+
}
123+
},
124+
),
125+
BlocListener<ReportScreenshotBloc, ReportScreenshotState>(
126+
listener: (context, state) {
127+
isLoading = state is LoadingCenterReportScreenshotState;
128+
if (state is FailureReportScreenshotState) {
129+
final errorMessage = state.errorMessage.convertErrorMessageToHumanMessage();
130+
if (errorMessage.contains('401')) {
131+
widgetHelper.showDialog401(context);
132+
return;
133+
}
134+
}
135+
},
136+
),
144137
],
138+
child: Stack(
139+
children: [
140+
buildWidgetBody(),
141+
buildWidgetLoadingPreparingData(),
142+
],
143+
),
145144
),
146145
),
147146
),
@@ -262,6 +261,8 @@ class _ReportScreenshotPageState extends State<ReportScreenshotPage> {
262261
Icons.calendar_month,
263262
color: Theme.of(context).colorScheme.inverseSurface,
264263
),
264+
filled: true,
265+
fillColor: Colors.transparent,
265266
),
266267
mouseCursor: MaterialStateMouseCursor.clickable,
267268
readOnly: true,
@@ -293,69 +294,35 @@ class _ReportScreenshotPageState extends State<ReportScreenshotPage> {
293294
final foregroundColor = isEnabled
294295
? Theme.of(context).colorScheme.inverseSurface
295296
: Theme.of(context).colorScheme.inverseSurface.withOpacity(.3);
296-
return TextField(
297-
controller: controllerFilterUser,
298-
decoration: widgetHelper.setDefaultTextFieldDecoration(
299-
suffixIcon: FaIcon(
297+
298+
return SizedBox(
299+
height: 42,
300+
child: DropdownButtonFormField(
301+
value: selectedUser,
302+
items: listUserProfile.map((e) {
303+
return DropdownMenuItem(
304+
value: e,
305+
child: Text(e.name ?? '-'),
306+
);
307+
}).toList(),
308+
onChanged: (newValue) {
309+
setState(() {
310+
selectedUser = newValue;
311+
});
312+
},
313+
isExpanded: true,
314+
decoration: widgetHelper.setDefaultTextFieldDecoration(
315+
filled: true,
316+
fillColor: Colors.transparent,
317+
),
318+
icon: FaIcon(
300319
FontAwesomeIcons.userLarge,
301320
size: 14,
302321
color: foregroundColor,
303322
),
304-
suffixIconConstraints: const BoxConstraints(
305-
minWidth: 28,
306-
maxWidth: 28,
307-
),
323+
padding: EdgeInsets.zero,
324+
style: Theme.of(context).textTheme.bodyMedium,
308325
),
309-
mouseCursor: MaterialStateMouseCursor.clickable,
310-
readOnly: true,
311-
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
312-
color: foregroundColor,
313-
),
314-
enabled: isEnabled,
315-
onTap: !isEnabled
316-
? null
317-
: () async {
318-
final selectedUserTemp = await showDialog<UserProfileResponse?>(
319-
context: context,
320-
builder: (context) {
321-
return SimpleDialog(
322-
titlePadding: EdgeInsets.zero,
323-
contentPadding: const EdgeInsets.symmetric(vertical: 16),
324-
children: listUserProfile.map((element) {
325-
return InkWell(
326-
onTap: () => Navigator.pop(context, element),
327-
child: Padding(
328-
padding: const EdgeInsets.symmetric(
329-
vertical: 16.0,
330-
horizontal: 16.0,
331-
),
332-
child: Row(
333-
children: [
334-
Expanded(
335-
child: Text(element.name ?? '-'),
336-
),
337-
const SizedBox(width: 16),
338-
element == selectedUser
339-
? Icon(
340-
Icons.check_circle,
341-
color: Theme.of(context).colorScheme.primary,
342-
)
343-
: Container(),
344-
],
345-
),
346-
),
347-
);
348-
}).toList(),
349-
);
350-
},
351-
);
352-
if (selectedUserTemp != null) {
353-
selectedUser = selectedUserTemp;
354-
setFilterUser();
355-
setState(() {});
356-
}
357-
},
358-
maxLines: 1,
359326
);
360327
}
361328

0 commit comments

Comments
 (0)