Fakultas Ilmu Komputer UI

fasilitas.dart 22.3 KB
Newer Older
1
import 'package:bisaGo/bloc/kegiatan_bloc.dart';
2
import 'package:bisaGo/bloc/lokasi_response_bloc.dart';
3
import 'package:bisaGo/component/image_holder.dart';
4
import 'package:bisaGo/model/kegiatan.dart';
Fakhira Devina's avatar
Fakhira Devina committed
5
import 'package:bisaGo/model/lokasi.dart';
6
import 'package:bisaGo/page/filter_fasilitas/add_kegiatan.dart';
7
import 'package:flutter/material.dart';
8
import 'package:bisaGo/bloc/komentar_bloc.dart';
9
10
11
12
import 'package:bisaGo/component/bisago_appbar.dart';
import 'package:bisaGo/component/bisago_drawer.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/network/data/network_model.dart';
13
import 'package:bisaGo/page/add_informasi/add_informasi.dart';
14
15
16
import 'package:bisaGo/page/filter_fasilitas/komentar.dart';
import 'package:bisaGo/model/komentar.dart';
import 'package:bisaGo/page/login/login.dart';
Usman Sidiq's avatar
Usman Sidiq committed
17
import 'package:shared_preferences/shared_preferences.dart';
18

19
20
import 'kegiatan.dart';

21
class Fasilitas extends StatefulWidget {
Fakhira Devina's avatar
Fakhira Devina committed
22
  final Lokasi lokasi;
23
  final KegiatanModel kegiatan;
24
  final KomentarModel komentar;
Yoga Pratama's avatar
Yoga Pratama committed
25
26
  const Fasilitas(
      {@required this.lokasi, this.kegiatan, this.komentar, Key key})
27
      : super(key: key);
28
29
30
31
32
  @override
  _FasilitasState createState() => _FasilitasState();
}

class _FasilitasState extends State<Fasilitas> {
33
34
35
36
37
38
39
  var kursiRodaVal = true;
  var liftVal = true;
  var toiletDisabilitasVal = true;
  var tempatIbadahVal = true;
  var bidangMiringVal = true;
  var parkirUmumVal = true;
  var parkirDisabilitasVal = true;
40
41
42
43
44
45
  var guidingBlockVal = true;
  var temanDisabilitasVal = true;
  var juruIsyaratVal = true;
  var tongkatVal = true;
  var kursiDisabilitasVal = true;
  var runningTextVal = true;
46
  var sortKomentar = -1;
Fakhira Devina's avatar
Fakhira Devina committed
47
  var showUrutan = true;
48
  List<KegiatanModel> allKegiatanFromApi;
49
  List<KomentarModel> allKomentarFromApi;
50
51
  KegiatanBloc _kegiatanBloc;
  KomentarBloc _komentarBloc;
52
  LokasiResponseBloc _lokasiBloc;
53
54
55

