Skip to content

Commit ea100c7

Browse files
authored
Merge pull request #520 from EnsembleUI/newMaps
New maps
2 parents 4e0e84e + 1370b90 commit ea100c7

File tree

8 files changed

+80
-25
lines changed

8 files changed

+80
-25
lines changed

.ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ target 'Runner' do
3131
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
3232

3333
pod 'FlutterPluginRegistrant', :path => File.join('Flutter', 'FlutterPluginRegistrant'), :inhibit_warnings => true
34-
pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '10.7.0'
34+
pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '10.9.0'
3535
end
3636

3737
post_install do |installer|

assets/schema/ensemble_schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,7 +3061,15 @@
30613061
}
30623062
}
30633063
},
3064-
"scrollableOverlay": {
3064+
"markerOverlayMaxWidth": {
3065+
"type": "integer",
3066+
"description": "Marker overlay stretches to fill available horizontal space. Use this to cap its width on larger screens. (default 500)"
3067+
},
3068+
"markerOverlayMaxHeight": {
3069+
"type": "integer",
3070+
"description": "Set the max height of the marker overlay. (default: 50% of the screen height)"
3071+
},
3072+
"scrollableMarkerOverlay": {
30653073
"type": "boolean",
30663074
"description": "If using overlay and there are more than one marker, swiping left/right within the overlay will navigate to next/previous marker"
30673075
},

lib/framework/data_context.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,23 @@ class Formatter with Invokable {
445445
'prettyDateTime': (input) => InvokablePrimitive.prettyDateTime(input),
446446
'prettyCurrency': (input) => InvokablePrimitive.prettyCurrency(input),
447447
'prettyDuration': (input) =>
448-
InvokablePrimitive.prettyDuration(input, locale: locale)
448+
InvokablePrimitive.prettyDuration(input, locale: locale),
449+
'pluralize': pluralize
449450
};
450451
}
451452

452453
@override
453454
Map<String, Function> setters() {
454455
return {};
455456
}
457+
458+
String pluralize(String singularText, int? count, [pluralText]) {
459+
count ??= 1;
460+
if (count <= 1) {
461+
return singularText;
462+
}
463+
return pluralText ?? '${singularText}s';
464+
}
456465
}
457466

458467
class UserInfo with Invokable {

lib/framework/widget/widget.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,22 @@ abstract class WidgetState<W extends HasController> extends BaseWidgetState<W> {
2727
return const SizedBox.shrink();
2828
}
2929
Widget rtn = buildWidget(context);
30+
31+
// wrap inside Align if specified
32+
if ((widget.controller as WidgetController).alignToParent != null) {
33+
rtn = Align(
34+
alignment: (widget.controller as WidgetController).alignToParent!,
35+
child: rtn);
36+
}
37+
3038
if ((widget.controller as WidgetController).expanded == true) {
3139
/// Important notes:
3240
/// 1. If the Column/Row is scrollable, putting Expanded on the child will cause layout exception
3341
/// 2. If Column/Row is inside a parent without height/width constraint, it will collapse its size.
3442
/// So if we put Expanded on the Column's child, layout exception will occur
3543
rtn = Expanded(child: rtn);
3644
}
45+
3746
return rtn;
3847
}
3948
throw LanguageError("Wrong usage of widget controller!");

