Skip to content

Commit

Permalink
implement for android
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 19, 2024
1 parent b0c5382 commit d0afadb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/src/native/widget_state_jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ final class MapLibreMapStateJni extends MapLibreMapState
_hostApi = pigeon.MapLibreHostApi(messageChannelSuffix: channelSuffix);
pigeon.MapLibreFlutterApi.setUp(this, messageChannelSuffix: channelSuffix);
_viewId = viewId;
setState(() => isInitialized = true);
jni.Logger.setVerbosity(jni.Logger.WARN);
}

@override
void onMapReady() {
widget.onEvent?.call(MapEventMapCreated(mapController: this));
widget.onMapCreated?.call(this);
setState(() => isInitialized = true);
}

@override
Expand Down
20 changes: 12 additions & 8 deletions lib/src/ui/attribution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ class _AttributionState extends State<Attribution> {
],
...attributions.map(_HtmlWidget.new),
],
IconButton(
onPressed: () => setState(() {
_initMapCamera = null;
_expanded = !_expanded;
}),
icon: const Icon(Icons.info, size: 18),
padding: const EdgeInsets.all(4),
constraints: const BoxConstraints(),
// The SizedBox enforces the height on android (web works without it).
SizedBox.square(
dimension: 30,
child: IconButton(
onPressed: () => setState(() {
_initMapCamera = null;
_expanded = !_expanded;
}),
icon: const Icon(Icons.info, size: 18),
padding: const EdgeInsets.all(4),
constraints: const BoxConstraints(),
),
),
],
),
Expand Down
15 changes: 9 additions & 6 deletions lib/src/ui/scalebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class Scalebar extends StatelessWidget {
final futureMetersPerPixel = controller.getMetersPerPixelAtLatitude(
camera.center.lat.toDouble(),
);
final theme = Theme.of(context);
return Container(
alignment: Alignment.bottomLeft,
padding: const EdgeInsets.all(12),
child: FutureBuilder<double>(
future: futureMetersPerPixel,
builder: (context, snapshot) {
if (snapshot.data case final double data) {
return CustomPaint(painter: _ScaleBarPainter(data));
return CustomPaint(painter: _ScaleBarPainter(data, theme));
}
return const SizedBox.shrink();
},
Expand All @@ -36,15 +37,17 @@ class Scalebar extends StatelessWidget {
}

class _ScaleBarPainter extends CustomPainter {
_ScaleBarPainter(this.metersPerPixel);
_ScaleBarPainter(this.metersPerPixel, this.theme);

final double metersPerPixel;
final ThemeData theme;

final _linePaint = Paint()
..color = Colors.black
late final _linePaint = Paint()
..color = theme.textTheme.bodySmall?.color ?? Colors.black
..strokeWidth = 1.5;

final _backgroundPaint = Paint()..color = Colors.white60;
late final _backgroundPaint = Paint()
..color = theme.scaffoldBackgroundColor.withOpacity(0.62);

@override
void paint(Canvas canvas, Size size) {
Expand Down Expand Up @@ -105,7 +108,7 @@ class _ScaleBarPainter extends CustomPainter {

final textPainter = TextPainter(
text: TextSpan(
style: const TextStyle(fontSize: 12),
style: theme.textTheme.bodySmall,
text: '${meters / unit.meters} ${unit.abbreviation}',
),
textAlign: TextAlign.left,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/ui/zoom_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ class ZoomButtons extends StatelessWidget {
heroTag: 'MapLibreZoomInButton',
onPressed: () => controller.animateCamera(
zoom: controller.getCamera().zoom + 1,
nativeDuration: Duration(milliseconds: 200),
),
child: const Icon(Icons.add),
),
FloatingActionButton(
heroTag: 'MapLibreZoomOutButton',
onPressed: () => controller.animateCamera(
zoom: controller.getCamera().zoom - 1,
nativeDuration: Duration(milliseconds: 200),
),
child: const Icon(Icons.remove),
),
Expand Down

0 comments on commit d0afadb

Please sign in to comment.