Skip to content

Commit

Permalink
feat: maplibre
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiya10 committed Jun 30, 2024
1 parent bae3219 commit 776d902
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/app/page/report_list/report_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class _ReportListPageState extends State<ReportListPage> {

setState(() {
reportList = newList;
lastFetchTime = DateTime.now();
});

return reportList;
Expand Down
37 changes: 23 additions & 14 deletions lib/app/page/report/report.dart → lib/route/report/report.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import 'package:dpip/api/exptech.dart';
import 'package:dpip/model/report/earthquake_report.dart';
import 'package:dpip/model/report/partial_earthquake_report.dart';
import 'package:dpip/util/extension/build_context.dart';
import 'package:dpip/widget/report/intensity_box.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:maplibre_gl/maplibre_gl.dart';

class ReportPage extends StatefulWidget {
final String reportId;
const ReportPage({super.key, required this.reportId});
class ReportRoute extends StatefulWidget {
final PartialEarthquakeReport report;
const ReportRoute({super.key, required this.report});

@override
State<ReportPage> createState() => _ReportPageState();
State<ReportRoute> createState() => _ReportRouteState();
}

class _ReportPageState extends State<ReportPage> with SingleTickerProviderStateMixin {
class _ReportRouteState extends State<ReportRoute> with SingleTickerProviderStateMixin {
final sheetController = DraggableScrollableController();
final sheetInitialSize = 0.2;
late final AnimationController controller = BottomSheet.createAnimationController(this);
late final animController = AnimationController(vsync: this);
final sheetController = DraggableScrollableController();
late final decorationTween = DecorationTween(
begin: BoxDecoration(
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
Expand All @@ -31,7 +33,7 @@ class _ReportPageState extends State<ReportPage> with SingleTickerProviderStateM
EarthquakeReport? report;

Future<EarthquakeReport> fetchEarthquakeReport() async {
final data = await ExpTech().getReport(widget.reportId);
final data = await ExpTech().getReport(widget.report.id);
setState(() {
report = data;
});
Expand All @@ -45,7 +47,7 @@ class _ReportPageState extends State<ReportPage> with SingleTickerProviderStateM
sheetController.addListener(
() {
final newSize = sheetController.size;
final scrollPosition = ((newSize - 0.25) / (1 - 0.25)).clamp(0.0, 1.0);
final scrollPosition = ((newSize - sheetInitialSize) / (1 - sheetInitialSize)).clamp(0.0, 1.0);
animController.animateTo(scrollPosition, duration: Duration.zero);
},
);
Expand All @@ -55,14 +57,16 @@ class _ReportPageState extends State<ReportPage> with SingleTickerProviderStateM
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.reportId),
title: Text(widget.report.hasNumber ? "編號 ${widget.report.number}" : "小區域有感地震"),
),
body: Stack(children: [
FlutterMap(
children: [],
MapLibreMap(
initialCameraPosition: const CameraPosition(target: LatLng(23.8, 120.1), zoom: 6),
),
Positioned.fill(
child: DraggableScrollableSheet(
initialChildSize: sheetInitialSize,
minChildSize: sheetInitialSize,
controller: sheetController,
snap: true,
builder: (context, scrollController) {
Expand Down Expand Up @@ -92,9 +96,14 @@ class _ReportPageState extends State<ReportPage> with SingleTickerProviderStateM
child: Row(
children: [
IntensityBox(intensity: report!.getMaxIntensity()),
const SizedBox(width: 8),
const SizedBox(width: 16),
Column(
children: [Text(report!.getLocation())],
children: [
Text(
report!.getLocation(),
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
],
)
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/widget/report/list_item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:dpip/app/page/report/report.dart';
import 'package:dpip/route/report/report.dart';
import 'package:dpip/model/report/partial_earthquake_report.dart';
import 'package:dpip/util/extension/build_context.dart';
import 'package:dpip/util/intensity_color.dart';
Expand Down Expand Up @@ -137,7 +137,7 @@ class ReportListItem extends StatelessWidget {
context,
MaterialPageRoute(
builder: (context) {
return ReportPage(reportId: report.id);
return ReportRoute(report: report);
},
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:
dynamic_color: ^1.7.0
simple_icons: ^10.1.3
url_launcher: ^6.3.0
flutter_map: ^7.0.1
maplibre_gl: ^0.20.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 776d902

Please sign in to comment.