diff --git a/lib/src/ui/screens/activity/activity.dart b/lib/src/ui/screens/activity/activity.dart index 6f141ac..18963bb 100644 --- a/lib/src/ui/screens/activity/activity.dart +++ b/lib/src/ui/screens/activity/activity.dart @@ -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'; @@ -19,6 +20,13 @@ class _ActivityScreenState extends State { return Scaffold( appBar: AppBar( title: Text('My activity'), + actions: [ + IconButton( + onPressed: () => + Navigator.pushNamed(context, ActivityCreateScreen.routeName), + icon: FaIcon(FontAwesomeIcons.plus), + ), + ], ), body: BlocBuilder( builder: (context, state) { @@ -29,27 +37,7 @@ class _ActivityScreenState extends State { } return LoadingIndicator('Loading activity'); } else if (state is ActivityHistoryLoaded) { - return Container( - padding: EdgeInsets.symmetric(horizontal: 20), - child: Column( - children: [ - 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.'), diff --git a/lib/src/ui/screens/activity/activity_cards/index.dart b/lib/src/ui/screens/activity/activity_cards/index.dart deleted file mode 100644 index 6b4fdc7..0000000 --- a/lib/src/ui/screens/activity/activity_cards/index.dart +++ /dev/null @@ -1 +0,0 @@ -export 'location.dart'; diff --git a/lib/src/ui/screens/activity/activity_cards/location.dart b/lib/src/ui/screens/activity/activity_cards/location.dart deleted file mode 100644 index be9a9ed..0000000 --- a/lib/src/ui/screens/activity/activity_cards/location.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; - -import 'package:coronavirus_diary/src/data/database/database.dart'; - -class LocationCard extends StatelessWidget { - final ActivityWithLocation activity; - - const LocationCard([this.activity]); - - @override - Widget build(BuildContext context) { - return Card( - child: Container( - padding: EdgeInsets.all(20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(bottom: 10), - child: Text( - DateFormat('kk:mm (yyyy-MM-dd)') - .format(activity.activity.created), - style: Theme.of(context).textTheme.title, - ), - ), - Text('Latitude: ${activity.location.lat}'), - Text('Longitude: ${activity.location.long}'), - Text('Participants: ${activity.activity.participants}'), - ], - ), - ), - ); - } -} diff --git a/lib/src/ui/screens/activity/activity_list.dart b/lib/src/ui/screens/activity/activity_list.dart index 9c46d1e..c96eff6 100644 --- a/lib/src/ui/screens/activity/activity_list.dart +++ b/lib/src/ui/screens/activity/activity_list.dart @@ -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 activities; - const ActivityList({ - this.activities = const [], - }); + const ActivityList({this.activities = const []}); @override _ActivityListState createState() => _ActivityListState(); } class _ActivityListState extends State { + MapController mapController; + List points = []; + + @override + void initState() { + super.initState(); + points = _getPoints(); + mapController = MapController(); + mapController.onReady.then((result) { + mapController.fitBounds(LatLngBounds.fromPoints(points)); + }); + } + + List _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, + ), + ], + ), + ], ); } } diff --git a/pubspec.lock b/pubspec.lock index a824408..1e86baf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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 @@ -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: @@ -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: @@ -646,13 +702,6 @@ 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: @@ -660,6 +709,20 @@ packages: 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: @@ -667,6 +730,20 @@ packages: 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: diff --git a/pubspec.yaml b/pubspec.yaml index c5a5828..7ff1fc1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 @@ -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