Skip to content

Commit

Permalink
Add location map
Browse files Browse the repository at this point in the history
  • Loading branch information
ferndot committed Mar 16, 2020
1 parent f57c2f1 commit ac21073
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 84 deletions.
30 changes: 9 additions & 21 deletions lib/src/ui/screens/activity/activity.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'package:coronavirus_diary/src/blocs/activity/activity.dart';
import 'package:coronavirus_diary/src/ui/screens/activity/activity_list.dart';
Expand All @@ -19,6 +20,13 @@ class _ActivityScreenState extends State<ActivityScreen> {
return Scaffold(
appBar: AppBar(
title: Text('My activity'),
actions: <Widget>[
IconButton(
onPressed: () =>
Navigator.pushNamed(context, ActivityCreateScreen.routeName),
icon: FaIcon(FontAwesomeIcons.plus),
),
],
),
body: BlocBuilder<ActivityBloc, ActivityHistoryState>(
builder: (context, state) {
Expand All @@ -29,27 +37,7 @@ class _ActivityScreenState extends State<ActivityScreen> {
}
return LoadingIndicator('Loading activity');
} else if (state is ActivityHistoryLoaded) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: SizedBox(
width: double.infinity,
child: RaisedButton(
onPressed: () => Navigator.pushNamed(
context, ActivityCreateScreen.routeName),
child: Text('Add an activity'),
),
),
),
Expanded(
child: ActivityList(activities: state.activities),
),
],
),
);
return ActivityList(activities: state.activities);
} else {
return Center(
child: Text('Activity loading failed.'),
Expand Down
1 change: 0 additions & 1 deletion lib/src/ui/screens/activity/activity_cards/index.dart

This file was deleted.

35 changes: 0 additions & 35 deletions lib/src/ui/screens/activity/activity_cards/location.dart

This file was deleted.

59 changes: 40 additions & 19 deletions lib/src/ui/screens/activity/activity_list.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
import 'package:flutter/material.dart';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

import 'package:coronavirus_diary/src/data/database/database.dart';
import 'activity_cards/index.dart';

class ActivityList extends StatefulWidget {
final List<ActivityWithLocation> activities;

const ActivityList({
this.activities = const [],
});
const ActivityList({this.activities = const []});

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

class _ActivityListState extends State<ActivityList> {
MapController mapController;
List<LatLng> points = [];

@override
void initState() {
super.initState();
points = _getPoints();
mapController = MapController();
mapController.onReady.then((result) {
mapController.fitBounds(LatLngBounds.fromPoints(points));
});
}

List<LatLng> _getPoints() {
return widget.activities.map((ActivityWithLocation activity) {
return LatLng(activity.location.lat, activity.location.long);
}).toList();
}

@override
Widget build(BuildContext context) {
if (widget.activities.length == 0) {
return Center(
child: Text('No activity found.'),
);
}

return Timeline.builder(
position: TimelinePosition.Left,
itemCount: widget.activities.length,
itemBuilder: (BuildContext context, int index) {
final ActivityWithLocation activity = widget.activities[index];
return TimelineModel(LocationCard(activity));
},
return FlutterMap(
mapController: mapController,
options: MapOptions(),
layers: [
TileLayerOptions(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c'],
),
PolylineLayerOptions(
polylines: [
Polyline(
points: points,
strokeWidth: 4.0,
color: Colors.purple,
),
],
),
],
);
}
}
91 changes: 84 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.2"
ansicolor:
dependency: transitive
description:
name: ansicolor
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -120,6 +127,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.9"
cached_network_image:
dependency: transitive
description:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -155,6 +169,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
console_log_handler:
dependency: transitive
description:
name: console_log_handler
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -230,6 +251,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
flutter_cache_manager:
dependency: transitive
description:
name: flutter_cache_manager
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
flutter_image:
dependency: transitive
description:
name: flutter_image
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
flutter_map:
dependency: "direct main"
description:
name: flutter_map
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.2"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -354,6 +396,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.5"
latlong:
dependency: transitive
description:
name: latlong
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
location_permissions:
dependency: transitive
description:
Expand Down Expand Up @@ -508,6 +557,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
positioned_tap_detector:
dependency: transitive
description:
name: positioned_tap_detector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -646,27 +702,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
timeline_list:
dependency: "direct main"
description:
name: timeline_list
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.5"
timing:
dependency: transitive
description:
name: timing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+2"
transparent_image:
dependency: transitive
description:
name: transparent_image
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
tuple:
dependency: transitive
description:
name: tuple
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
validate:
dependency: transitive
description:
name: validate
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
sdk: flutter
flutter_background_geolocation: ^1.7.0
flutter_bloc: ^3.2.0
flutter_map: ^0.8.2
flutter_xlider: ^3.2.0
font_awesome_flutter: ^8.7.0
geolocator: ^5.3.0
Expand All @@ -35,7 +36,6 @@ dependencies:
path: ^1.6.4
provider: ^4.0.4
sqflite: any
timeline_list: ^0.0.5

dev_dependencies:
build_runner: ^1.8.0
Expand Down

0 comments on commit ac21073

Please sign in to comment.