Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] develop from openfoodfacts:develop #78

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class KnowledgePanelCard extends StatelessWidget {
final UserPreferences userPreferences = context.watch<UserPreferences>();
final KnowledgePanel? panel =
KnowledgePanelsBuilder.getKnowledgePanel(product, panelId);

if (panel == null) {
return EMPTY_WIDGET;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels_builder.dart';

Expand Down Expand Up @@ -47,9 +48,13 @@ class KnowledgePanelExpandedCard extends StatelessWidget {
}
}
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: elementWidgets,
return Provider<KnowledgePanel>(
lazy: true,
create: (_) => panel,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: elementWidgets,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'package:flutter/material.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';

class KnowledgePanelWorldMapCard extends StatelessWidget {
const KnowledgePanelWorldMapCard(this.mapElement);
Expand All @@ -20,6 +22,7 @@ class KnowledgePanelWorldMapCard extends StatelessWidget {
const double markerSize = 30;
final List<Marker> markers = <Marker>[];
final List<LatLng> coordinates = <LatLng>[];

void addCoordinate(final LatLng latLng) {
coordinates.add(latLng);
markers.add(
Expand All @@ -40,51 +43,102 @@ class KnowledgePanelWorldMapCard extends StatelessWidget {
}
}

final MapOptions mapOptions = _generateMapOptions(
coordinates: coordinates,
markerSize: markerSize,
interactive: false,
);

final List<Widget> children = <Widget>[
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
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',
),
),
],
),
];

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,
),
children: children,
),
),
);
},
child: IgnorePointer(
ignoring: true,
child: FlutterMap(
options: mapOptions,
children: children,
),
),
),
),
);
}

MapOptions _generateMapOptions({
required List<LatLng> coordinates,
required double markerSize,
double initialZoom = 6.0,
bool interactive = false,
}) {
final MapOptions mapOptions;
if (coordinates.length == 1) {
mapOptions = MapOptions(
initialCenter: coordinates.first,
initialZoom: 6.0,
initialZoom: initialZoom,
interactionOptions: InteractionOptions(
flags: interactive ? InteractiveFlag.all : InteractiveFlag.none,
),
);
} else {
mapOptions = MapOptions(
initialCameraFit: CameraFit.coordinates(
coordinates: coordinates,
maxZoom: 13.0,
forceIntegerZoomLevel: true,
padding: const EdgeInsets.all(markerSize),
padding: EdgeInsets.all(markerSize),
),
interactionOptions: InteractionOptions(
flags: interactive ? InteractiveFlag.all : InteractiveFlag.none,
),
);
}
return Padding(
padding: const EdgeInsetsDirectional.only(bottom: MEDIUM_SPACE),
child: SizedBox(
height: 200,
child: FlutterMap(
options: mapOptions,
children: <Widget>[
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'org.openfoodfacts.app',
),
MarkerLayer(markers: markers),
RichAttributionWidget(
popupInitialDisplayDuration: const Duration(seconds: 5),
animationConfig: const ScaleRAWA(),
showFlutterMapAttribution: false,
attributions: <SourceAttribution>[
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => LaunchUrlHelper.launchURL(
'https://www.openstreetmap.org/copyright',
),
),
],
),
],
),
),
);
return mapOptions;
}

String? _getTitle(BuildContext context) {
try {
return context.read<KnowledgePanel>().titleElement?.title;
} catch (_) {
return null;
}
}

@override
Expand Down
32 changes: 32 additions & 0 deletions packages/smooth_app/lib/pages/product/world_map_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

class WorldMapPage extends StatelessWidget {
const WorldMapPage({
required this.title,
required this.mapOptions,
required this.children,
super.key,
});

final String? title;
final MapOptions mapOptions;
final List<Widget> children;

@override
Widget build(BuildContext context) {
return SmoothScaffold(
appBar: AppBar(
title: Text(title ?? ''),
backgroundColor:
AppBarTheme.of(context).backgroundColor?.withValues(alpha: 0.8),
),
extendBodyBehindAppBar: true,
body: FlutterMap(
options: mapOptions,
children: children,
),
);
}
}
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/pages/scan/scan_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class _ScanHeaderState extends State<ScanHeader> {
borderRadius: BorderRadius.all(Radius.circular(18.0)),
),
),
iconColor: WidgetStateProperty.all<Color>(
Theme.of(context).colorScheme.onPrimary,
),
foregroundColor: WidgetStateProperty.all<Color>(
Theme.of(context).colorScheme.onPrimary,
),
Expand Down
Loading