Skip to content

Commit

Permalink
Nothing to see here. Just removing dead code and linting the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vusters committed Aug 2, 2024
1 parent 678b5b5 commit 2f87b7e
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 263 deletions.
93 changes: 51 additions & 42 deletions modules/ensemble/lib/action/get_network_info_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,33 @@ class GetNetworkInfoAction extends EnsembleAction {
EnsembleAction? onDenied;
EnsembleAction? onLocationDisabled;

GetNetworkInfoAction({super.initiator,
super.inputs,
this.onSuccess,
this.onError,
this.onDenied,
this.onLocationDisabled});
GetNetworkInfoAction(
{super.initiator,
super.inputs,
this.onSuccess,
this.onError,
this.onDenied,
this.onLocationDisabled});

factory GetNetworkInfoAction.from({Invokable? initiator,dynamic payload}) =>
GetNetworkInfoAction.fromYaml(initiator: initiator, payload: Utils.getYamlMap(payload));
factory GetNetworkInfoAction.from({Invokable? initiator, dynamic payload}) =>
GetNetworkInfoAction.fromYaml(
initiator: initiator, payload: Utils.getYamlMap(payload));
factory GetNetworkInfoAction.fromYaml({Invokable? initiator, Map? payload}) {
if (payload?['onSuccess'] == null) {
throw LanguageError('onSuccess is required',recovery:'Please specify onSuccess method to call when network info is retrieved');
throw LanguageError('onSuccess is required',
recovery:
'Please specify onSuccess method to call when network info is retrieved');
}
return GetNetworkInfoAction(
initiator: initiator,
inputs: Utils.getMap(payload?['inputs']),
onSuccess: EnsembleAction.from(payload?['onSuccess'], initiator: initiator),
onSuccess:
EnsembleAction.from(payload?['onSuccess'], initiator: initiator),
onError: EnsembleAction.from(payload?['onError'], initiator: initiator),
onDenied: EnsembleAction.from(payload?['onDenied'], initiator: initiator),
onLocationDisabled: EnsembleAction.from(payload?['onLocationDisabled'], initiator: initiator));
onDenied:
EnsembleAction.from(payload?['onDenied'], initiator: initiator),
onLocationDisabled: EnsembleAction.from(payload?['onLocationDisabled'],
initiator: initiator));
}

