Fakultas Ilmu Komputer UI

Commit fb63469f authored by Ardian Ghifari's avatar Ardian Ghifari
Browse files

[GREEN] Add shimmer loading effect to pencarian.dart

parent 45c52b4e
......@@ -8,6 +8,7 @@ import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/page/filter_fasilitas/fasilitas.dart';
import 'package:shimmer/shimmer.dart';
/// Create Pencarian page widget with a state
class Pencarian extends StatefulWidget {
......@@ -36,7 +37,22 @@ class PencarianState extends State<Pencarian> {
/// BLoC for pencarian
LokasiResponseBloc bloc = LokasiResponseBloc();
final mockLokasi = [
Lokasi.fromJson({
'id': 3,
'name': 'Coolidge',
'latitude': -23.7169139,
'longitude': -46.8498038,
'alamat': '74809 Hooker Drive',
'image': 'static/img/2669211407.jpg',
'telepon': '+55 956 836 5799',
'counter': 69,
})
];
bool _enabled = true;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
......@@ -61,7 +77,7 @@ class PencarianState extends State<Pencarian> {
bloc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -131,13 +147,11 @@ class PencarianState extends State<Pencarian> {
if (snapshot.hasData) {
switch (snapshot.data.status) {
case Status.loading:
return const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(greenPrimary),
),
);
_enabled = true;
_buildMockHistoryWidget();
break;
case Status.completed:
_enabled = false;
final recentSearch = snapshot.data.data;
Widget displayWidget;
if (recentSearch.listLokasi.isEmpty) {
......@@ -150,6 +164,7 @@ class PencarianState extends State<Pencarian> {
return displayWidget;
break;
case Status.error:
_enabled = false;
return Center(
child: Text('${snapshot.data.status}'),
);
......@@ -174,14 +189,11 @@ class PencarianState extends State<Pencarian> {
if (snapshot.hasData) {
switch (snapshot.data.status) {
case Status.loading:
return const Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(greenPrimary),
),
);
_enabled = true;
_buildMockLokasiWidget();
break;
case Status.completed:
_enabled = false;
places = snapshot.data.data.listLokasi;
return snapshot.data.data.listLokasi.isEmpty
? Center(
......@@ -197,9 +209,9 @@ class PencarianState extends State<Pencarian> {
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
greenPrimary)
),
backgroundColor:
MaterialStateProperty.all(
greenPrimary)),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
......@@ -216,6 +228,7 @@ class PencarianState extends State<Pencarian> {
: makeLokasiWidget(snapshot.data.data.listLokasi);
break;
case Status.error:
_enabled = false;
return Center(
child: Text(snapshot.data.data.toString()),
);
......@@ -391,4 +404,22 @@ class PencarianState extends State<Pencarian> {
);
});
}
Widget _buildMockHistoryWidget() {
return Container(
child: Shimmer.fromColors(
baseColor: Colors.grey[300],
highlightColor: Colors.grey[100],
enabled: _enabled,
child: makeHistoryWidget(mockLokasi)));
}
Widget _buildMockLokasiWidget() {
return Container(
child: Shimmer.fromColors(
baseColor: Colors.grey[300],
highlightColor: Colors.grey[100],
enabled: _enabled,
child: makeLokasiWidget(mockLokasi)));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment