-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(map): Add map support for viewing and managing diary entry locat…
…ions Closes #13
- Loading branch information
Showing
14 changed files
with
416 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
description: This file stores settings for Dart & Flutter DevTools. | ||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states | ||
extensions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
class GeoResponse { | ||
String? code; | ||
List<Location>? location; | ||
Refer? refer; | ||
|
||
GeoResponse({this.code, this.location, this.refer}); | ||
|
||
GeoResponse.fromJson(Map<String, dynamic> json) { | ||
code = json["code"]; | ||
location = json["location"] == null ? null : (json["location"] as List).map((e) => Location.fromJson(e)).toList(); | ||
refer = json["refer"] == null ? null : Refer.fromJson(json["refer"]); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data["code"] = code; | ||
data["location"] = location?.map((e) => e.toJson()).toList(); | ||
data["refer"] = refer?.toJson(); | ||
return data; | ||
} | ||
} | ||
|
||
class Refer { | ||
List<String>? sources; | ||
List<String>? license; | ||
|
||
Refer({this.sources, this.license}); | ||
|
||
Refer.fromJson(Map<String, dynamic> json) { | ||
sources = json["sources"] == null ? null : List<String>.from(json["sources"]); | ||
license = json["license"] == null ? null : List<String>.from(json["license"]); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data["sources"] = sources; | ||
data["license"] = license; | ||
return data; | ||
} | ||
} | ||
|
||
class Location { | ||
String? name; | ||
String? id; | ||
String? lat; | ||
String? lon; | ||
String? adm2; | ||
String? adm1; | ||
String? country; | ||
String? tz; | ||
String? utcOffset; | ||
String? isDst; | ||
String? type; | ||
String? rank; | ||
String? fxLink; | ||
|
||
Location({ | ||
this.name, | ||
this.id, | ||
this.lat, | ||
this.lon, | ||
this.adm2, | ||
this.adm1, | ||
this.country, | ||
this.tz, | ||
this.utcOffset, | ||
this.isDst, | ||
this.type, | ||
this.rank, | ||
this.fxLink, | ||
}); | ||
|
||
Location.fromJson(Map<String, dynamic> json) { | ||
name = json["name"]; | ||
id = json["id"]; | ||
lat = json["lat"]; | ||
lon = json["lon"]; | ||
adm2 = json["adm2"]; | ||
adm1 = json["adm1"]; | ||
country = json["country"]; | ||
tz = json["tz"]; | ||
utcOffset = json["utcOffset"]; | ||
isDst = json["isDst"]; | ||
type = json["type"]; | ||
rank = json["rank"]; | ||
fxLink = json["fxLink"]; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data["name"] = name; | ||
data["id"] = id; | ||
data["lat"] = lat; | ||
data["lon"] = lon; | ||
data["adm2"] = adm2; | ||
data["adm1"] = adm1; | ||
data["country"] = country; | ||
data["tz"] = tz; | ||
data["utcOffset"] = utcOffset; | ||
data["isDst"] = isDst; | ||
data["type"] = type; | ||
data["rank"] = rank; | ||
data["fxLink"] = fxLink; | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
class DiaryMapItem { | ||
// 坐标 | ||
late LatLng latLng; | ||
|
||
// 文章id | ||
late int id; | ||
|
||
// 封面图片名称 | ||
late String coverImageName; | ||
|
||
DiaryMapItem(this.latLng, this.id, this.coverImageName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Bubble extends StatelessWidget { | ||
final Widget child; | ||
final Color backgroundColor; | ||
final double borderRadius; | ||
|
||
const Bubble({ | ||
super.key, | ||
required this.child, | ||
this.backgroundColor = Colors.white, | ||
this.borderRadius = 8.0, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CustomPaint( | ||
painter: BubblePainter( | ||
color: backgroundColor, | ||
borderRadius: borderRadius, | ||
), | ||
child: Align( | ||
alignment: Alignment.topCenter, | ||
child: Padding( | ||
padding: const EdgeInsets.all(4.0), | ||
child: child, | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class BubblePainter extends CustomPainter { | ||
final Color color; | ||
final double borderRadius; | ||
|
||
BubblePainter({required this.color, required this.borderRadius}); | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
final paint = Paint() | ||
..color = color | ||
..style = PaintingStyle.fill; | ||
const arrowWidth = 16.0; | ||
const arrowHeight = 8.0; | ||
final rectWidth = size.width; | ||
final rectHeight = size.height - arrowHeight; // 减去箭头的高度 | ||
|
||
// 创建带圆角的矩形区域 | ||
final rrect = RRect.fromLTRBR( | ||
0, | ||
0, | ||
rectWidth, | ||
rectHeight, | ||
Radius.circular(borderRadius), | ||
); | ||
|
||
// 创建路径 | ||
final path = Path() | ||
..addRRect(rrect) // 添加圆角矩形 | ||
..moveTo((rectWidth - arrowWidth) / 2, rectHeight) // 箭头左侧 | ||
..lineTo(rectWidth / 2, rectHeight + arrowHeight) // 箭头尖端 | ||
..lineTo((rectWidth + arrowWidth) / 2, rectHeight); // 箭头右侧 | ||
|
||
canvas.drawPath(path, paint); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.