Fakultas Ilmu Komputer UI

dashboard.dart 4.23 KB
Newer Older
1
import 'package:flutter/material.dart';
2
import 'package:geolocator/geolocator.dart';
3
import 'package:google_maps_flutter/google_maps_flutter.dart';
4
5
6
7
8
import 'package:bisaGo/component/bisago_appbar.dart';
import 'package:bisaGo/component/bisago_drawer.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/page/pencarian/pencarian.dart';
import 'package:bisaGo/page/informasi/layananDisabilitas.dart';
9
10

class Dashboard extends StatefulWidget {
11
  @override
12
13
14
15
  DashboardState createState() => DashboardState();
}

class DashboardState extends State<Dashboard> {
Fakhira Devina's avatar
Fakhira Devina committed
16
  final double cameraZoom = 40;
17
18
19
  GoogleMapController mapController;
  Geolocator geolocator;
  LatLng currentLocation;
20
  Set<Marker> markers = {};
21
22
23
24

  @override
  void initState() {
    super.initState();
25
    geolocator = Geolocator()..forceAndroidLocationManager;
26
    setInitialLocation();
27
28
  }

29
  void _navigateToPencarianPage(BuildContext context) {
30
31
32
33
    final route = MaterialPageRoute(builder: (_) => Pencarian());
    Navigator.of(context).push(route);
  }

34
  void _navigateToInformasiLayananDisabilitasPage(BuildContext context) {
35
    final route = MaterialPageRoute(builder: (_) => LayananDisabilitas());
36
37
38
    Navigator.of(context).push(route);
  }

39
  static const textFieldKey = Key('Text Field Mau Kemana');
40
41
42
  @override
  Widget build(BuildContext context) {
    return Scaffold(
43
      drawer: BisaGoDrawer(),
44
      body: Stack(key: const Key('Stack'), children: <Widget>[
45
        _buildGoogleMap(context),
46
        InkWell(
47
          key: const Key('Navigate to Pencarian'),
48
49
          onTap: () => _navigateToPencarianPage(context),
          child: Container(
50
            key: const Key('Container Text Field'),
51
52
53
54
55
56
57
58
            margin: EdgeInsets.only(
                left: doubleSpace, right: doubleSpace, top: doubleSpace),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: doubleBorderRadius,
                boxShadow: regularShadow),
            child: TextFormField(
              enabled: false,
59
              key: const Key('Text Field Mau Kemana'),
60
              decoration: InputDecoration(
61
62
63
64
65
66
67
68
69
                prefixIcon: Icon(
                  Icons.search,
                  color: greenPrimary,
                  size: 25,
                ),
                border: InputBorder.none,
                fillColor: Colors.white,
                labelText: 'Kamu mau kemana?',
                labelStyle: TextStyle(
70
                    color: greenPrimary,
71
72
73
74
                    fontSize: 20,
                    fontFamily: 'Muli',
                    fontWeight: FontWeight.w700),
              ),
75
              onTap: () => _navigateToPencarianPage(context),
76
            ),
77
78
79
          ),
        ),
      ]),
80
      floatingActionButton: FloatingActionButton.extended(
81
        key: const Key('FloatingActionButton'),
82
83
84
85
86
87
88
89
        onPressed: () {
          _navigateToInformasiLayananDisabilitasPage(context);
        },
        label: Text('Informasi Layanan Disabilitas'),
        icon: Icon(Icons.search),
        backgroundColor: greenPrimary,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
90
      appBar: PreferredSize(
Fakhira Devina's avatar
Fakhira Devina committed
91
        preferredSize: const Size.fromHeight(55),
92
        child: BisaGoAppBar(),
93
        key: const Key('Scaffold Text Field'),
Agnes Handoko's avatar
Agnes Handoko committed
94
      ),
95
96
97
98
    );
  }

  Widget _buildGoogleMap(BuildContext context) {
99
100
101
102
103
    if (currentLocation == null) {
      return Container(
        child: Center(
          child: CircularProgressIndicator(),
        ),
104
      );
105
106
    } else {
      return GoogleMap(
107
        mapType: MapType.normal,
108
109
        initialCameraPosition:
            CameraPosition(target: currentLocation, zoom: cameraZoom),
110
        onMapCreated: (GoogleMapController controller) {
111
          mapController = controller;
112
        },
113
114
        myLocationEnabled: true,
        compassEnabled: true,
115
        markers: markers,
116
117
118
        onCameraMove: _onCameraMove,
      );
    }
119
120
  }

121
  void _onCameraMove(CameraPosition position) {
122
    setState(() {
123
      currentLocation = position.target;
124
125
126
    });
  }

127
128
  void setInitialLocation() async {
    var position = await geolocator.getCurrentPosition(
129
130
131
132
133
        desiredAccuracy: LocationAccuracy.high);

    setState(() {
      currentLocation = LatLng(position.latitude, position.longitude);
    });
134
135
  }
}