@override
Expand All @@ -51,35 +58,31 @@ class GetNetworkInfoAction extends EnsembleAction {
data: {'status': 'error'}));
}
networkInfo.getLocationStatus().then((locationStatus) {
if ((locationStatus == LocationPermissionStatus.denied.name
|| locationStatus == LocationPermissionStatus.deniedForever.name)
&& onDenied != null) {
if ((locationStatus == LocationPermissionStatus.denied.name ||
locationStatus == LocationPermissionStatus.deniedForever.name) &&
onDenied != null) {
return ScreenController().executeAction(context, onDenied!,
event: EnsembleEvent(initiator,
data: {'status': locationStatus}));
} else if (locationStatus == LocationStatus.disabled.name
&& onLocationDisabled != null) {
event: EnsembleEvent(initiator, data: {'status': locationStatus}));
} else if (locationStatus == LocationStatus.disabled.name &&
onLocationDisabled != null) {
return ScreenController().executeAction(context, onLocationDisabled!,
event: EnsembleEvent(initiator,
data: {'status': locationStatus}));
} else
if (locationStatus == LocationPermissionStatus.unableToDetermine.name
&& onError != null) {
event: EnsembleEvent(initiator, data: {'status': locationStatus}));
} else if (locationStatus ==
LocationPermissionStatus.unableToDetermine.name &&
onError != null) {
return ScreenController().executeAction(context, onError!,
event: EnsembleEvent(initiator,
data: {
'status': locationStatus
}));
event: EnsembleEvent(initiator, data: {'status': locationStatus}));
} else {
try {
networkInfo.getNetworkInfo().then((info) =>
ScreenController().executeAction(context, onSuccess!,
event: EnsembleEvent(initiator,
data: {
networkInfo
.getNetworkInfo()
.then((info) =>
ScreenController().executeAction(context, onSuccess!,
event: EnsembleEvent(initiator, data: {
'status': locationStatus,
'networkInfo': info,
}
))).onError((error, stackTrace) {
})))
.onError((error, stackTrace) {
if (onError != null) {
return ScreenController().executeAction(context, onError!,
event: EnsembleEvent(initiator,
Expand All @@ -91,25 +94,32 @@ class GetNetworkInfoAction extends EnsembleAction {
if (onError != null) {
return ScreenController().executeAction(context, onError!,
event: EnsembleEvent(initiator,
error: e.toString(),
data: {'status': locationStatus}));
error: e.toString(), data: {'status': locationStatus}));
}
}
}
}).onError((e, stackTrace) {
if (onError != null) {
return ScreenController().executeAction(context, onError!,
event: EnsembleEvent(initiator,
error: e.toString(),
data: {'status': 'error: '+e.toString(), 'networkInfo': null}));
event: EnsembleEvent(initiator, error: e.toString(), data: {
'status': 'error: ' + e.toString(),
'networkInfo': null
}));
}
print('Failed to get location status: $e');
});
return Future.value(null);
}
}

class InvokableNetworkInfo extends Object with Invokable {
String? wifiName,wifiIPv6,wifiIPv4,wifiGatewayIP,wifiSubmask,wifiBroadcast,wifiBSSID;
String? wifiName,
wifiIPv6,
wifiIPv4,
wifiGatewayIP,
wifiSubmask,
wifiBroadcast,
wifiBSSID;
InvokableNetworkInfo({
this.wifiName,
this.wifiIPv4,
Expand All @@ -120,7 +130,6 @@ class InvokableNetworkInfo extends Object with Invokable {
this.wifiBSSID,
});


@override
Map<String, Function> getters() {
return {
Expand All @@ -143,4 +152,4 @@ class InvokableNetworkInfo extends Object with Invokable {
Map<String, Function> setters() {
return {};
}
}
}
6 changes: 3 additions & 3 deletions modules/ensemble/lib/framework/stub/network_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ abstract class NetworkInfoManager {
}

class NetworkInfoManagerStub implements NetworkInfoManager {
NetworkInfoManagerStub() {
}
NetworkInfoManagerStub() {}
@override
Future<InvokableNetworkInfo> getNetworkInfo() {
if (kIsWeb) {
Expand All @@ -22,6 +21,7 @@ class NetworkInfoManagerStub implements NetworkInfoManager {
throw ConfigError(
"NetworkInfo module is not enabled. Please review the Ensemble documentation.");
}

@override
Future<LocationPermissionStatus> checkPermission() {
throw ConfigError(
Expand All @@ -33,4 +33,4 @@ class NetworkInfoManagerStub implements NetworkInfoManager {
throw ConfigError(
"NetworkInfo module is not enabled. Please review the Ensemble documentation.");
}
}
}
17 changes: 2 additions & 15 deletions modules/ensemble/lib/framework/theme/theme_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ mixin ThemeLoader {
),
),
textTheme: _buildTextTheme(themeConfig?['Text']),
// outlinedButtonTheme: OutlinedButtonThemeData(
// style: OutlinedButton.styleFrom(
// textStyle: const TextStyle(fontSize: 16),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(8.0),
// ),
// ),
// ),
// textButtonTheme: TextButtonThemeData(
// style: TextButton.styleFrom(
// textStyle: const TextStyle(fontSize: 16),
// ),
// ),
// ,
tabBarTheme: TabBarTheme(
labelColor: DesignSystem.primary,
),
Expand Down Expand Up @@ -355,7 +341,8 @@ mixin ThemeLoader {

// labelStyle starts at Text->labelLarge and overriden at Widgets->Button
var textStyle = Utils.getTextStyle(input?["labelStyle"]);
var labelStyle = baselineTheme.textTheme.labelLarge?.merge(textStyle) ?? textStyle;
var labelStyle =
baselineTheme.textTheme.labelLarge?.merge(textStyle) ?? textStyle;

var buttonStyle = _getButtonStyle(
isOutline: isOutline,
Expand Down
2 changes: 1 addition & 1 deletion modules/ensemble/lib/framework/theme/theme_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dynamic getProp(Map? root, List<String> paths) {
result = result[path];
}
return result;
}
}
1 change: 1 addition & 0 deletions modules/ensemble/lib/framework/theme_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class EnsembleThemeManager {
}
return currentTheme()?.resolveStyles(context, hasStyles);
}

void configureStyles(
DataContext dataContext, HasStyles model, HasStyles hasStyles) {
//we have to set all these so we can resolve when styles change at runtime through app logic
Expand Down
3 changes: 2 additions & 1 deletion modules/ensemble/lib/page_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ abstract class PageModel {
} on Error catch (e) {
throw LanguageError("Invalid page definition.",
recovery: "Please double check your page syntax.",
detailedError: e.toString() + "\n" + (e.stackTrace?.toString() ?? ''));
detailedError:
e.toString() + "\n" + (e.stackTrace?.toString() ?? ''));
}
}

Expand Down
8 changes: 5 additions & 3 deletions modules/ensemble/lib/util/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,15 @@ class Utils {
} else if (style is String) {}
return null;
}

//fontFamily could either be a string or a map where the key is the language code and the value is the font family name
static TextStyle? getFontFamily(dynamic name) {
String? fontFamily;
// Check if the name is a map with language codes
if (name is Map) {
// Retrieve the current language code
String? languageCode = UserLocale.from(Ensemble().getLocale())?.languageCode;
String? languageCode =
UserLocale.from(Ensemble().getLocale())?.languageCode;
if (languageCode != null && name.containsKey(languageCode)) {
fontFamily = name[languageCode]?.toString();
}
Expand All @@ -569,7 +571,8 @@ class Utils {
if (fontFamily == null || fontFamily.isEmpty) {
fontFamily = name['default']?.toString();
}
} else if (name is String) { // Handle the case where name is a string
} else if (name is String) {
// Handle the case where name is a string
fontFamily = name;
}
// If a valid font family is found, apply it
Expand All @@ -584,7 +587,6 @@ class Utils {
return null;
}


static TextAlign? getTextAlignment(dynamic align) {
TextAlign? textAlign;
switch (align) {
Expand Down
52 changes: 0 additions & 52 deletions modules/ensemble/lib/widget/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,58 +194,6 @@ class ButtonState extends WidgetState<Button> {
widget._controller.labelStyle.getTextStyle();
}

// ButtonStyle getButtonStyle2(BuildContext context, bool isOutlineButton) {
// // we need to build a border which requires valid borderColor, borderThickness & borderRadius.
// // Let's get the default theme so we can overwrite only necessary styles
// RoundedRectangleBorder? border;
// OutlinedBorder? defaultShape = isOutlineButton
// ? Theme.of(context).textButtonTheme.style?.shape?.resolve({})
// : Theme.of(context).elevatedButtonTheme.style?.shape?.resolve({});
// if (defaultShape is RoundedRectangleBorder) {
// // if we don't specify borderColor here, and the default border is none, stick with that
// BorderSide borderSide;
// if (widget._controller.borderColor == null &&
// defaultShape.side.style == BorderStyle.none) {
// borderSide = defaultShape.side;
// } else {
// borderSide = BorderSide(
// color: widget._controller.borderColor ?? defaultShape.side.color,
// width: widget._controller.borderWidth?.toDouble() ??
// defaultShape.side.width);
// }
//
// border = RoundedRectangleBorder(
// borderRadius: widget._controller.borderRadius == null
// ? defaultShape.borderRadius
// : widget._controller.borderRadius!.getValue(),
// // when we give [borderGradient] and [borderColor] it will draw that color also around borderSide
// // So when the borderGradient is there the side will be none
// side: widget._controller.borderGradient != null
// ? BorderSide.none
// : borderSide);
// } else {
// if (isOutlineButton) {
// border = const RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.zero),
// );
// }
// }
//
// // we need to get the button shape from borderRadius, borderColor & borderThickness
// // and we do not want to override the default theme if not specified
// //int borderRadius = widget._controller.borderRadius ?? defaultButtonStyle?.
//
// return ThemeManager().getButtonStyle(
// isOutline: isOutlineButton,
// backgroundColor: widget._controller.backgroundGradient == null
// ? widget._controller.backgroundColor
// : Colors.transparent,
// border: border,
// buttonHeight: widget._controller.buttonHeight?.toDouble(),
// buttonWidth: widget._controller.buttonWidth?.toDouble(),
// padding: widget._controller.padding);
// }

void onPressed(BuildContext context) {
// validate if we are inside a Form
if (widget._controller.validateForm != null &&
Expand Down
21 changes: 12 additions & 9 deletions modules/ensemble/lib/widget/input/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ abstract class SelectOne extends StatefulWidget
_controller.dropdownMaxHeight = Utils.optionalInt(value, min: 0),
'itemTemplate': (itemTemplate) => _setItemTemplate(itemTemplate),
'createNewItem': (value) => _setCreateNewItem(value),
'textStyle': (style) => _controller.textStyle = Utils.getTextStyleAsComposite(_controller,style: style),
'textStyle': (style) => _controller.textStyle =
Utils.getTextStyleAsComposite(_controller, style: style),
});
return setters;
}
Expand Down Expand Up @@ -406,11 +407,10 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
widget._controller.dropdownOffsetY?.toDouble() ?? 0,
)),
decoration: inputDecoration.copyWith(
contentPadding: adjustedContentPadding,
labelText: widget.controller.floatLabel == true
? widget.controller.label
: null
));
contentPadding: adjustedContentPadding,
labelText: widget.controller.floatLabel == true
? widget.controller.label
: null));
}

