Skip to content

Commit

Permalink
Improved example app
Browse files Browse the repository at this point in the history
Deprecated `BaseRegion` & `DownloadableRegion` `.when` & `.maybeWhen`
Improved documentation
  • Loading branch information
JaffaKetchup committed Sep 21, 2024
1 parent 3fe9e63 commit 702dfb5
Show file tree
Hide file tree
Showing 28 changed files with 860 additions and 723 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import 'src/screens/download/download.dart';
import 'src/screens/import/import.dart';
import 'src/screens/initialisation_error/initialisation_error.dart';
import 'src/screens/main/main.dart';
import 'src/shared/state/region_selection_provider.dart';
import 'src/screens/main/secondary_view/contents/home/components/stores_list/state/export_selection_provider.dart';
import 'src/screens/store_editor/store_editor.dart';
import 'src/shared/misc/shared_preferences.dart';
import 'src/shared/state/general_provider.dart';
import 'src/shared/state/region_selection_provider.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _ConfigureDownloadPopupState extends State<ConfigureDownloadPopup> {
super.didChangeDependencies();

final provider = context.read<RegionSelectionProvider>();
const FMTCStore('')
/*const FMTCStore('')
.download
.check(
region ??= provider.region!.toDownloadable(
Expand All @@ -41,7 +41,7 @@ class _ConfigureDownloadPopupState extends State<ConfigureDownloadPopup> {
options: TileLayer(),
),
)
.then((v) => setState(() => maxTiles = v));
.then((v) => setState(() => maxTiles = v));*/
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class CustomPolygonSnappingIndicator extends StatelessWidget {

@override
Widget build(BuildContext context) {
final coords = context
.select<RegionSelectionProvider, List<LatLng>>((p) => p.coordinates);
final coords = context.select<RegionSelectionProvider, List<LatLng>>(
(p) => p.currentConstructingCoordinates,
);

return MarkerLayer(
markers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,99 +7,136 @@ import 'package:provider/provider.dart';
import '../../../../../shared/state/region_selection_provider.dart';

class RegionShape extends StatelessWidget {
const RegionShape({
super.key,
});
const RegionShape({super.key});

static const _fullWorldPolygon = [
LatLng(-90, 180),
LatLng(90, 180),
LatLng(90, -180),
LatLng(-90, -180),
];

@override
Widget build(BuildContext context) => Consumer<RegionSelectionProvider>(
builder: (context, provider, _) {
if (provider.regionType == RegionType.line) {
if (provider.coordinates.isEmpty) return const SizedBox.shrink();
return PolylineLayer(
polylines: [
Polyline(
points: [
...provider.coordinates,
provider.currentNewPointPos,
builder: (context, provider, _) => Stack(
fit: StackFit.expand,
children: [
for (final MapEntry(key: region, value: color)
in provider.constructedRegions.entries)
switch (region) {
RectangleRegion(:final bounds) => PolygonLayer(
polygons: [
Polygon(
points: [
bounds.northWest,
bounds.northEast,
bounds.southEast,
bounds.southWest,
],
color: color.toColor(),
),
],
),
CircleRegion(:final center, :final radius) => CircleLayer(
circles: [
CircleMarker(
point: center,
radius: radius * 1000,
useRadiusInMeter: true,
color: color.toColor(),
),
],
),
LineRegion(:final line, :final radius) => PolylineLayer(
polylines: [
Polyline(
points: line,
strokeWidth: radius * 2,
useStrokeWidthInMeter: true,
color: color.toColor(),
),
],
),
CustomPolygonRegion(:final outline) => PolygonLayer(
polygons: [
Polygon(
points: outline,
color: color.toColor(),
),
],
),
MultiRegion() => throw UnsupportedError(
'Cannot support `MultiRegion`s here',
),
},
if (provider.currentConstructingCoordinates.isNotEmpty)
if (provider.currentRegionType == RegionType.line)
PolylineLayer(
polylines: [
Polyline(
points: [
...provider.currentConstructingCoordinates,
provider.currentNewPointPos,
],
color: Colors.white.withOpacity(2 / 3),
strokeWidth: provider.lineRadius * 2,
useStrokeWidthInMeter: true,
),
],
borderColor: Colors.black,
borderStrokeWidth: 2,
color: Colors.green.withOpacity(2 / 3),
strokeWidth: provider.lineRadius * 2,
useStrokeWidthInMeter: true,
),
],
);
}

final List<LatLng> holePoints;
if (provider.coordinates.isEmpty) {
holePoints = [];
} else {
switch (provider.regionType) {
case RegionType.square:
final bounds = LatLngBounds.fromPoints(
provider.coordinates.length == 1
? [provider.coordinates[0], provider.currentNewPointPos]
: provider.coordinates,
);
holePoints = [
bounds.northWest,
bounds.northEast,
bounds.southEast,
bounds.southWest,
];
case RegionType.circle:
holePoints = CircleRegion(
provider.coordinates[0],
const Distance(roundResult: false).distance(
provider.coordinates[0],
provider.coordinates.length == 1
? provider.currentNewPointPos
: provider.coordinates[1],
) /
1000,
).toOutline().toList();
case RegionType.customPolygon:
holePoints = provider.isCustomPolygonComplete
? provider.coordinates
: [
...provider.coordinates,
if (provider.customPolygonSnap)
provider.coordinates.first
else
provider.currentNewPointPos,
];
case RegionType.line:
throw UnsupportedError('Unreachable.');
}
}

return PolygonLayer(
key: UniqueKey(),
polygons: [
Polygon(
points: [
const LatLng(-90, 180),
const LatLng(90, 180),
const LatLng(90, -180),
const LatLng(-90, -180),
],
holePointsList: holePoints.length < 3
? null
: [
if (Polygon.isClockwise(holePoints))
holePoints
else
holePoints.reversed.toList(),
)
else
PolygonLayer(
polygons: [
Polygon(
points: _fullWorldPolygon,
holePointsList: [
switch (provider.currentRegionType) {
RegionType.circle => CircleRegion(
provider.currentConstructingCoordinates[0],
const Distance(roundResult: false).distance(
provider.currentConstructingCoordinates[0],
provider.currentConstructingCoordinates
.length ==
1
? provider.currentNewPointPos
: provider
.currentConstructingCoordinates[1],
) /
1000,
).toOutline().toList(),
RegionType.rectangle => RectangleRegion(
LatLngBounds.fromPoints(
provider.currentConstructingCoordinates
.length ==
1
? [
provider
.currentConstructingCoordinates[0],
provider.currentNewPointPos,
]
: provider.currentConstructingCoordinates,
),
).toOutline().toList(),
RegionType.customPolygon => [
...provider.currentConstructingCoordinates,
if (provider.customPolygonSnap)
provider.currentConstructingCoordinates.first
else
provider.currentNewPointPos,
],
_ => throw UnsupportedError('Unreachable.'),
},
],
borderColor: Colors.black,
borderStrokeWidth: 2,
color: Theme.of(context).colorScheme.surface.withOpacity(0.5),
),
],
);
},
borderColor: Colors.black,
borderStrokeWidth: 2,
color: Theme.of(context)
.colorScheme
.surface
.withOpacity(0.5),
),
],
),
],
),
);
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 702dfb5

Please sign in to comment.