Skip to content

Commit

Permalink
Add PermissionHandler.open_app_settings() (#3375)
Browse files Browse the repository at this point in the history
* return None if invoke_method returns "null"

* PermissionHandler: open_app_settings

* Cleanup + Refactoring

* MapLayer: initial commit

* Cleanup Map*

* Map: rename points/location to coordinates
  • Loading branch information
ndonkoHenri authored May 29, 2024
1 parent 7855121 commit 4f4bd9c
Show file tree
Hide file tree
Showing 33 changed files with 316 additions and 371 deletions.
2 changes: 2 additions & 0 deletions packages/flet/lib/flet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export 'src/utils/material_state.dart';
export 'src/utils/menu.dart';
export 'src/utils/mouse.dart';
export 'src/utils/numbers.dart';
export 'src/utils/others.dart';
export 'src/utils/platform_utils_non_web.dart'
if (dart.library.js) "src/utils/platform_utils_web.dart";
export 'src/utils/responsive.dart';
export 'src/utils/shadows.dart';
export 'src/utils/strings.dart';
export 'src/utils/text.dart';
export 'src/utils/textfield.dart';
export 'src/utils/theme.dart';
29 changes: 16 additions & 13 deletions packages/flet_audio_recorder/lib/src/audio_recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,21 @@ class _AudioRecorderControlState extends State<AudioRecorderControl>
switch (methodName) {
case "start_recording":
if (await recorder!.hasPermission()) {
await recorder!.start(
RecordConfig(
encoder: audioEncoder,
bitRate: bitRate,
sampleRate: sampleRate,
numChannels: numChannels,
autoGain: autoGain,
echoCancel: cancelEcho,
noiseSuppress: suppressNoise,
),
path: args["outputPath"] ??
""); // FIX: a better default value just in case
if (args["outputPath"] != null) {
await recorder!.start(
RecordConfig(
encoder: audioEncoder,
bitRate: bitRate,
sampleRate: sampleRate,
numChannels: numChannels,
autoGain: autoGain,
echoCancel: cancelEcho,
noiseSuppress: suppressNoise,
),
path: args["outputPath"]!);
return "true";
}
break;
}
return null;
case "stop_recording":
Expand All @@ -129,7 +132,7 @@ class _AudioRecorderControlState extends State<AudioRecorderControl>
parseAudioEncoder(args["encoder"]) ?? AudioEncoder.wav);
return isSupported.toString();
}
return null;
break;
case "is_paused":
debugPrint("AudioRecorder.isPaused($hashCode)");
bool isPaused = await recorder!.isPaused();
Expand Down
6 changes: 3 additions & 3 deletions packages/flet_geolocator/lib/src/geolocator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ class _GeolocatorControlState extends State<GeolocatorControl>
var opened = await Geolocator.openAppSettings();
return opened.toString();
}
return "false";
break;
case "open_location_settings":
if (!kIsWeb) {
var opened = await Geolocator.openLocationSettings();
return opened.toString();
}
return "false";
break;
case "get_last_known_position":
if (!kIsWeb) {
Position? position = await Geolocator.getLastKnownPosition();
return positionToJson(position);
}
return null;
break;
case "get_current_position":
Position currentPosition = await Geolocator.getCurrentPosition(
desiredAccuracy: parseLocationAccuracy(
Expand Down
8 changes: 4 additions & 4 deletions packages/flet_map/lib/src/circle_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class CircleLayerControl extends StatelessWidget with FletStoreMixin {

@override
Widget build(BuildContext context) {
debugPrint("CircleLayerControl build: ${control.id} (${control.hashCode})");
debugPrint("CircleLayerControl build: ${control.id}");

return withControls(control.childIds, (context, circlesView) {
debugPrint("CircleLayerControlState build: ${control.id}");

var circles = circlesView.controlViews
.where(
(c) => c.control.type == "mapcirclemarker" && c.control.isVisible)
.where((c) =>
c.control.type == "map_circle_marker" && c.control.isVisible)
.map((circle) {
return CircleMarker(
point: parseLatLng(circle.control, "location")!,
point: parseLatLng(circle.control, "coordinates")!,
color: circle.control
.attrColor("color", context, const Color(0xFF00FF00))!,
borderColor: circle.control
Expand Down
14 changes: 7 additions & 7 deletions packages/flet_map/lib/src/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@ CreateControlFactory createControl = (CreateControlArgs args) {
parentDisabled: args.parentDisabled,
backend: args.backend,
);
case "maprichattribution":
case "map_rich_attribution":
return RichAttributionControl(
parent: args.parent,
control: args.control,
children: args.children,
backend: args.backend,
);
case "mapsimpleattribution":
case "map_simple_attribution":
return SimpleAttributionControl(
parent: args.parent,
control: args.control,
children: args.children,
backend: args.backend,
);
case "maptilelayer":
case "map_tile_layer":
return TileLayerControl(
parent: args.parent,
control: args.control,
backend: args.backend,
);
case "mapmarkerlayer":
case "map_marker_layer":
return MarkerLayerControl(
parent: args.parent,
control: args.control,
children: args.children,
parentDisabled: args.parentDisabled,
);
case "mapcirclelayer":
case "map_circle_layer":
return CircleLayerControl(
parent: args.parent,
control: args.control,
children: args.children,
);
case "mappolygonlayer":
case "map_polygon_layer":
return PolygonLayerControl(
parent: args.parent,
control: args.control,
children: args.children,
);
case "mappolylinelayer":
case "map_polyline_layer":
return PolylineLayerControl(
parent: args.parent,
control: args.control,
Expand Down
18 changes: 8 additions & 10 deletions packages/flet_map/lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
bool disabled = widget.control.isDisabled || widget.parentDisabled;

List<String> acceptedChildrenTypes = [
"mapcirclelayer",
"maptilelayer",
"mappolygonlayer",
"mappolylinelayer",
"mapmarkerlayer",
"maprichattribution",
"mapsimpleattribution"
"map_circle_layer",
"map_tile_layer",
"map_polygon_layer",
"map_polyline_layer",
"map_marker_layer",
"map_rich_attribution",
"map_simple_attribution"
];
var ctrls = widget.children
.where((c) => c.isVisible && (acceptedChildrenTypes.contains(c.type)))
Expand All @@ -58,7 +58,7 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {

return withControls(widget.control.childIds, (context, configurationsView) {
var configuration = configurationsView.controlViews
.where((c) => c.control.type == "mapconfiguration")
.where((c) => c.control.type == "map_configuration")
.map((config) {
var onTap = config.control.attrBool("onTap", false)!;
var onLongPress = config.control.attrBool("onLongPress", false)!;
Expand All @@ -69,8 +69,6 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
return MapOptions(
initialCenter: parseLatLng(
config.control, "initialCenter", const LatLng(50.5, 30.51))!,
applyPointerTranslucencyToLayers: config.control
.attrBool("applyPointerTranslucencyToLayers", true)!,
backgroundColor: config.control
.attrColor("backgroundColor", context, const Color(0x00000000))!,
initialRotation: config.control.attrDouble("initialRotation", 0.0)!,
Expand Down
6 changes: 3 additions & 3 deletions packages/flet_map/lib/src/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class MarkerLayerControl extends StatelessWidget with FletStoreMixin {

@override
Widget build(BuildContext context) {
debugPrint("MarkerLayerControl build: ${control.id} (${control.hashCode})");
debugPrint("MarkerLayerControl build: ${control.id}");

return withControls(control.childIds, (context, markersView) {
debugPrint("MarkerLayerControlState build: ${control.id}");

var markers = markersView.controlViews
.where((c) => c.control.type == "mapmarker" && c.control.isVisible)
.where((c) => c.control.type == "map_marker" && c.control.isVisible)
.map((marker) {
return Marker(
point: parseLatLng(marker.control, "location")!,
point: parseLatLng(marker.control, "coordinates")!,
rotate: marker.control.attrBool("rotate"),
height: marker.control.attrDouble("height", 30)!,
width: marker.control.attrDouble("width", 30)!,
Expand Down
27 changes: 11 additions & 16 deletions packages/flet_map/lib/src/polygon_layer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:flet/flet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
Expand All @@ -20,23 +19,20 @@ class PolygonLayerControl extends StatelessWidget with FletStoreMixin {

@override
Widget build(BuildContext context) {
debugPrint(
"PolygonLayerControl build: ${control.id} (${control.hashCode})");
debugPrint("PolygonLayerControl build: ${control.id}");

return withControls(control.childIds, (context, polygonsView) {
debugPrint("PolygonLayerControlState build: ${control.id}");

var polygons = polygonsView.controlViews
.where((c) =>
c.control.type == "mappolygonmarker" && c.control.isVisible)
c.control.type == "map_polygon_marker" && c.control.isVisible)
.map((polygon) {
var strokeCap = StrokeCap.values.firstWhereOrNull((e) =>
e.name.toLowerCase() ==
control.attrString("strokeCap", "")!.toLowerCase());
var strokeJoin = StrokeJoin.values.firstWhereOrNull((e) =>
e.name.toLowerCase() ==
control.attrString("strokeJoin", "")!.toLowerCase());
var points = polygon.control.attrString("points");
var strokeCap = parseStrokeCap(
polygon.control.attrString("strokeCap"), StrokeCap.round)!;
var strokeJoin = parseStrokeJoin(
polygon.control.attrString("strokeJoin"), StrokeJoin.round)!;
var coordinates = polygon.control.attrString("coordinates");
return Polygon(
borderStrokeWidth:
polygon.control.attrDouble("borderStrokeWidth", 0)!,
Expand All @@ -45,18 +41,17 @@ class PolygonLayerControl extends StatelessWidget with FletStoreMixin {
color: polygon.control.attrColor("color", context) ??
const Color(0xFF00FF00),
isDotted: polygon.control.attrBool("dotted", false)!,
isFilled: polygon.control.attrBool("filled", false)!,
disableHolesBorder:
polygon.control.attrBool("disableHolesBorder", false)!,
rotateLabel: polygon.control.attrBool("rotateLabel", false)!,
label: polygon.control.attrString("label"),
labelStyle: parseTextStyle(
Theme.of(context), polygon.control, "labelStyle") ??
const TextStyle(),
strokeCap: strokeCap ?? StrokeCap.round,
strokeJoin: strokeJoin ?? StrokeJoin.round,
points: points != null
? (jsonDecode(points) as List)
strokeCap: strokeCap,
strokeJoin: strokeJoin,
points: coordinates != null
? (jsonDecode(coordinates) as List)
.map((e) => latLngFromJson(e))
.toList()
: []);
Expand Down
32 changes: 13 additions & 19 deletions packages/flet_map/lib/src/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,30 @@ class PolylineLayerControl extends StatelessWidget with FletStoreMixin {

@override
Widget build(BuildContext context) {
debugPrint(
"PolylineLayerControl build: ${control.id} (${control.hashCode})");
debugPrint("PolylineLayerControl build: ${control.id}");

return withControls(control.childIds, (context, polylinesView) {
debugPrint("PolylineLayerControlState build: ${control.id}");

var polylines = polylinesView.controlViews
.where((c) =>
c.control.type == "mappolylinemarker" && c.control.isVisible)
c.control.type == "map_polyline_marker" && c.control.isVisible)
.map((polyline) {
var strokeCap = StrokeCap.values.firstWhereOrNull((e) =>
e.name.toLowerCase() ==
control.attrString("strokeCap", "")!.toLowerCase());
var strokeJoin = StrokeJoin.values.firstWhereOrNull((e) =>
e.name.toLowerCase() ==
control.attrString("strokeJoin", "")!.toLowerCase());
var points = polyline.control.attrString("points");
var coordinates = polyline.control.attrString("coordinates");
var colorsStop = polyline.control.attrString("colorsStop");
var gradientColors = polyline.control.attrString("gradientColors");
return Polyline(
borderStrokeWidth:
polyline.control.attrDouble("borderStrokeWidth", 0)!,
borderColor: polyline.control.attrColor("borderColor", context) ??
const Color(0xFFFFFF00),
color: polyline.control.attrColor("color", context) ??
const Color(0xFF00FF00),
borderColor: polyline.control
.attrColor("borderColor", context, const Color(0xFFFFFF00))!,
color: polyline.control
.attrColor("color", context, const Color(0xFF00FF00))!,
isDotted: polyline.control.attrBool("dotted", false)!,
strokeCap: strokeCap ?? StrokeCap.round,
strokeJoin: strokeJoin ?? StrokeJoin.round,
strokeCap: parseStrokeCap(
polyline.control.attrString("strokeCap"), StrokeCap.round)!,
strokeJoin: parseStrokeJoin(
polyline.control.attrString("strokeJoin"), StrokeJoin.round)!,
strokeWidth: polyline.control.attrDouble("strokeWidth", 1.0)!,
useStrokeWidthInMeter:
polyline.control.attrBool("useStrokeWidthInMeter", false)!,
Expand All @@ -64,16 +59,15 @@ class PolylineLayerControl extends StatelessWidget with FletStoreMixin {
.whereNotNull()
.toList()
: null,
points: points != null
? (jsonDecode(points) as List)
points: coordinates != null
? (jsonDecode(coordinates) as List)
.map((e) => latLngFromJson(e))
.toList()
: []);
}).toList();

return PolylineLayer(
polylines: polylines,
polylineCulling: control.attrBool("polylineCulling", false)!,
);
});
}
Expand Down
5 changes: 2 additions & 3 deletions packages/flet_map/lib/src/rich_attribution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ class _RichAttributionControlState extends State<RichAttributionControl>
with FletStoreMixin {
@override
Widget build(BuildContext context) {
debugPrint(
"RichAttributionControl build: ${widget.control.id} (${widget.control.hashCode})");
debugPrint("RichAttributionControl build: ${widget.control.id}");

return withControls(widget.control.childIds, (context, attributionsView) {
debugPrint("RichAttributionControlState build: ${widget.control.id}");

var attributions = attributionsView.controlViews
.map((v) => v.control)
.where((c) => c.type == "maptextsourceattribution" && c.isVisible)
.where((c) => c.type == "map_text_source_attribution" && c.isVisible)
.map((Control itemCtrl) {
return TextSourceAttribution(
itemCtrl.attrs["text"] ?? "Placeholder Text",
Expand Down
3 changes: 1 addition & 2 deletions packages/flet_map/lib/src/simple_attribution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class SimpleAttributionControl extends StatefulWidget {
class _SimpleAttributionControlState extends State<SimpleAttributionControl> {
@override
Widget build(BuildContext context) {
debugPrint(
"SimpleAttributionControl build: ${widget.control.id} (${widget.control.hashCode})");
debugPrint("SimpleAttributionControl build: ${widget.control.id}");

return SimpleAttributionWidget(
source: Text(widget.control.attrString("text", "Placeholder Text")!),
Expand Down
3 changes: 1 addition & 2 deletions packages/flet_map/lib/src/text_source_attribution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class TextSourceAttributionControl extends StatelessWidget {

@override
Widget build(BuildContext context) {
debugPrint(
"TextSourceAttributionControl build: ${control.id} (${control.hashCode})");
debugPrint("TextSourceAttributionControl build: ${control.id}");

return TextSourceAttribution(
control.attrString("text", "Placeholder Text")!,
Expand Down
2 changes: 1 addition & 1 deletion packages/flet_map/lib/src/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TileLayerControl extends StatelessWidget with FletStoreMixin {

@override
Widget build(BuildContext context) {
debugPrint("TileLayerControl build: ${control.id} (${control.hashCode})");
debugPrint("TileLayerControl build: ${control.id}");

return withPageArgs((context, pageArgs) {
var errorImageSrc = control.attrString("errorImageSrc");
Expand Down
Loading

0 comments on commit 4f4bd9c

Please sign in to comment.