/// build the auto-complete Dropdown
Expand Down Expand Up @@ -438,7 +438,8 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
labelText: widget.controller.floatLabel == true
? widget.controller.label
: null,
fillColor: widget._controller.fillColor, // Background color for the field
fillColor: widget._controller
.fillColor, // Background color for the field
),
onChanged: (value) {
final oldValue = widget._controller.maybeValue;
Expand Down Expand Up @@ -570,12 +571,14 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
widget._controller.createNewItemLabel,
option.value,
),
style: widget._controller.textStyle.getTextStyle(),
style: widget._controller.textStyle
.getTextStyle(),
)
: Text(
Utils.optionalString(option.label) ??
option.value,
style: widget._controller.textStyle.getTextStyle(),
style: widget._controller.textStyle
.getTextStyle(),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions modules/ensemble/lib/widget/webview/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class EnsembleWebView extends StatefulWidget
ensemble.EnsembleAction.from(funcDefinition, initiator: this),
// legacy
'uri': (value) => _controller.url = Utils.getUrl(value),
'allowedLaunchSchemes': (value) =>
_controller.schemes = Utils.getList<String>(value) ??
'allowedLaunchSchemes': (value) => _controller.schemes =
Utils.getList<String>(value) ??
EnsembleWebViewController.defaultSchemes,
};
}
Expand Down
Loading

0 comments on commit 2f87b7e

Please sign in to comment.