lib/widget/helpers/controllers.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ abstract class WidgetController extends Controller {
1212
bool visible = true;
1313
String? id; // do we need this?
1414

15+
// wrap widget inside an Align widget
16+
Alignment? alignToParent;
17+
1518
// optional label/labelHint for use in Forms
1619
String? label;
1720
String? description;
@@ -30,6 +33,7 @@ abstract class WidgetController extends Controller {
3033
return {
3134
'expanded': (value) => expanded = Utils.getBool(value, fallback: false),
3235
'visible': (value) => visible = Utils.getBool(value, fallback: true),
36+
'alignToParent': (value) => alignToParent = Utils.getAlignment(value),
3337
'label': (value) => label = Utils.optionalString(value),
3438
'description': (value) => description = Utils.optionalString(value),
3539
'labelHint': (value) => labelHint = Utils.optionalString(value),

lib/widget/maps/maps.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Maps extends StatefulWidget
3333
return {
3434
'width': (value) => _controller.width = Utils.optionalInt(value),
3535
'height': (value) => _controller.height = Utils.optionalInt(value),
36+
'markerOverlayMaxWidth': (value) => _controller.markerOverlayMaxWidth =
37+
Utils.getInt(value, fallback: _controller.markerOverlayMaxWidth),
38+
'markerOverlayMaxHeight': (value) => _controller.markerOverlayMaxHeight =
39+
Utils.getInt(value, fallback: _controller.markerOverlayMaxHeight),
3640
'initialCameraPosition': (cameraPosition) =>
3741
_controller.initialCameraPosition = cameraPosition,
3842
'autoZoom': (value) => _controller.autoZoom =
@@ -46,8 +50,9 @@ class Maps extends StatefulWidget
4650
fallback: _controller.includeCurrentLocationInAutoZoom),
4751
'mapType': (value) => _controller.mapType = value,
4852
'markers': (markerData) => setMarkers(markerData),
49-
'scrollableOverlay': (value) => _controller.scrollableOverlay =
50-
Utils.getBool(value, fallback: _controller.scrollableOverlay),
53+
'scrollableMarkerOverlay': (value) => _controller
54+
.scrollableMarkerOverlay =
55+
Utils.getBool(value, fallback: _controller.scrollableMarkerOverlay),
5156
'autoSelect': (value) => _controller.autoSelect =
5257
Utils.getBool(value, fallback: _controller.autoSelect),
5358
'onMapCreated': (action) => _controller.onMapCreated =
@@ -108,11 +113,15 @@ class MyController extends WidgetController with LocationCapability {
108113
int? height;
109114
int? width;
110115

116+
// overlay fill available horizontal space, so cap max width/height
117+
int markerOverlayMaxWidth = 500;
118+
int markerOverlayMaxHeight = 500;
119+
bool scrollableMarkerOverlay = false;
120+
111121
final defaultCameraLatLng = const LatLng(37.773972, -122.431297);
112122
final double defaultCameraZoom = 10;
113123
dynamic initialCameraPosition;
114124

115-
bool scrollableOverlay = false;
116125
bool autoSelect = true;
117126

118127
bool autoZoom = false;

lib/widget/maps/maps_overlay.dart

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import 'package:pointer_interceptor/pointer_interceptor.dart';
55

66
class MapsOverlay extends StatelessWidget {
77
const MapsOverlay(this.overlayWidget,
8-
{super.key, this.scrollable = true, this.onScrolled});
8+
{super.key,
9+
this.scrollable = true,
10+
this.onScrolled,
11+
this.maxWidth,
12+
this.maxHeight});
913
final Widget overlayWidget;
14+
final int? maxWidth;
15+
final int? maxHeight;
1016
final bool scrollable;
1117
final OverlayScrollCallback? onScrolled;
1218

@@ -17,23 +23,31 @@ class MapsOverlay extends StatelessWidget {
1723
var content =
1824
kIsWeb ? PointerInterceptor(child: overlayWidget) : overlayWidget;
1925

20-
return Positioned(
21-
right: 0,
22-
left: 0,
23-
bottom: 0,
24-
child: scrollable && onScrolled != null
25-
? GestureDetector(
26-
onHorizontalDragEnd: (details) {
27-
if (details.primaryVelocity != null) {
28-
if (details.primaryVelocity! < 0) {
29-
onScrolled!(true); // next marker
30-
} else if (details.primaryVelocity! > 0) {
31-
onScrolled!(false); // previous marker
32-
}
33-
}
34-
},
35-
child: content)
36-
: content);
26+
var gestureWrapper = scrollable && onScrolled != null
27+
? GestureDetector(
28+
onHorizontalDragEnd: (details) {
29+
if (details.primaryVelocity != null) {
30+
if (details.primaryVelocity! < 0) {
31+
onScrolled!(true); // next marker
32+
} else if (details.primaryVelocity! > 0) {
33+
onScrolled!(false); // previous marker
34+
}
35+
}
36+
},
37+
child: content)
38+
: content;
39+
40+
return Align(
41+
alignment: Alignment.bottomCenter,
42+
child: ConstrainedBox(
43+
constraints: BoxConstraints(
44+
maxWidth: maxWidth?.toDouble() ?? 500,
45+
maxHeight: maxHeight?.toDouble() ?? Device().screenHeight / 2),
46+
// always stretch the content, up to the constraints
47+
child: SizedBox(
48+
width: double.infinity,
49+
child: gestureWrapper,
50+
)));
3751
}
3852
}
3953

lib/widget/maps/maps_state.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,11 @@ class MapsState extends MapsActionableState
451451
_overlayWidget != null && _selectedMarkerId != null
452452
? MapsOverlay(
453453
_overlayWidget!,
454-
scrollable: widget.controller.scrollableOverlay,
454+
scrollable: widget.controller.scrollableMarkerOverlay,
455455
onScrolled: (isNext) =>
456456
isNext ? _selectNextMarker() : _selectPreviousMarker(),
457+
maxWidth: widget.controller.markerOverlayMaxWidth,
458+
maxHeight: widget.controller.markerOverlayMaxHeight,
457459
)
458460
: const SizedBox.shrink()
459461
]);

0 commit comments

Comments
 (0)