  @override
  void initState() {
56
    allKegiatanFromApi = [];
57
    allKomentarFromApi = [];
58
59
    _kegiatanBloc = KegiatanBloc(widget.lokasi.placeId);
    _komentarBloc = KomentarBloc(widget.lokasi.placeId);
60
    _lokasiBloc = LokasiResponseBloc();
61
    _postSearchHistory();
62
63
    super.initState();
  }
Fakhira Devina's avatar
Fakhira Devina committed
64

65
66
  @override
  Widget build(BuildContext context) {
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: const BisaGoAppBar(
          key: Key('Scaffold Text Field'),
        ),
        drawer: BisaGoDrawer(),
        body: NestedScrollView(
          scrollDirection: Axis.vertical,
          headerSliverBuilder: (context, innerBoxIsScrolled) => [
            SliverToBoxAdapter(
              child: Column(
                children: <Widget>[
                  // Render location data
                  Container(
Yoga Pratama's avatar
Yoga Pratama committed
82
83
84
                      margin: const EdgeInsets.all(doubleSpace),
                      child: SingleChildScrollView(
                        child: Column(
85
86
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
Yoga Pratama's avatar
Yoga Pratama committed
87
88
89
90
91
                              SizedBox(
                                height: 150,
                                child: ImageHolder(
                                  url: widget.lokasi.image ?? '',
                                  fasilitas: null,
92
93
                                ),
                              ),
Yoga Pratama's avatar
Yoga Pratama committed
94
                              Column(
95
96
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
Yoga Pratama's avatar
Yoga Pratama committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
                                  Text(
                                    widget.lokasi.name ?? 'INVALID',
                                    style: const TextStyle(
                                      fontSize: 25,
                                      fontWeight: FontWeight.w800,
                                      color: Colors.black,
                                      fontFamily: 'Muli',
                                    ),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(
                                      top: regularSpace,
                                      bottom: regularSpace,
                                      left: smallSpace,
                                    ),
                                    child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        const Icon(Icons.place,
                                            color: Colors.black, size: 20),
                                        Flexible(
                                            key: const Key('Alamat'),
                                            child: Text(
                                              widget.lokasi.alamat ??
                                                  'LOCATION INVALID',
                                              softWrap: true,
                                              textAlign: TextAlign.left,
                                              style: const TextStyle(
                                                fontSize: 15,
                                                color: Colors.black,
                                                fontFamily: 'Muli',
                                              ),
                                            ))
                                      ],
                                    ),
133
                                  ),
Yoga Pratama's avatar
Yoga Pratama committed
134
135
136
137
138
139
                                  Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: <Widget>[
                                      const Icon(
                                        Icons.local_phone,
140
                                        color: Colors.black,
Yoga Pratama's avatar
Yoga Pratama committed
141
                                        size: 20,
142
                                      ),
Yoga Pratama's avatar
Yoga Pratama committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
                                      Flexible(
                                        child: Text(
                                          widget.lokasi.noTelp ?? '-',
                                          softWrap: true,
                                          textAlign: TextAlign.left,
                                          style: const TextStyle(
                                            fontSize: 15,
                                            color: Colors.black,
                                            fontFamily: 'Muli',
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
157
                                ],
Yoga Pratama's avatar
Yoga Pratama committed
158
159
160
                              )
                            ]),
                      )),
161
162
163
164
165
166
167
168
169
170
171
                  // Tab bar (Fasilitas & Kegiatan)
                  Container(
                    height: 50,
                    child: AppBar(
                      backgroundColor: Colors.white,
                      bottom: TabBar(
                        indicatorColor: greenPrimary,
                        indicatorSize: TabBarIndicatorSize.tab,
                        indicatorWeight: 4,
                        labelStyle: TextStyle(fontSize: 15, fontFamily: 'Muli'),
                        labelColor: greenPrimary,
Yoga Pratama's avatar
Yoga Pratama committed
172
173
                        unselectedLabelStyle:
                            TextStyle(fontSize: 15, fontFamily: 'Muli'),
174
175
176
177
178
                        unselectedLabelColor: Colors.black,
                        tabs: [
                          Tab(text: 'Fasilitas'),
                          Tab(text: 'Kegiatan'),
                        ],
179
180
                      ),
                    ),
181
182
183
184
185
186
187
                  ),
                ],
              ),
            ),
          ],
          body: Column(
            children: [
Yoga Pratama's avatar
Yoga Pratama committed
188
189
              Expanded(
                // Render tab bar content
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
                child: TabBarView(
                  physics: BouncingScrollPhysics(),
                  children: [
                    // First tab bar view widget
                    ListView(
                      children: [
                        Container(
                          margin: const EdgeInsets.only(
                            top: doubleSpace,
                            bottom: regularSpace,
                            left: doubleSpace,
                            right: doubleSpace,
                          ),
                          decoration: BoxDecoration(boxShadow: regularShadow),
                          child: SizedBox(
                            width: double.infinity,
jovi_013's avatar
jovi_013 committed
206
                            child: TextButton(
207
                              key: const Key('Tambah Informasi'),
jovi_013's avatar
jovi_013 committed
208
                              style: ButtonStyle(
Yoga Pratama's avatar
Yoga Pratama committed
209
210
                                backgroundColor:
                                    MaterialStateProperty.resolveWith((states) {
jovi_013's avatar
jovi_013 committed
211
212
213
214
215
                                  if (states.contains(MaterialState.disabled)) {
                                    return Colors.grey;
                                  }
                                  return Colors.green[700];
                                }),
Yoga Pratama's avatar
Yoga Pratama committed
216
217
                                foregroundColor:
                                    MaterialStateProperty.resolveWith((states) {
jovi_013's avatar
jovi_013 committed
218
219
220
221
222
223
                                  if (states.contains(MaterialState.disabled)) {
                                    return Colors.black;
                                  }
                                  return Colors.white;
                                }),
                                padding: MaterialStateProperty.all(
Yoga Pratama's avatar
Yoga Pratama committed
224
225
                                    EdgeInsets.symmetric(
                                        vertical: 8, horizontal: 8)),
jovi_013's avatar
jovi_013 committed
226
                                shape: MaterialStateProperty.all(
Yoga Pratama's avatar
Yoga Pratama committed
227
228
229
230
                                    RoundedRectangleBorder(
                                        borderRadius: regularBorderRadius,
                                        side: const BorderSide(
                                            color: Colors.transparent))),
jovi_013's avatar
jovi_013 committed
231
                              ),
232
                              onPressed: () {
233
                                checkLoginStatus('informasi');
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  const Icon(
                                    Icons.add,
                                    size: 20,
                                  ),
                                  const Text(
                                    'Tambah Informasi',
                                    style: TextStyle(fontSize: 20),
                                  ),
                                ],
                              ),
                            ),
249
                          ),
250
251
252
253
254
                        ),
                        Container(
                          margin: EdgeInsets.only(
                            top: smallSpace,
                            bottom: doubleSpace,
255
                          ),
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                          child: Center(
                            child: const Text(
                              'Fasilitas atau layanan yang disediakan',
                              style: TextStyle(
                                fontSize: 15,
                                fontWeight: FontWeight.w800,
                                color: Colors.black,
                                fontFamily: 'Muli',
                              ),
                            ),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(
                            left: doubleSpace,
                            right: doubleSpace,
                            bottom: regularSpace,
                          ),
                          child: StreamBuilder(
Yoga Pratama's avatar
Yoga Pratama committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
                              stream: _komentarBloc.komentarListStream,
                              builder: (context, snapshot) {
                                if (snapshot.hasData) {
                                  switch (snapshot.data.status) {
                                    case Status.loading:
                                      return const Center(
                                        child: CircularProgressIndicator(
                                          valueColor:
                                              AlwaysStoppedAnimation<Color>(
                                                  greenPrimary),
                                        ),
                                      );
                                      break;

                                    case Status.completed:
                                      allKomentarFromApi =
                                          snapshot.data.data.allKomentar;
                                      if (allKomentarFromApi.isEmpty) {
                                        return const Center(
                                          child: Text('Belum ada informasi'),
                                        );
                                      }
                                      return Column(
                                          children: allKomentarFromApi
                                              .map<Widget>((k) => Komentar(
                                                  lokasi: widget.lokasi,
                                                  komentar: k))
                                              .toList());
                                      break;
304

Yoga Pratama's avatar
Yoga Pratama committed
305
                                    case Status.error:
306
307
308
                                      return const Center(
                                        child: Text('Belum ada informasi'),
                                      );
Yoga Pratama's avatar
Yoga Pratama committed
309
310
                                      break;
                                  }
311
                                }
Yoga Pratama's avatar
Yoga Pratama committed
312
313
                                return Container();
                              }),
314
315
                        ),
                      ],
316
                    ),
317
318
319
320
321
322
323
324
325
326
327
328
329
                    // second tab bar view widget
                    ListView(
                      children: [
                        Container(
                          margin: const EdgeInsets.only(
                            top: doubleSpace,
                            bottom: regularSpace,
                            left: doubleSpace,
                            right: doubleSpace,
                          ),
                          decoration: BoxDecoration(boxShadow: regularShadow),
                          child: SizedBox(
                            width: double.infinity,
jovi_013's avatar
jovi_013 committed
330
331
332
                            child: TextButton(
                              key: const Key('Tambah Informasi'),
                              style: ButtonStyle(
Yoga Pratama's avatar
Yoga Pratama committed
333
334
                                backgroundColor:
                                    MaterialStateProperty.resolveWith((states) {
jovi_013's avatar
jovi_013 committed
335
336
337
338
339
                                  if (states.contains(MaterialState.disabled)) {
                                    return Colors.grey;
                                  }
                                  return Colors.green[700];
                                }),
Yoga Pratama's avatar
Yoga Pratama committed
340
341
                                foregroundColor:
                                    MaterialStateProperty.resolveWith((states) {
jovi_013's avatar
jovi_013 committed
342
343
344
345
346
347
                                  if (states.contains(MaterialState.disabled)) {
                                    return Colors.black;
                                  }
                                  return Colors.white;
                                }),
                                padding: MaterialStateProperty.all(
Yoga Pratama's avatar
Yoga Pratama committed
348
349
                                    EdgeInsets.symmetric(
                                        vertical: 8, horizontal: 8)),
jovi_013's avatar
jovi_013 committed
350
                                shape: MaterialStateProperty.all(
Yoga Pratama's avatar
Yoga Pratama committed
351
352
353
354
                                    RoundedRectangleBorder(
                                        borderRadius: regularBorderRadius,
                                        side: const BorderSide(
                                            color: Colors.transparent))),
355
                              ),
356
                              onPressed: () {
357
                                checkLoginStatus('kegiatan');
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  const Icon(
                                    Icons.add,
                                    size: 20,
                                  ),
                                  const Text(
                                    'Tambah Kegiatan',
                                    style: TextStyle(fontSize: 20),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(
                            top: smallSpace,
                            bottom: doubleSpace,
                          ),
                          child: Center(
                            child: const Text(
                              'Kegiatan yang diadakan',
                              style: TextStyle(
                                fontSize: 15,
                                fontWeight: FontWeight.w800,
                                color: Colors.black,
                                fontFamily: 'Muli',
                              ),
                            ),
                          ),
                        ),
                        Container(
Yoga Pratama's avatar
Yoga Pratama committed
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
                            margin: EdgeInsets.only(
                              left: doubleSpace,
                              right: doubleSpace,
                              bottom: regularSpace,
                            ),
                            child: StreamBuilder(
                                stream: _kegiatanBloc.kegiatanListStream,
                                builder: (context, snapshot) {
                                  if (snapshot.hasData) {
                                    switch (snapshot.data.status) {
                                      case Status.loading:
                                        return const Center(
                                          child: CircularProgressIndicator(
                                            valueColor:
                                                AlwaysStoppedAnimation<Color>(
                                                    greenPrimary),
                                          ),
                                        );
                                        break;

                                      case Status.completed:
                                        allKegiatanFromApi =
                                            snapshot.data.data.allKegiatan;
                                        if (allKegiatanFromApi.isEmpty) {
                                          return const Center(
                                              child:
                                                  Text('Belum ada informasi'));
                                        }
                                        return Column(
                                            children: allKegiatanFromApi
                                                .map<Widget>((k) => Kegiatan(
424
425
                                                    lokasi: widget.lokasi,
                                                    kegiatan: k))
Yoga Pratama's avatar
Yoga Pratama committed
426
427
                                                .toList());
                                        break;
428

Yoga Pratama's avatar
Yoga Pratama committed
429
430
431
432
433
434
435
436
437
                                      case Status.error:
                                        return const Center(
                                          child: Text('Belum ada informasi'),
                                        );
                                        break;
                                    }
                                  }
                                  return Container();
                                })),
438
                      ],
439
                    ),
440
                  ],
441
                ),
442
443
444
              ),
            ],
          ),
Fakhira Devina's avatar
Fakhira Devina committed
445
446
447
448
        ),
      ),
    );
  }
449

450
451
  @override
  void dispose() {
452
453
454
455
456
457
458
459
460
461
462
463
464
    kursiRodaVal = true;
    liftVal = true;
    toiletDisabilitasVal = true;
    tempatIbadahVal = true;
    bidangMiringVal = true;
    parkirUmumVal = true;
    parkirDisabilitasVal = true;
    guidingBlockVal = true;
    temanDisabilitasVal = true;
    juruIsyaratVal = true;
    tongkatVal = true;
    kursiDisabilitasVal = true;
    runningTextVal = true;
465
    sortKomentar = -1;
466
467
    _komentarBloc.dispose();
    _kegiatanBloc.dispose();
468
    super.dispose();
469
  }
Usman Sidiq's avatar
Usman Sidiq committed
470

471
  void checkLoginStatus(String type) async {
472
    final sharedPreferences = await SharedPreferences.getInstance();
473
474
    if (sharedPreferences.getString('token') == null) {
      await Navigator.of(context).pushAndRemoveUntil(
475
          MaterialPageRoute(builder: (BuildContext context) => const Login()),
476
          (Route<dynamic> route) => false);
477
    } else if (type == 'informasi') {
478
479
480
481
      await Navigator.of(context)
          .push(MaterialPageRoute(
              builder: (BuildContext context) => AddInformasi(
                    nama: widget.lokasi.name,
482
                    placeId: widget.lokasi.placeId,
483
                  )))
Yoga Pratama's avatar
Yoga Pratama committed
484
485
          .then((value) =>
              _komentarBloc.fetchKomentarList(widget.lokasi.placeId));
486
487
488
489
490
491
492
493
494
495
496
497
    } else {
      await Navigator.of(context)
          .push(MaterialPageRoute(
              builder: (BuildContext context) => AddKegiatan(
                    nama: widget.lokasi.name,
                    placeId: widget.lokasi.placeId,
                  )))
          .then(
            (value) => _kegiatanBloc.fetchKegiatanList(
              widget.lokasi.placeId,
            ),
          );
Usman Sidiq's avatar
Usman Sidiq committed
498
499
    }
  }
500
501
502
503
504
505
506
507
508

  Future<void> _postSearchHistory() async {
    final sharedPreferences = await SharedPreferences.getInstance();

    if (sharedPreferences.containsKey('token')) {
      final token = 'token ${sharedPreferences.getString('token')}';
      await _lokasiBloc.postSearchHistory(widget.lokasi.placeId, token);
    }
  }
509
}