diff --git a/app/lib/main.dart b/app/lib/main.dart index 10b3118b6bb06acf9ed72c7e3de427f0e5aad0e8..7f804e167f65ab7b2a70699d638bcb215f542a03 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'pages/default_page.dart'; +import 'pages/marker_data.dart'; void main() { runApp(MyApp()); diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart index fd38e444cdb3250c9ead379d6a5b63c57110d4ea..af5fa79dca924e5270d85b61857e5ce96a644bd8 100644 --- a/app/lib/pages/default_page.dart +++ b/app/lib/pages/default_page.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'widgets/map_widget.dart'; -import 'widgets/details_widget.dart'; import 'marker_data.dart'; import 'consts.dart'; @@ -79,9 +78,7 @@ class _DefaultPageState extends State<DefaultPage> { ), body: ListView( children: [ - MapContainerWidget(markerList: markerList), - const SizedBox(height: 30), // Padding between widgets - DetailsContainerWidget(markerData: markerList.first), + MapContainerWidget(markerList: markerList),// Return a specific list element ], ), ); diff --git a/app/lib/pages/widgets/details_widget.dart b/app/lib/pages/widgets/details_widget.dart deleted file mode 100644 index 240cb5d3e9375deceed82ccd580cb7247fec46dd..0000000000000000000000000000000000000000 --- a/app/lib/pages/widgets/details_widget.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import '../marker_data.dart'; - -class DetailsContainerWidget extends StatefulWidget { - const DetailsContainerWidget({Key? key, required this.markerData}) : super(key: key); - - final MarkerTemplate markerData; - - @override - _DetailsContainerWidgetState createState() => _DetailsContainerWidgetState(); -} - -class _DetailsContainerWidgetState extends State<DetailsContainerWidget> { - @override - Widget build(BuildContext context) { - double screenWidth = MediaQuery.of(context).size.width; - double boxWidth = 0.9; - double boxHeight = 1.5; - - return Container( - width: screenWidth * boxWidth, - height: screenWidth * boxHeight, - color: Colors.blue, - child: Align( - alignment: Alignment.topLeft, - child: Padding( - padding: const EdgeInsets.only(top: 10, left: 10), // Edge padding, text - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Ice thickness details', - style: TextStyle(fontSize: 30, color: Colors.black), - ), - Text( - 'Latitude: ${widget.markerData.geoData.latitude}', - style: TextStyle(fontSize: 20, color: Colors.black), - ), - Text( - 'Longitude: ${widget.markerData.geoData.longitude}', - style: TextStyle(fontSize: 20, color: Colors.black), - ), - // Add more information widgets here - ], - ), - ), - ), - ); - } -} diff --git a/app/lib/pages/widgets/map_widget.dart b/app/lib/pages/widgets/map_widget.dart index cf40ce9e0225b9dda7711ad87eba18d3bf6a2f4c..992a6e5e88c0a8b499b29d3892ee0c7443ed232f 100644 --- a/app/lib/pages/widgets/map_widget.dart +++ b/app/lib/pages/widgets/map_widget.dart @@ -1,49 +1,55 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../marker_data.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; -class MapContainerWidget extends StatelessWidget { +class MapContainerWidget extends StatefulWidget { final List<MarkerTemplate> markerList; - const MapContainerWidget({super.key, required this.markerList}); + const MapContainerWidget({Key? key, required this.markerList}) : super(key: key); + + @override + _MapContainerWidgetState createState() => _MapContainerWidgetState(); +} + +class _MapContainerWidgetState extends State<MapContainerWidget> { @override Widget build(BuildContext context) { - double screenWidth = MediaQuery - .of(context) - .size - .width; + MarkerTemplate? selectedMarker; + double screenWidth = MediaQuery.of(context).size.width; double boxWidth = 0.9; double boxHeight = 1.5; - return Container( - width: screenWidth * boxWidth, - height: screenWidth * boxHeight, - color: Colors.blue, - child: FlutterMap( - options: MapOptions( - center: LatLng(60.7666, 10.8471), - zoom: 9.0, - ), - children: [ - TileLayer( - urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", - subdomains: const ['a', 'b', 'c'], - ), - MarkerLayer( - markers: markerList.map((MarkerTemplate markerTemplate) { - return Marker( - width: markerTemplate.size, - height: markerTemplate.size, - point: markerTemplate.location, - builder: (ctx) => - GestureDetector( + return Column( + children: [ + Container( + width: screenWidth * boxWidth, + height: screenWidth * boxHeight, + color: Colors.blue, + child: FlutterMap( + options: MapOptions( + center: LatLng(60.7666, 10.8471), + zoom: 9.0, + ), + children: [ + TileLayer( + urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + subdomains: const ['a', 'b', 'c'], + ), + MarkerLayer( + markers: widget.markerList.map((MarkerTemplate markerTemplate) { + return Marker( + width: markerTemplate.size, + height: markerTemplate.size, + point: markerTemplate.location, + builder: (ctx) => GestureDetector( onTap: () { + setState(() { + selectedMarker = markerTemplate; + }); // NB: temporary print - print('Icon tapped'); - // NB: trigger function to add contents to the next box + print('Icon tapped: ${selectedMarker?.size}'); }, child: Image.asset( 'assets/icons/circle-red.png', @@ -53,25 +59,56 @@ class MapContainerWidget extends StatelessWidget { height: markerTemplate.size, ), ), - ); - }).toList(), + ); + }).toList(), + ), + /*PolygonLayer( + polygons: [ + Polygon( + points: [ + LatLng(60.7600, 10.8000), + LatLng(60.7600, 11.0000), + LatLng(60.7000, 11.0000), + LatLng(60.7000, 10.8000), + ], + color: Colors.blue, + isFilled: true, + ), + ], + ),*/ + ], + ), + ), + const SizedBox(height: 30), // Padding between containers + Container( + width: screenWidth * boxWidth, + height: screenWidth * boxHeight, + color: const Color(0xFF64B5F6), + child: Align( + alignment: Alignment.topLeft, + child: Padding( + padding: const EdgeInsets.only(top: 20, left: 20), // Edge padding, text + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Ice stats', + style: TextStyle(fontSize: 30, color: Colors.black), + ), + Text( + 'Latitude: ${selectedMarker?.size}', + style: const TextStyle(fontSize: 20, color: Colors.black), + ), + Text( + 'Longitude: ${selectedMarker?.geoData.longitude}', + style: const TextStyle(fontSize: 20, color: Colors.black), + ), + ], + ), + ), ), - /*PolygonLayer( - polygons: [ - Polygon( - points: [ - LatLng(60.7600, 10.8000), - LatLng(60.7600, 11.0000), - LatLng(60.7000, 11.0000), - LatLng(60.7000, 10.8000), - ], - color: Colors.blue, - isFilled: true, - ), - ], - ),*/ - ], - ), + ), + ], ); } -} \ No newline at end of file +} diff --git a/app/pubspec.lock b/app/pubspec.lock index 29ec17a46d8598260b9d81c6ec4ef924f60898a6..93f4867381731573e4b8164214a932b5c4017224 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -155,6 +155,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + nested: + dependency: transitive + description: + name: nested + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" + source: hosted + version: "1.0.0" path: dependency: transitive description: @@ -179,6 +187,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + provider: + dependency: "direct main" + description: + name: provider + sha256: "59471e0a4595e264625d3496af567ac85bdae1148ec985aff1e0555786f53ecf" + url: "https://pub.dev" + source: hosted + version: "5.0.0" sky_engine: dependency: transitive description: flutter diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 040d821ed00ded67b57e9ba1601874cde445f8e2..70f3908354c3949d3da27b2836831b227a4460a5 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: flutter_map: ^4.0.0 http: ^0.13.3 latlong2: ^0.8.2 + provider: ^5.0.0