Skip to content

Commit

Permalink
Change Case List to a map view
Browse files Browse the repository at this point in the history
  • Loading branch information
dewmal committed Apr 11, 2020
1 parent 1372dea commit dbc366f
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 8 deletions.
2 changes: 1 addition & 1 deletion assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"case_item_foreign": "Foreign",
"case_item_community": "Community",
"case_item_quarantine": "Quarantine",
"case_item_reported_locations": "Reported locations",
"case_item_reported_locations": "Reported location",
"case_item_register": "REGISTER",
"case_item_already_register": "Already Added for Registration",
"medical_consultation_service_title": "Medical Consultation Services",
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/si.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"case_item_foreign": "විදේශිය",
"case_item_community": "ප්\u200Dරජාව",
"case_item_quarantine": "නිරෝධායනය",
"case_item_reported_locations": "වාර්තා වූ ස්ථාන",
"case_item_reported_locations": "වාර්තා වූ ස්ථානය",
"case_item_register": " ලියාපදිංචි වන්න",
"case_item_already_register": "දැනටමත් ලියාපදිංචිවී ඇත",
"medical_consultation_service_title": "වෛද්\u200Dය උපදේශන සේවාවන්",
Expand Down
193 changes: 193 additions & 0 deletions lib/page/screen/case_details_map_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import 'dart:async';
import 'dart:convert';
import 'package:async/async.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:selftrackingapp/models/location.dart';
import 'package:selftrackingapp/models/reported_case.dart';
import 'package:selftrackingapp/networking/api_client.dart';
import 'package:selftrackingapp/widgets/case_item_map_detail.dart';

DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");

class CaseListMapDetailScreen extends StatefulWidget {
const CaseListMapDetailScreen({Key key}) : super(key: key);

@override
_CaseListMapDetailScreenState createState() =>
_CaseListMapDetailScreenState();
}

class _CaseListMapDetailScreenState extends State<CaseListMapDetailScreen> {
static const MethodChannel _channel = MethodChannel('location');
ReportedCase selectedCase;

Completer<GoogleMapController> _controller = Completer();
Position _currentLocation;
double pinPillPosition = -1000;

List<Marker> locationMarkers = [];

Future<void> _fetchCases(BitmapDescriptor mapIcon) async {
List<ReportedCase> _cases = [];
int id = await ApiClient().getLastCaseId();
if (id == -1) {
return _cases;
}
for (int i = id; i > 0; i--) {
ReportedCase reportedCase =
await ApiClient().getCase(i, forceUpdate: false);
if (reportedCase != null && reportedCase.locations != null) {
Location l = reportedCase.locations[0];
setState(() {
locationMarkers.add(
Marker(
icon: mapIcon,
alpha: 0.5,
markerId: MarkerId("${l.date.millisecondsSinceEpoch}"),
position: LatLng(l.latitude, l.longitude),
onTap: () {
setState(() {
selectedCase = reportedCase;
pinPillPosition = MediaQuery.of(context).size.height / 10;
});
}),
);
});
}
}
print("Cases found Retreived: ${_cases.length}");
}

@override
void initState() {
super.initState();

BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio: 0.1, size: Size(0.5, 0.5)),
"assets/images/user_icon.png")
.then((userIcon) {
BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio: 0.1, size: Size(0.5, 0.5)),
"assets/images/suspected_icon.png")
.then((suspectIcon) {
_fetchCases(suspectIcon);
// getLocationUpdate().then((List<Location> locations) {
//
// });
});
});
}

@override
void dispose() {
super.dispose();
// if (_locationTimer != null) _locationTimer.cancel();
// if (_currentLoctimer != null) _currentLoctimer.cancel();
print("CANCELLING timers");
}

@override
Widget build(BuildContext context) {
return Container(
child: getMapView(), //initially this will be empty
);
}

Widget getMapView() {
return Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
mapType: MapType.terrain,
markers: getMapEntries(),
initialCameraPosition: CameraPosition(
target: _currentLocation != null
? LatLng(
_currentLocation.latitude, _currentLocation.longitude)
: LatLng(6.9271, 79.8612),
zoom: 12,
),
mapToolbarEnabled: true,
myLocationButtonEnabled: true,
myLocationEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onTap: (LatLng location) {
setState(() {
pinPillPosition = -MediaQuery.of(context).size.height;
});
},
),
AnimatedPositioned(
bottom: pinPillPosition,
right: 0,
left: 0,
duration: Duration(milliseconds: 300),
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.all(4),
width: MediaQuery.of(context).size.width * 7 / 8,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(16)),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 20,
offset: Offset.zero,
color: Colors.grey.withOpacity(0.5))
]),
child: selectedCase != null
? Padding(
padding: const EdgeInsets.all(8.0),
child: CaseItemMapInfo(selectedCase, () {
print("Click Card");
setState(() {
pinPillPosition =
-MediaQuery.of(context).size.height;
});
}),
)
: Container(),
)),
)
],
),
);
}

Widget getListView(List<Location> entries) {
return ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return Text(
'Entry ${entries[index].longitude},${entries[index].latitude},${entries[index].date}');
});
}

Future<List<Location>> getLocationUpdate() async {
try {
final List<dynamic> locations =
await _channel.invokeMethod('getLocation');
print("locations $locations");

return locations
.map((v) => Location.fromBackgroundJson(json.decode(v)))
.toList();
} on Exception catch (e) {
print(e);
}
return null;
}

getMapEntries() {
return locationMarkers.toSet();
}
}
3 changes: 2 additions & 1 deletion lib/page/screen/root_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:titled_navigation_bar/titled_navigation_bar.dart';
import '../../app_localizations.dart';
import '../ios_faq.dart';
import 'case_details_screen.dart';
import 'case_details_map_screen.dart';

enum RootTab { HomeTab, CaseTab, ContactTab, RegisterTab }

Expand All @@ -42,7 +43,7 @@ class _RootScreenState extends State<RootScreen> {
bool _hasCaseThrownError = false;
final List<Widget> _homeTabsTotal = [
DashboardScreen(),
CaseListScreen(),
CaseListMapDetailScreen(),
CaseDetailScreen(),
FAQScreen()
];
Expand Down
5 changes: 1 addition & 4 deletions lib/widgets/case_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import 'package:provider/provider.dart';
import 'package:selftrackingapp/app_localizations.dart';
import 'package:selftrackingapp/models/reported_case.dart';
import 'package:selftrackingapp/notifiers/registered_cases_model.dart';
import 'package:selftrackingapp/page/screen/case_details_screen.dart';
import 'package:selftrackingapp/page/screen/user_register_screen.dart';
import 'package:selftrackingapp/page/screen/selected_case_detail_screen.dart';
import 'package:selftrackingapp/page/screen/user_register_screen.dart';
import 'package:selftrackingapp/utils/tracker_colors.dart';

import 'custom_text.dart';

class CaseItem extends StatelessWidget {
final ReportedCase _case;

Expand Down
Loading

0 comments on commit dbc366f

Please sign in to comment.