Skip to content

Commit

Permalink
Minor improvements (openfoodfacts#6146)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Jan 7, 2025
1 parent 1f8ad04 commit 5186bc6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/pages/product/world_map_page.dart';
import 'package:smooth_app/resources/app_icons.dart' as icons;

class KnowledgePanelWorldMapCard extends StatelessWidget {
const KnowledgePanelWorldMapCard(this.mapElement);
Expand Down Expand Up @@ -55,47 +56,60 @@ class KnowledgePanelWorldMapCard extends StatelessWidget {
userAgentPackageName: 'org.openfoodfacts.app',
),
MarkerLayer(markers: markers),
RichAttributionWidget(
animationConfig: const ScaleRAWA(),
showFlutterMapAttribution: false,
attributions: <SourceAttribution>[
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => LaunchUrlHelper.launchURL(
'https://www.openstreetmap.org/copyright',
),
),
],
),
];

final String? kpTitle = _getTitle(context);

return Padding(
padding: const EdgeInsetsDirectional.only(bottom: MEDIUM_SPACE),
child: SizedBox(
height: 200,
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<Widget>(
builder: (_) => WorldMapPage(
title: _getTitle(context),
mapOptions: _generateMapOptions(
coordinates: coordinates,
markerSize: markerSize,
initialZoom: 12.0,
interactive: true,
child: Semantics(
label: AppLocalizations.of(context)
.knowledge_panel_world_map_accessibility_label(kpTitle ?? '?'),
image: true,
button: true,
child: SizedBox(
width: double.infinity,
height: 200.0,
child: Stack(
children: <Widget>[
Positioned.fill(
child: IgnorePointer(
ignoring: true,
child: FlutterMap(
options: mapOptions,
children: <Widget>[
...children,
const _ExpandMapIcon(),
],
),
children: children,
),
),
);
},
child: IgnorePointer(
ignoring: true,
child: FlutterMap(
options: mapOptions,
children: children,
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<Widget>(
builder: (_) {
return WorldMapPage(
title: kpTitle,
mapOptions: _generateMapOptions(
coordinates: coordinates,
markerSize: markerSize,
initialZoom: 12.0,
interactive: true,
),
children: children,
);
},
),
);
},
),
),
),
],
),
),
),
Expand Down Expand Up @@ -155,3 +169,32 @@ class KnowledgePanelWorldMapCard extends StatelessWidget {
);
}
}

class _ExpandMapIcon extends StatelessWidget {
const _ExpandMapIcon();

@override
Widget build(BuildContext context) {
return const Align(
alignment: AlignmentDirectional.bottomEnd,
child: Padding(
padding: EdgeInsetsDirectional.all(
VERY_SMALL_SPACE,
),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.black38,
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsetsDirectional.all(SMALL_SPACE),
child: icons.Expand(
size: 15.0,
color: Colors.white,
),
),
),
),
);
}
}
13 changes: 13 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3495,5 +3495,18 @@
"photo_undo_action": "Undo the previous action",
"@photo_undo_action": {
"description": "Button to undo the previous action on a photo"
},
"knowledge_panel_world_map_accessibility_label": "A world map of {location}",
"@knowledge_panel_world_map_accessibility_label": {
"description": "Accessibility label for the world map in the knowledge panel",
"placeholders": {
"location": {
"type": "String"
}
}
},
"open_street_map_contributor_attribution": "OpenStreetMap contributors",
"@open_street_map_contributor_attribution": {
"description": "Attribution for OpenStreetMap contributors"
}
}
29 changes: 27 additions & 2 deletions packages/smooth_app/lib/pages/product/world_map_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

class WorldMapPage extends StatelessWidget {
Expand All @@ -18,14 +20,37 @@ class WorldMapPage extends StatelessWidget {
Widget build(BuildContext context) {
return SmoothScaffold(
appBar: AppBar(
title: Text(title ?? ''),
title: Text(
title ?? '',
maxLines: 2,
),
backgroundColor:
AppBarTheme.of(context).backgroundColor?.withValues(alpha: 0.8),
),
extendBodyBehindAppBar: true,
body: FlutterMap(
options: mapOptions,
children: children,
children: <Widget>[
...children,
SafeArea(
child: RichAttributionWidget(
animationConfig: const ScaleRAWA(),
alignment: Directionality.of(context) == TextDirection.ltr
? AttributionAlignment.bottomRight
: AttributionAlignment.bottomLeft,
showFlutterMapAttribution: false,
attributions: <SourceAttribution>[
TextSourceAttribution(
AppLocalizations.of(context)
.open_street_map_contributor_attribution,
onTap: () => LaunchUrlHelper.launchURL(
'https://www.openstreetmap.org/copyright',
),
),
],
),
),
],
),
);
}
Expand Down

0 comments on commit 5186bc6

Please sign in to comment.