From 7edd9c8caf6c360d4c37316fd93e6ccc618896ed Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 27 Dec 2022 10:12:38 +0100 Subject: [PATCH 01/23] init commit --- .../src/elements/actions/braintree/pay.dart | 7 +- .../actions/mixpanel/set_user_id.dart | 3 +- .../src/elements/actions/mixpanel/track.dart | 3 +- .../actions/navigation/open_bottom_sheet.dart | 17 +- .../actions/navigation/open_page.dart | 24 +- .../actions/navigation/open_snack.dart | 17 +- .../actions/snippets/get_page_on_code.dart | 3 +- .../elements/actions/teta_cms/auth/login.dart | 4 +- .../actions/teta_cms/auth/logout.dart | 5 +- .../src/elements/bodies/google_maps_body.dart | 228 ++++++--- .../lib/src/elements/bodies/scaffold.dart | 3 +- .../lib/src/elements/builder/add_dataset.dart | 48 +- .../elements/builder/placeholder_child.dart | 4 +- .../src/elements/builder/save_dataset.dart | 34 +- .../elements/code/page/code_component.dart | 3 +- .../lib/src/elements/code/page/scaffold.dart | 3 +- .../code/templates/cms_logged_user.dart | 11 +- .../elements/code/templates/component.dart | 7 +- .../lib/src/elements/code/templates/map.dart | 5 +- .../src/elements/controls/atoms/action.dart | 7 +- .../src/elements/controls/atoms/delete.dart | 17 +- .../elements/controls/atoms/fill/asset.dart | 122 +++-- .../elements/controls/atoms/src_image.dart | 434 +++++++++--------- .../lib/src/elements/controls/atoms/text.dart | 11 +- .../src/elements/widgets/airtable/fetch.dart | 5 +- .../lib/src/elements/widgets/component.dart | 61 ++- .../google_maps_web_mobile_widget.dart | 10 +- .../lib/src/elements/widgets/map.dart | 32 +- .../lib/src/elements/widgets/map_builder.dart | 53 ++- .../widgets/teta_cms/logged_user.dart | 8 +- 30 files changed, 636 insertions(+), 553 deletions(-) diff --git a/teta_widgets/lib/src/elements/actions/braintree/pay.dart b/teta_widgets/lib/src/elements/actions/braintree/pay.dart index e2a2af79..3118c5f8 100644 --- a/teta_widgets/lib/src/elements/actions/braintree/pay.dart +++ b/teta_widgets/lib/src/elements/actions/braintree/pay.dart @@ -39,10 +39,11 @@ class FActionBraintreeBuy { final String? stateName, { final int loop = 0, }) { - final prj = (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final isSandbox = prj.config?.braintreeIsSandbox ?? true; - final token = - !isSandbox ? prj.config?.braintreeClientToken : prj.config?.braintreeClientTokenSandbox; + final token = !isSandbox + ? prj.config?.braintreeClientToken + : prj.config?.braintreeClientTokenSandbox; final companyName = prj.config?.companyName ?? ''; final currencyCode = prj.config?.braintreeCurrencyCode ?? ''; final countryCode = prj.config?.countryCode ?? ''; diff --git a/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart b/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart index ecdfb355..09980f3e 100644 --- a/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart +++ b/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart @@ -52,8 +52,7 @@ class FAMixpanelSetUserId { final BuildContext context, final FTextTypeInput? userIdValue, ) { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; if (prj.config?.isMixpanelReady ?? false) { final userId = userIdValue?.toCode( 0, diff --git a/teta_widgets/lib/src/elements/actions/mixpanel/track.dart b/teta_widgets/lib/src/elements/actions/mixpanel/track.dart index 39567cc2..f79b8bef 100644 --- a/teta_widgets/lib/src/elements/actions/mixpanel/track.dart +++ b/teta_widgets/lib/src/elements/actions/mixpanel/track.dart @@ -54,8 +54,7 @@ class FAMixpanelTrack { final FTextTypeInput? eventName, final List? props, ) { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; if (prj.config?.isMixpanelReady ?? false) { //props final mapBody = {}; diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart index de2e5668..9d821d65 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart @@ -28,10 +28,11 @@ class FActionNavigationOpenBottomSheet { ) async { try { if (nameOfPage != null) { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; final currentPage = BlocProvider.of(context).state; PageObject? page; - page = prj.prj.pages!.firstWhereOrNull((final element) => element.name == nameOfPage); + page = prj.pages! + .firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( 'nodes', @@ -88,12 +89,13 @@ class FActionNavigationOpenBottomSheet { final Map? paramsToSend, ) { try { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; if (nameOfPage == null || - (prj.prj.pages ?? []) + (prj.pages ?? []) .indexWhere((final element) => element.name == nameOfPage) == -1) return ''; - final page = prj.prj.pages!.firstWhere((final element) => element.name == nameOfPage); + final page = + prj.pages!.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -117,8 +119,9 @@ class FActionNavigationOpenBottomSheet { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); // ignore: avoid_dynamic_calls - final valueToSend = - (paramsToSend ?? {})[param.id]?['label'] as String? ?? 'null'; + final valueToSend = (paramsToSend ?? {})[param.id] + ?['label'] as String? ?? + 'null'; final rc = ReCase(valueToSend); stringParamsToSend.write('widget.${rc.camelCase}, '); } diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart index bbfea6e0..a0b5d46c 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart @@ -31,7 +31,8 @@ void goTo(final CNode node, final BuildContext context, final Widget child) { T.Transition( child: child, transitionEffect: - (node.body.attributes[DBKeys.pageTransition] as FPageTransition).transitionEffect!, + (node.body.attributes[DBKeys.pageTransition] as FPageTransition) + .transitionEffect!, ), ); } else { @@ -52,10 +53,11 @@ class FActionNavigationOpenPage { final Map? paramsToSend, ) async { try { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; final currentPage = BlocProvider.of(context).state; PageObject? page; - page = prj.prj.pages!.firstWhereOrNull((final element) => element.name == nameOfPage); + page = prj.pages! + .firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( 'nodes', @@ -81,14 +83,14 @@ class FActionNavigationOpenPage { page = page.copyWith(flatList: nodes, scaffold: scaffold); BlocProvider.of(context) - .onFocus(prj: prj.prj, page: page, context: context); + .onFocus(prj: prj, page: page, context: context); await Navigator.push( context, MaterialPageRoute( builder: (final context) => BlocProvider( create: (final context) => - PageCubit()..onFocus(prj: prj.prj, page: page!, context: context), + PageCubit()..onFocus(prj: prj, page: page!, context: context), child: page!.scaffold!.toWidget( state: state.copyWith( forPlay: true, @@ -120,12 +122,13 @@ class FActionNavigationOpenPage { final String? nameOfPage, final Map? paramsToSend, ) { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; if (nameOfPage == null || - (prj.prj.pages ?? []) + (prj.pages ?? []) .indexWhere((final element) => element.name == nameOfPage) == -1) return ''; - final page = prj.prj.pages!.firstWhere((final element) => element.name == nameOfPage); + final page = + prj.pages!.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -149,8 +152,9 @@ class FActionNavigationOpenPage { // ignore: literal_only_boolean_expressions if ("${paramsToSend?[param.id]?['dataset']}" == 'States' || "${paramsToSend?[param.id]?['dataset']}" == 'Params') { - final valueToSend = - (paramsToSend ?? {})[param.id]?['label'] as String? ?? 'null'; + final valueToSend = (paramsToSend ?? {})[param.id] + ?['label'] as String? ?? + 'null'; if (valueToSend != 'null') { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart index a3b4c5b9..a53713de 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart @@ -26,10 +26,11 @@ class FActionNavigationOpenSnackBar { ) async { try { if (nameOfPage != null) { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; final currentPage = BlocProvider.of(context).state; PageObject? page; - page = prj.prj.pages!.firstWhereOrNull((final element) => element.name == nameOfPage); + page = prj.pages! + .firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( 'nodes', @@ -83,12 +84,13 @@ class FActionNavigationOpenSnackBar { final Map? paramsToSend, ) { try { - final prj = BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; if (nameOfPage == null || - (prj.prj.pages ?? []) + (prj.pages ?? []) .indexWhere((final element) => element.name == nameOfPage) == -1) return ''; - final page = prj.prj.pages!.firstWhere((final element) => element.name == nameOfPage); + final page = + prj.pages!.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -111,8 +113,9 @@ class FActionNavigationOpenSnackBar { for (final param in page.params) { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); - final valueToSend = - (paramsToSend ?? {})[param.id]['label'] as String? ?? 'null'; + final valueToSend = (paramsToSend ?? {})[param.id] + ['label'] as String? ?? + 'null'; final rc = ReCase(valueToSend); stringParamsToSend.write('${rc.camelCase}, '); } diff --git a/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart b/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart index 1e8807bb..f04c554e 100644 --- a/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart +++ b/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart @@ -4,8 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; PageObject? getPageOnToCode(final int pageId, final BuildContext context) { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; if (prj.pages != null) { return prj.pages!.firstWhereOrNull((final element) => element.id == pageId); } diff --git a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart index 89450f70..06708e26 100644 --- a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart +++ b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart @@ -22,7 +22,7 @@ class FATetaCMSLogin { final Map? paramsToSend, final TetaProvider provider, ) async { - final prj = (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; // final page = BlocProvider.of(context).state; // final status = takeStateFrom(page, 'status'); @@ -65,7 +65,7 @@ class FATetaCMSLogin { final String? nameOfPage, final Map? paramsToSend, ) { - final prj = (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final isRevenueCatEnabled = prj.config?.isRevenueCatEnabled ?? false; final providerStr = provider == TetaProvider.google ? 'TetaProvider.google' diff --git a/teta_widgets/lib/src/elements/actions/teta_cms/auth/logout.dart b/teta_widgets/lib/src/elements/actions/teta_cms/auth/logout.dart index 148c175f..0722289d 100644 --- a/teta_widgets/lib/src/elements/actions/teta_cms/auth/logout.dart +++ b/teta_widgets/lib/src/elements/actions/teta_cms/auth/logout.dart @@ -15,10 +15,7 @@ class FATetaCMSLogout { static Future action( final BuildContext context, ) async { - final prjId = - (BlocProvider.of(context).state as ProjectLoaded) - .prj - .id; + final prjId = BlocProvider.of(context).state!.id; TrackService.instance.track( eventName: 'Teta Auth: logout in Teta', prjId: prjId, diff --git a/teta_widgets/lib/src/elements/bodies/google_maps_body.dart b/teta_widgets/lib/src/elements/bodies/google_maps_body.dart index 42df58db..e9280519 100644 --- a/teta_widgets/lib/src/elements/bodies/google_maps_body.dart +++ b/teta_widgets/lib/src/elements/bodies/google_maps_body.dart @@ -71,7 +71,8 @@ final googleMapsIntrinsicStates = IntrinsicStates( const Suggestion( title: 'Why use Google Maps in Teta?', description: 'Test', - linkToOpen: 'https://docs.teta.so/teta-docs/widget/map-widgets/google-maps', + linkToOpen: + 'https://docs.teta.so/teta-docs/widget/map-widgets/google-maps', ) ], ); @@ -124,7 +125,8 @@ class GoogleMapsBody extends NodeBody { type: ControlType.googleMapsMapStyle, key: DBKeys.mapCustomStyle, value: attributes[DBKeys.mapCustomStyle], - description: 'JSON String. See more at https://mapstyle.withgoogle.com/ .', + description: + 'JSON String. See more at https://mapstyle.withgoogle.com/ .', flag: true, valueType: VariableType.string, ), @@ -178,7 +180,8 @@ class GoogleMapsBody extends NodeBody { key: DBKeys.markerId, value: attributes[DBKeys.markerId] as FDataset, flag: true, - description: 'String UUID. Generate https://www.uuidgenerator.net/version4', + description: + 'String UUID. Generate https://www.uuidgenerator.net/version4', valueType: VariableType.string, ), ControlObject( @@ -260,28 +263,50 @@ class GoogleMapsBody extends NodeBody { state: state, child: child, mapControllerName: - (attributes[DBKeys.googleMapsController] as FTextTypeInput).stateName ?? '', - markersDatasetName: (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', - markerId: (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', - markerLatitude: (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? '', - markerLongitude: (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? '', - markerIconUrl: (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? '', - markerIconWidth: (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? '', - markerIconHeight: (attributes[DBKeys.markerIconHeight] as FDataset).datasetAttrName ?? '', + (attributes[DBKeys.googleMapsController] as FTextTypeInput) + .stateName ?? + '', + markersDatasetName: + (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', + markerId: + (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', + markerLatitude: + (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? + '', + markerLongitude: + (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? + '', + markerIconUrl: + (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? + '', + markerIconWidth: + (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? + '', + markerIconHeight: + (attributes[DBKeys.markerIconHeight] as FDataset).datasetAttrName ?? + '', drawPathFromUserGeolocationToMarker: - (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset).datasetAttrName ?? + (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset) + .datasetAttrName ?? '', mapStyle: attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle, - initialPositionLat: (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) - .toCode(state.loop, resultType: ResultTypeEnum.double), - initialPositionLng: (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) - .toCode(state.loop, resultType: ResultTypeEnum.double), - showMyLocationMarker: attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, - initialZoomLevel: (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) - .toCode(state.loop, resultType: ResultTypeEnum.double), + initialPositionLat: + (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) + .toCode(state.loop, resultType: ResultTypeEnum.double), + initialPositionLng: + (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) + .toCode(state.loop, resultType: ResultTypeEnum.double), + showMyLocationMarker: + attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, + initialZoomLevel: + (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) + .toCode(state.loop, resultType: ResultTypeEnum.double), trackMyLocation: attributes[DBKeys.mapConfigTrackMyLocation] as bool, pathColor: attributes[DBKeys.fill] as FFill, - cubitName: (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput).stateName ?? '', + cubitName: + (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput) + .stateName ?? + '', ); @override @@ -296,31 +321,52 @@ class GoogleMapsBody extends NodeBody { ) => GoogleMapsTemplate.toCodeOnInit( mapControllerName: - (attributes[DBKeys.googleMapsController] as FTextTypeInput).stateName ?? '', - markersDatasetName: (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', - markerId: (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', - markerLatitude: (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? '', - markerLongitude: (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? '', - markerIconUrl: (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? '', - markerIconWidth: (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? '', + (attributes[DBKeys.googleMapsController] as FTextTypeInput) + .stateName ?? + '', + markersDatasetName: + (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', + markerId: + (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', + markerLatitude: + (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? + '', + markerLongitude: + (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? + '', + markerIconUrl: + (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? + '', + markerIconWidth: + (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? + '', markerDrawPath: - (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset).datasetAttrName ?? + (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset) + .datasetAttrName ?? '', - customMapStyle: (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, - initialPositionLat: (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), - initialPositionLng: (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput).toCode( + customMapStyle: + (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, + initialPositionLat: + (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), + initialPositionLng: + (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput).toCode( loop, resultType: ResultTypeEnum.double, ), - showMyLocationMarker: attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, - initialZoomLevel: (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput).toCode( + showMyLocationMarker: + attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, + initialZoomLevel: + (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) + .toCode( loop, resultType: ResultTypeEnum.double, ), trackMyLocation: attributes[DBKeys.mapConfigTrackMyLocation] as bool, googleMapsBlocName: - (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput).stateName ?? '', + (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput) + .stateName ?? + '', pathColor: (attributes[DBKeys.fill] as FFill).getHexColor(context), ); @@ -336,32 +382,52 @@ class GoogleMapsBody extends NodeBody { ) => GoogleMapsCubitTemplate.toCode( mapControllerName: - (attributes[DBKeys.googleMapsController] as FTextTypeInput).stateName ?? '', - markersDatasetName: (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', - markerId: (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', - markerLatitude: (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? '', - markerLongitude: (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? '', - markerIconUrl: (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? '', - markerIconWidth: (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? '', + (attributes[DBKeys.googleMapsController] as FTextTypeInput) + .stateName ?? + '', + markersDatasetName: + (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', + markerId: + (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', + markerLatitude: + (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? + '', + markerLongitude: + (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? + '', + markerIconUrl: + (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? + '', + markerIconWidth: + (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? + '', markerDrawPath: - (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset).datasetAttrName ?? + (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset) + .datasetAttrName ?? '', - customMapStyle: (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, - initialPositionLat: (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), - initialPositionLng: (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), - showMyLocationMarker: attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, - initialZoomLevel: (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), + customMapStyle: + (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, + initialPositionLat: + (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), + initialPositionLng: + (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), + showMyLocationMarker: + attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, + initialZoomLevel: + (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), trackMyLocation: attributes[DBKeys.mapConfigTrackMyLocation] as bool, - googleMapsKey: (BlocProvider.of(context).state as ProjectLoaded) - .prj + googleMapsKey: BlocProvider.of(context) + .state! .config ?.googleMapsKey ?? '', googleMapsCubitName: - (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput).stateName ?? '', + (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput) + .stateName ?? + '', pathColor: (attributes[DBKeys.fill] as FFill).getHexColor(context), ); @@ -381,29 +447,51 @@ class GoogleMapsBody extends NodeBody { GoogleMapsTemplate.toCode( context: context, mapControllerName: - (attributes[DBKeys.googleMapsController] as FTextTypeInput).stateName ?? '', - markersDatasetName: (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', - markerId: (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', - markerLatitude: (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? '', - markerLongitude: (attributes[DBKeys.markerLongitude] as FDataset).datasetAttrName ?? '', - markerIconUrl: (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? '', - markerIconWidth: (attributes[DBKeys.markerIconWidth] as FDataset).datasetAttrName ?? '', - markerDrawPath: (attributes[DBKeys.markerDrawPathToUserCurrentLocation] as FDataset) + (attributes[DBKeys.googleMapsController] as FTextTypeInput) + .stateName ?? + '', + markersDatasetName: + (attributes[DBKeys.datasetInput] as FDataset).datasetName ?? '', + markerId: + (attributes[DBKeys.markerId] as FDataset).datasetAttrName ?? '', + markerLatitude: + (attributes[DBKeys.markerLatitude] as FDataset).datasetAttrName ?? + '', + markerLongitude: (attributes[DBKeys.markerLongitude] as FDataset) + .datasetAttrName ?? + '', + markerIconUrl: + (attributes[DBKeys.markerIconUrl] as FDataset).datasetAttrName ?? + '', + markerIconWidth: (attributes[DBKeys.markerIconWidth] as FDataset) .datasetAttrName ?? '', - customMapStyle: (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, - initialPositionLat: (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), - initialPositionLng: (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) - .toCode(loop, resultType: ResultTypeEnum.double), - showMyLocationMarker: attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, - initialZoomLevel: (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput).toCode( + markerDrawPath: + (attributes[DBKeys.markerDrawPathToUserCurrentLocation] + as FDataset) + .datasetAttrName ?? + '', + customMapStyle: + (attributes[DBKeys.mapCustomStyle] as FGoogleMapsMapStyle).get, + initialPositionLat: + (attributes[DBKeys.mapInitialPositionLat] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), + initialPositionLng: + (attributes[DBKeys.mapInitialPositionLng] as FTextTypeInput) + .toCode(loop, resultType: ResultTypeEnum.double), + showMyLocationMarker: + attributes[DBKeys.mapConfigShowMyLocationMarker] as bool, + initialZoomLevel: + (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) + .toCode( loop, resultType: ResultTypeEnum.double, ), trackMyLocation: attributes[DBKeys.mapConfigTrackMyLocation] as bool, googleMapsCubitName: - (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput).stateName ?? '', + (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput) + .stateName ?? + '', pathColor: (attributes[DBKeys.fill] as FFill).getHexColor(context), ), loop ?? 0, diff --git a/teta_widgets/lib/src/elements/bodies/scaffold.dart b/teta_widgets/lib/src/elements/bodies/scaffold.dart index b8d3bef3..d72870fa 100644 --- a/teta_widgets/lib/src/elements/bodies/scaffold.dart +++ b/teta_widgets/lib/src/elements/bodies/scaffold.dart @@ -187,8 +187,7 @@ class ScaffoldBody extends NodeBody { final int pageId, final int? loop, ) { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final page = prj.pages!.firstWhere((final element) => element.id == pageId); if (!page.isHardCoded) { return pageCodeTemplate( diff --git a/teta_widgets/lib/src/elements/builder/add_dataset.dart b/teta_widgets/lib/src/elements/builder/add_dataset.dart index 2c0bc2bd..16393d4c 100644 --- a/teta_widgets/lib/src/elements/builder/add_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/add_dataset.dart @@ -13,9 +13,8 @@ List addDataset( final DatasetObject map, ) { final list = [...dataset, map]; - final prjState = BlocProvider.of(context).state; + final prj = BlocProvider.of(context).state!; final pageFocused = BlocProvider.of(context).state; - final prj = (prjState as ProjectLoaded).prj; try { var flag = true; @@ -28,20 +27,19 @@ List addDataset( } if (flag) pageFocused.datasets = [...pageFocused.datasets, map]; - if (prjState is ProjectLoaded) { - for (final page in prjState.prj.pages!) { - if (page.id == pageFocused.id) { - var flag = true; - for (final e in pageFocused.datasets) { - if (e.getName == map.getName) { - flag = false; - break; - } + for (final page in prj.pages!) { + if (page.id == pageFocused.id) { + var flag = true; + for (final e in pageFocused.datasets) { + if (e.getName == map.getName) { + flag = false; + break; } - if (flag) page.datasets = [...page.datasets, map]; } + if (flag) page.datasets = [...page.datasets, map]; } } + Box> box; if (Hive.isBoxOpen('datasets${prj.id}')) { final list2 = []; @@ -51,13 +49,13 @@ List addDataset( for (final dynamic key in boxMap.keys) { final map2 = box.get(key)!; final map3 = map2 - .map((dynamic e) => (e as Map).cast()) + .map((final dynamic e) => (e as Map).cast()) .toList(); - var _map = DatasetObject(name: key.toString(), map: map3); + final _map = DatasetObject(name: key.toString(), map: map3); list2.add(_map); } - for (var element in list2) { + for (final element in list2) { var flag = true; for (final e in pageFocused.datasets) { if (e.getName == element.getName) { @@ -69,20 +67,18 @@ List addDataset( if (flag) pageFocused.datasets = [...pageFocused.datasets, element]; } - if (prjState is ProjectLoaded) { - for (final page in prjState.prj.pages!) { - for (var element in list2) { - var flag = true; - for (final e in page.datasets) { - if (e.getName == element.getName) { - page.datasets[page.datasets.indexOf(e)] = element; + for (final page in prj.pages!) { + for (final element in list2) { + var flag = true; + for (final e in page.datasets) { + if (e.getName == element.getName) { + page.datasets[page.datasets.indexOf(e)] = element; - flag = false; - break; - } + flag = false; + break; } - if (flag) page.datasets = [...page.datasets, element]; } + if (flag) page.datasets = [...page.datasets, element]; } } } diff --git a/teta_widgets/lib/src/elements/builder/placeholder_child.dart b/teta_widgets/lib/src/elements/builder/placeholder_child.dart index be371db0..62e7e3c5 100644 --- a/teta_widgets/lib/src/elements/builder/placeholder_child.dart +++ b/teta_widgets/lib/src/elements/builder/placeholder_child.dart @@ -35,9 +35,7 @@ class PlaceholderChildBuilder extends StatelessWidget { padding: const EdgeInsets.all(16), child: BounceLarge( onTap: () { - final prj = (BlocProvider.of(context).state - as ProjectLoaded) - .prj; + final prj = BlocProvider.of(context).state!; final focusPageBloc = BlocProvider.of(context); final refreshCubit = BlocProvider.of(context); final focusBloc = BlocProvider.of(context); diff --git a/teta_widgets/lib/src/elements/builder/save_dataset.dart b/teta_widgets/lib/src/elements/builder/save_dataset.dart index 0937c447..dde6c494 100644 --- a/teta_widgets/lib/src/elements/builder/save_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/save_dataset.dart @@ -1,9 +1,9 @@ // Flutter imports: import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; // Package imports: import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hive/hive.dart'; import 'package:teta_core/teta_core.dart'; /// Function to add a new dataset to scaffold and widgets' tree @@ -14,9 +14,8 @@ Future> saveDatasets( final DatasetObject map, ) async { final list = [...dataset, map]; - final prjState = BlocProvider.of(context).state; final pageFocused = BlocProvider.of(context).state; - final prj = (prjState as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; try { Box> box; if (!Hive.isBoxOpen('datasets${prj.id}')) { @@ -32,13 +31,14 @@ Future> saveDatasets( for (final dynamic key in boxMap.keys) { final map2 = box.get(key)!; - final map3 = - map2.map((dynamic e) => (e as Map).cast()).toList(); - var _map = DatasetObject(name: key.toString(), map: map3); + final map3 = map2 + .map((final dynamic e) => (e as Map).cast()) + .toList(); + final _map = DatasetObject(name: key.toString(), map: map3); list2.add(_map); } - for (var element in list2) { + for (final element in list2) { var flag = true; for (final e in pageFocused.datasets) { if (e.getName == element.getName) { @@ -50,20 +50,18 @@ Future> saveDatasets( if (flag) pageFocused.datasets = [...pageFocused.datasets, element]; } - if (prjState is ProjectLoaded) { - for (final page in prjState.prj.pages!) { - for (var element in list2) { - var flag = true; - for (final e in page.datasets) { - if (e.getName == element.getName) { - page.datasets[page.datasets.indexOf(e)] = element; + for (final page in prj.pages!) { + for (final element in list2) { + var flag = true; + for (final e in page.datasets) { + if (e.getName == element.getName) { + page.datasets[page.datasets.indexOf(e)] = element; - flag = false; - break; - } + flag = false; + break; } - if (flag) page.datasets = [...page.datasets, element]; } + if (flag) page.datasets = [...page.datasets, element]; } } diff --git a/teta_widgets/lib/src/elements/code/page/code_component.dart b/teta_widgets/lib/src/elements/code/page/code_component.dart index ba68e0f0..6d81314a 100644 --- a/teta_widgets/lib/src/elements/code/page/code_component.dart +++ b/teta_widgets/lib/src/elements/code/page/code_component.dart @@ -16,8 +16,7 @@ Future codeComponentTemplate( final List children, final int pageId, ) async { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final page = prj.pages!.firstWhere((final element) => element.id == pageId); final list1 = page.code!.split('void'); diff --git a/teta_widgets/lib/src/elements/code/page/scaffold.dart b/teta_widgets/lib/src/elements/code/page/scaffold.dart index 20e64816..351b1464 100644 --- a/teta_widgets/lib/src/elements/code/page/scaffold.dart +++ b/teta_widgets/lib/src/elements/code/page/scaffold.dart @@ -27,8 +27,7 @@ Future pageCodeTemplate( final String onInitCode, final int? loop, ) async { - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final page = prj.pages!.firstWhere((final element) => element.id == pageId); final temp = removeDiacritics( page.name diff --git a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart index 88fa355c..9bf80229 100644 --- a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart +++ b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart @@ -25,12 +25,11 @@ class CmsLoggedUserCodeTemplate { loader = await children[1].toCode(context); } - final revenueCatFlag = - (BlocProvider.of(context).state as ProjectLoaded) - .prj - .config - ?.isRevenueCatEnabled ?? - false; + final revenueCatFlag = BlocProvider.of(context) + .state! + .config + ?.isRevenueCatEnabled ?? + false; final code = ''' TetaFutureBuilder( future: Future.sync(() async { diff --git a/teta_widgets/lib/src/elements/code/templates/component.dart b/teta_widgets/lib/src/elements/code/templates/component.dart index 6bd65f58..6ab2b5c2 100644 --- a/teta_widgets/lib/src/elements/code/templates/component.dart +++ b/teta_widgets/lib/src/elements/code/templates/component.dart @@ -21,18 +21,17 @@ Future componentCodeTemplate( final List children, final int pageId, ) async { - final projectLoaded = - BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; //this fix an error of badstate if (body.attributes[DBKeys.componentName] == null || - (projectLoaded.prj.pages ?? []).indexWhere( + (prj.pages ?? []).indexWhere( (final element) => element.name == body.attributes[DBKeys.componentName], ) == -1) return ''; - final compWidget = projectLoaded.prj.pages!.firstWhere( + final compWidget = prj.pages!.firstWhere( (final element) => element.name == body.attributes[DBKeys.componentName], ); diff --git a/teta_widgets/lib/src/elements/code/templates/map.dart b/teta_widgets/lib/src/elements/code/templates/map.dart index 2dc674b1..bbea8a80 100644 --- a/teta_widgets/lib/src/elements/code/templates/map.dart +++ b/teta_widgets/lib/src/elements/code/templates/map.dart @@ -20,10 +20,7 @@ class MapCodeTemplate { ) async { final flag = body.attributes[DBKeys.flag] as bool; final mapBoxKey = - (BlocProvider.of(context).state as ProjectLoaded) - .prj - .config - ?.mapboxKey; + BlocProvider.of(context).state!.config?.mapboxKey; final code = ''' map.MapLayoutBuilder( diff --git a/teta_widgets/lib/src/elements/controls/atoms/action.dart b/teta_widgets/lib/src/elements/controls/atoms/action.dart index 9d98d603..1a679dda 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action.dart @@ -6,11 +6,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:gap/gap.dart'; - // Package imports: import 'package:teta_core/src/design_system/buttons/element_button.dart'; import 'package:teta_core/teta_core.dart'; - // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/action_element.dart'; import 'package:teta_widgets/src/elements/features/actions/enums/action_google_maps.dart'; @@ -304,8 +302,7 @@ class __NewActionAlertState extends State<_NewActionAlert> { @override void initState() { super.initState(); - final prj = - (BlocProvider.of(context).state as ProjectLoaded).prj; + final prj = BlocProvider.of(context).state!; final page = BlocProvider.of(context).state; elements.addAll([ _SelectionClass( @@ -387,7 +384,7 @@ class __NewActionAlertState extends State<_NewActionAlert> { type: ActionSupabaseStorage.values, ), _SelectionClass( - title: "Airtable Database", + title: 'Airtable Database', actionType: ActionType.airtable, options: FActionElement.getAirtableDB(prj.config), type: ActionAirtableDB.values, diff --git a/teta_widgets/lib/src/elements/controls/atoms/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/delete.dart index ffcea5a0..5ca2eff0 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/delete.dart @@ -38,8 +38,7 @@ class DeleteControlState extends State { flatList: BlocProvider.of(context).state.flatList ?? [], element: widget.node, ); - final prjState = - BlocProvider.of(context).state as ProjectLoaded; + final prj = BlocProvider.of(context).state!; final pageState = BlocProvider.of(context).state; if (widget.node.intrinsicState.canHave == parentOfNode!.intrinsicState.canHave) { @@ -64,23 +63,11 @@ class DeleteControlState extends State { nodes: BlocProvider.of(context).state.flatList ?? [], node: widget.node as NDynamic, - prj: prjState.prj, + prj: prj, page: pageState, ), ), ), - if (false) - Padding( - padding: const EdgeInsets.only(top: 8), - child: CDangerousButton( - label: widget.node.intrinsicState.canHave == ChildrenEnum.none - ? 'Delete' - : widget.node.intrinsicState.canHave == ChildrenEnum.child - ? 'Delete with child' - : 'Delete with children', - callback: delete, - ), - ), ], ), ); diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart index 5840870e..585e8447 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart @@ -31,73 +31,63 @@ class AssetFillControl extends StatefulWidget { class AssetFillControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder( - builder: (final context, final prjState) => prjState is ProjectLoaded - ? BlocBuilder>( - builder: (final context, final state) { - //updateState(state); - - return BlocBuilder( - builder: (final context, final client) { - if (client == null) return const SizedBox(); - final _future = getList(client, prjState.prj); - return FutureBuilder>( - future: _future, - builder: (final context, final snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator(), + return BlocBuilder( + builder: (final context, final client) { + if (client == null) return const SizedBox(); + final _future = + getList(client, BlocProvider.of(context).state!); + return FutureBuilder>( + future: _future, + builder: (final context, final snapshot) { + if (!snapshot.hasData) { + return const Center( + child: CircularProgressIndicator(), + ); + } + final list = snapshot.data ?? []; + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (list.isEmpty) + Padding( + padding: const EdgeInsets.only(bottom: 72), + child: TParagraph( + 'Your bucket is empty. Upload your first file.', + color: Colors.white.withOpacity(0.5), + ), + ), + Row( + children: [ + Expanded( + child: CDropdownImageAssets( + value: widget.fill.file, + items: list, + onChange: (final value) { + PaletteModel? model; + BlocProvider.of(context) + .state + .forEach((final element) { + if (element.name == value.name) { + model = element; + } + }); + final old = FFill().fromJson(widget.fill.toJson()); + widget.fill.paletteStyle = model!.id; + widget.callBack( + widget.fill, + false, + old, ); - } - final list = snapshot.data ?? []; - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (list.isEmpty) - Padding( - padding: const EdgeInsets.only(bottom: 72), - child: TParagraph( - 'Your bucket is empty. Upload your first file.', - color: Colors.white.withOpacity(0.5), - ), - ), - Row( - children: [ - Expanded( - child: CDropdownImageAssets( - value: widget.fill.file, - items: list, - onChange: (final value) { - PaletteModel? model; - BlocProvider.of(context) - .state - .forEach((final element) { - if (element.name == value.name) { - model = element; - } - }); - final old = FFill() - .fromJson(widget.fill.toJson()); - widget.fill.paletteStyle = model!.id; - widget.callBack( - widget.fill, - false, - old, - ); - }, - ), - ), - ], - ), - ], - ); - }, - ); - }, - ); - }, - ) - : const SizedBox(), + }, + ), + ), + ], + ), + ], + ); + }, + ); + }, ); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart index 8b4dfd83..fedcc13c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart @@ -80,232 +80,220 @@ class SrcImageControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder( - builder: (final context, final prjState) => prjState is ProjectLoaded - ? BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.image.value ?? ''; - }); - nodeId = state.first.nid; + return BlocListener>( + listener: (final context, final state) { + if (state.isNotEmpty) { + if (state.first.nid != nodeId) { + setState(() { + isUpdated = true; + controller.text = widget.image.value ?? ''; + }); + nodeId = state.first.nid; + } + } + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TParagraph( + widget.title, + ), + CDropdownForType( + value: widget.image.type == FTextTypeEnum.asset + ? 'asset' + : widget.image.type == FTextTypeEnum.dataset + ? 'dataset' + : widget.image.type == FTextTypeEnum.state + ? 'state' + : widget.image.type == FTextTypeEnum.param + ? 'param' + : 'text', + items: const ['text', 'param', 'state', 'dataset', 'asset'], + onChange: (final value) { + var typeOfInput = FTextTypeEnum.text; + if (value == 'text') { + typeOfInput = FTextTypeEnum.text; + } + if (value == 'param') { + typeOfInput = FTextTypeEnum.param; + } + if (value == 'state') { + typeOfInput = FTextTypeEnum.state; + } + if (value == 'dataset') { + typeOfInput = FTextTypeEnum.dataset; } - } + if (value == 'asset') { + typeOfInput = FTextTypeEnum.asset; + } + final old = widget.image; + final newValue = widget.image..type = typeOfInput; + widget.callBack(newValue, old); + }, + ), + ], + ), + if (widget.image.type == FTextTypeEnum.text) + CTextField( + text: widget.image.value, + controller: controller, + callBack: (final value) { + value.replaceAll(r'\', r'\\'); + final old = widget.image; + widget.image.value = value; + widget.callBack(widget.image, old); }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TParagraph( - widget.title, - ), - CDropdownForType( - value: widget.image.type == FTextTypeEnum.asset - ? 'asset' - : widget.image.type == FTextTypeEnum.dataset - ? 'dataset' - : widget.image.type == FTextTypeEnum.state - ? 'state' - : widget.image.type == FTextTypeEnum.param - ? 'param' - : 'text', - items: const [ - 'text', - 'param', - 'state', - 'dataset', - 'asset' - ], - onChange: (final value) { - var typeOfInput = FTextTypeEnum.text; - if (value == 'text') { - typeOfInput = FTextTypeEnum.text; - } - if (value == 'param') { - typeOfInput = FTextTypeEnum.param; - } - if (value == 'state') { - typeOfInput = FTextTypeEnum.state; - } - if (value == 'dataset') { - typeOfInput = FTextTypeEnum.dataset; - } - if (value == 'asset') { - typeOfInput = FTextTypeEnum.asset; - } - final old = widget.image; - final newValue = widget.image..type = typeOfInput; - widget.callBack(newValue, old); - }, - ), - ], - ), - if (widget.image.type == FTextTypeEnum.text) - CTextField( - text: widget.image.value, - controller: controller, - callBack: (final value) { - value.replaceAll(r'\', r'\\'); - final old = widget.image; - widget.image.value = value; - widget.callBack(widget.image, old); - }, - onSubmitted: (final value) { - value.replaceAll(r'\', r'\\'); - final old = widget.image; - widget.image.value = value; - widget.callBack(widget.image, old); - }, - ), - if (widget.image.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params - .map((final e) => e.name) - .toSet() - .toList() - .contains(widget.image.paramName) - ? widget.image.paramName - : null, - items: widget.page.params - .map((final e) => e.name) - .toSet() - .toList(), - onChange: (final newValue) { - final old = widget.image; - widget.image.paramName = newValue; - widget.callBack(widget.image, old); - }, - ), - if (widget.image.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states - .map((final e) => e.name) - .toSet() - .toList() - .contains(widget.image.stateName) - ? widget.image.stateName - : null, - items: widget.page.states - .map((final e) => e.name) - .toSet() - .toList(), - onChange: (final newValue) { - final old = widget.image; - widget.image.stateName = newValue; - widget.callBack(widget.image, old); - }, - ), - if (widget.image.type == FTextTypeEnum.dataset) - CDropdown( - value: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toSet() - .contains(widget.image.datasetName) - ? widget.image.datasetName - : null, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toSet() - .toList(), - onChange: (final newValue) { - setState(() { - databaseName = newValue!; - }); - final old = widget.image; - widget.image.datasetName = newValue; - widget.callBack(widget.image, old); - }, - ), - if (widget.image.type == FTextTypeEnum.dataset && - widget.image.datasetName != null) - Padding( - padding: EI.smT, - child: CDropdown( - value: widget.page.datasets.indexWhere( - (final element) => - element.getName == - widget.image.datasetName, - ) != - -1 - ? widget.image.datasetAttr - : null, - items: list, - onChange: (final newValue) { - setState(() { - databaseAttribute = newValue!; - }); - final old = widget.image; - widget.image.datasetAttr = newValue; - widget.callBack(widget.image, old); - }, - ), - ), - if (widget.image.type == FTextTypeEnum.asset) - BlocBuilder( - builder: (final context, final client) { - if (client == null) return const SizedBox(); - final _future = getList(client, prjState.prj); - return FutureBuilder>( - future: _future, - builder: (final context, final snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator(), - ); - } - final list = snapshot.data ?? []; - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Row( - children: [ - Expanded( - child: CDropdownImageAssets( - value: widget.image.file, - items: list, - onChange: (final value) { - final old = widget.image; - widget.image.file = value; - widget.callBack(widget.image, old); - }, - ), - ), - ], - ), - if (list.isEmpty) - Padding( - padding: const EdgeInsets.only(bottom: 8), - child: GestureDetector( - onTap: () { - BlocProvider.of(context) - .changePanel( - PanelsEnum.assets, - ); - }, - child: const MouseRegion( - cursor: SystemMouseCursors.click, - child: TDetailLabel( - 'Your bucket is empty. Upload your first file >', - ), - ), - ), - ), - ], - ); - }, - ); - }, - ), - ], + onSubmitted: (final value) { + value.replaceAll(r'\', r'\\'); + final old = widget.image; + widget.image.value = value; + widget.callBack(widget.image, old); + }, + ), + if (widget.image.type == FTextTypeEnum.param) + CDropdown( + value: widget.page.params + .map((final e) => e.name) + .toSet() + .toList() + .contains(widget.image.paramName) + ? widget.image.paramName + : null, + items: + widget.page.params.map((final e) => e.name).toSet().toList(), + onChange: (final newValue) { + final old = widget.image; + widget.image.paramName = newValue; + widget.callBack(widget.image, old); + }, + ), + if (widget.image.type == FTextTypeEnum.state) + CDropdown( + value: widget.page.states + .map((final e) => e.name) + .toSet() + .toList() + .contains(widget.image.stateName) + ? widget.image.stateName + : null, + items: + widget.page.states.map((final e) => e.name).toSet().toList(), + onChange: (final newValue) { + final old = widget.image; + widget.image.stateName = newValue; + widget.callBack(widget.image, old); + }, + ), + if (widget.image.type == FTextTypeEnum.dataset) + CDropdown( + value: widget.page.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .toSet() + .contains(widget.image.datasetName) + ? widget.image.datasetName + : null, + items: widget.page.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .toSet() + .toList(), + onChange: (final newValue) { + setState(() { + databaseName = newValue!; + }); + final old = widget.image; + widget.image.datasetName = newValue; + widget.callBack(widget.image, old); + }, + ), + if (widget.image.type == FTextTypeEnum.dataset && + widget.image.datasetName != null) + Padding( + padding: EI.smT, + child: CDropdown( + value: widget.page.datasets.indexWhere( + (final element) => + element.getName == widget.image.datasetName, + ) != + -1 + ? widget.image.datasetAttr + : null, + items: list, + onChange: (final newValue) { + setState(() { + databaseAttribute = newValue!; + }); + final old = widget.image; + widget.image.datasetAttr = newValue; + widget.callBack(widget.image, old); + }, ), - ) - : const SizedBox(), + ), + if (widget.image.type == FTextTypeEnum.asset) + BlocBuilder( + builder: (final context, final client) { + if (client == null) return const SizedBox(); + final _future = getList( + client, + BlocProvider.of(context).state!, + ); + return FutureBuilder>( + future: _future, + builder: (final context, final snapshot) { + if (!snapshot.hasData) { + return const Center( + child: CircularProgressIndicator(), + ); + } + final list = snapshot.data ?? []; + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Row( + children: [ + Expanded( + child: CDropdownImageAssets( + value: widget.image.file, + items: list, + onChange: (final value) { + final old = widget.image; + widget.image.file = value; + widget.callBack(widget.image, old); + }, + ), + ), + ], + ), + if (list.isEmpty) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: GestureDetector( + onTap: () { + BlocProvider.of(context) + .changePanel( + PanelsEnum.assets, + ); + }, + child: const MouseRegion( + cursor: SystemMouseCursors.click, + child: TDetailLabel( + 'Your bucket is empty. Upload your first file >', + ), + ), + ), + ), + ], + ); + }, + ); + }, + ), + ], + ), ); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/text.dart b/teta_widgets/lib/src/elements/controls/atoms/text.dart index 92b2a200..13b33e94 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text.dart @@ -68,7 +68,7 @@ class PaddingsState extends State { keyController = TextEditingController(); nodeId = widget.node.nid; try { - text = widget.value.getValue(context) ?? ''; + text = widget.value.getValue(context); controller.text = text!; typeOfInput = widget.value.type!; if (widget.value.datasetName != null) { @@ -92,7 +92,7 @@ class PaddingsState extends State { index != -1 ? widget.page.datasets[index] : DatasetObject.empty(); return BlocListener( listener: (final context, final device) { - controller.text = widget.value.getValue(context) ?? ''; + controller.text = widget.value.getValue(context); }, child: BlocBuilder( builder: (final context, final device) => @@ -102,7 +102,7 @@ class PaddingsState extends State { if (state.first.nid != nodeId) { if (mounted) { nodeId = state.first.nid; - controller.text = widget.value.getValue(context) ?? ''; + controller.text = widget.value.getValue(context); } } } @@ -439,9 +439,8 @@ class PaddingsState extends State { if (widget.value.type == FTextTypeEnum.languages) CDropdown( value: widget.value.keyTranslator, - items: ((BlocProvider.of(context).state - as ProjectLoaded) - .prj + items: (BlocProvider.of(context) + .state! .config ?.appLanguage ?.terms ?? diff --git a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart index c22cba1b..020e24b3 100644 --- a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart @@ -53,10 +53,7 @@ class _WAirtableFetchState extends State { widget.state.loop, context, ); - final config = - (BlocProvider.of(context).state as ProjectLoaded) - .prj - .config; + final config = BlocProvider.of(context).state!.config; var dbElements = []; if (config != null && config.isAirtableReady) { final airtable = context.read(); diff --git a/teta_widgets/lib/src/elements/widgets/component.dart b/teta_widgets/lib/src/elements/widgets/component.dart index 9f9890bd..1cee820e 100644 --- a/teta_widgets/lib/src/elements/widgets/component.dart +++ b/teta_widgets/lib/src/elements/widgets/component.dart @@ -40,12 +40,12 @@ class _WComponentState extends State { PageObject? component; String? componentName = ''; WebViewXController? webViewController; - ProjectLoaded? prjState; + late ProjectObject prj; bool isLoaded = false; @override void initState() { - prjState = BlocProvider.of(context).state as ProjectLoaded; + prj = BlocProvider.of(context).state!; if (componentName != widget.componentName) { calc(); } @@ -53,16 +53,19 @@ class _WComponentState extends State { } Future calc() async { - prjState = BlocProvider.of(context).state as ProjectLoaded; + prj = BlocProvider.of(context).state!; PageObject? _component; - _component = prjState!.prj.pages!.firstWhereOrNull( + _component = prj.pages!.firstWhereOrNull( (final element) => element.name == widget.componentName, ); if (_component != null) { _component = _component.copyWith( states: [ - ..._component.states.map((final e) => e.toJson()).map(VariableObject.fromJson).toList() + ..._component.states + .map((final e) => e.toJson()) + .map(VariableObject.fromJson) + .toList() ], ); final nodes = await fetch(_component, context); @@ -124,7 +127,7 @@ class _WComponentState extends State { ? BlocProvider( create: (final context) => PageCubit() ..onFocus( - prj: prjState!.prj, + prj: prj, page: component!, context: context, forPlay: widget.state.forPlay, @@ -175,7 +178,8 @@ class _WComponentState extends State { ? '${element.get}' : element.firstValueForInitialization(); if (listVariableObjectParams.length > 1) { - if (listVariableObjectParams.indexOf(element) == listVariableObjectParams.length - 1) { + if (listVariableObjectParams.indexOf(element) == + listVariableObjectParams.length - 1) { parametersString += '${rc.camelCase}=$value'; } else { parametersString += '${rc.camelCase}=$value&'; @@ -196,48 +200,64 @@ class _WComponentState extends State { final list = [ DatasetObject( name: 'Parameters', - map: widget.state.params.map((final e) => {e.name: e.get}).toList(), + map: widget.state.params + .map((final e) => {e.name: e.get}) + .toList(), ), DatasetObject( name: 'States', - map: widget.state.states.map((final e) => {e.name: e.get}).toList(), + map: widget.state.states + .map((final e) => {e.name: e.get}) + .toList(), ), ...widget.state.dataset, ]; Map? selectedDataset; for (final element in list) { if (element.getName == widget.paramsToSend?[e.id]['dataset']) { - selectedDataset = {'name': element.getName, 'map': element.getMap}; + selectedDataset = { + 'name': element.getName, + 'map': element.getMap + }; } } VariableObject? variable; - if (selectedDataset?['name'] == 'Parameters' || selectedDataset?['name'] == 'States') { + if (selectedDataset?['name'] == 'Parameters' || + selectedDataset?['name'] == 'States') { final map = selectedDataset!['map'] as List>; for (final element in map) { if (element.keys.toList()[widget.state.loop ?? 0] == widget.paramsToSend?[e.id]?['label']) { - if (element[element.keys.toList()[widget.state.loop ?? 0]] is String || - element[element.keys.toList()[widget.state.loop ?? 0]] is int || - element[element.keys.toList()[widget.state.loop ?? 0]] is double) { + if (element[element.keys.toList()[widget.state.loop ?? 0]] + is String || + element[element.keys.toList()[widget.state.loop ?? 0]] + is int || + element[element.keys.toList()[widget.state.loop ?? 0]] + is double) { variable = VariableObject( name: element.keys.toList()[widget.state.loop ?? 0], - value: element[element.keys.toList()[widget.state.loop ?? 0]], + value: + element[element.keys.toList()[widget.state.loop ?? 0]], ); } - if (element[element.keys.toList()[widget.state.loop ?? 0]] is CameraController) { + if (element[element.keys.toList()[widget.state.loop ?? 0]] + is CameraController) { variable = VariableObject( name: element.keys.toList()[widget.state.loop ?? 0], type: VariableType.cameraController, controller: - element[element.keys.toList()[widget.state.loop ?? 0]] as CameraController, + element[element.keys.toList()[widget.state.loop ?? 0]] + as CameraController, ); } - if (element[element.keys.toList()[widget.state.loop ?? 0]] is XFile) { + if (element[element.keys.toList()[widget.state.loop ?? 0]] + is XFile) { debugPrint('is XFile'); variable = VariableObject( name: element.keys.toList()[widget.state.loop ?? 0], type: VariableType.file, - file: element[element.keys.toList()[widget.state.loop ?? 0]] as XFile, + file: element[element.keys.toList()[widget.state.loop ?? 0]] + as XFile, ); } } @@ -265,7 +285,8 @@ class _WComponentState extends State { //! this in the editor need to be in a sizedBox Widget hardCoded(final PageObject page) { - final _paramsString = initializeParamsForUri(getVariableObjectsFromParams(page)); + final _paramsString = + initializeParamsForUri(getVariableObjectsFromParams(page)); return WebViewX( width: double.maxFinite, height: double.maxFinite, diff --git a/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart b/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart index c03f892d..fe2917cf 100644 --- a/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart +++ b/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart @@ -138,7 +138,8 @@ class _WGoogleMapsState extends State { } } else if (state is GoogleMapsChangeMapStyleState) { if (googleMapsController.isCompleted) { - await (await googleMapsController.future).setMapStyle(state.uiModel.style); + await (await googleMapsController.future) + .setMapStyle(state.uiModel.style); } } else if (state is GoogleMapsReloadDataState) { if (kDebugMode) { @@ -148,7 +149,8 @@ class _WGoogleMapsState extends State { try { markersDataset = widget.state.dataset .firstWhere( - (final element) => element.getName == widget.markersDatasetName, + (final element) => + element.getName == widget.markersDatasetName, ) .getMap; } catch (e) { @@ -191,8 +193,8 @@ class _WGoogleMapsState extends State { Future initData() async { try { - googleMapsKey = (BlocProvider.of(context).state as ProjectLoaded) - .prj + googleMapsKey = BlocProvider.of(context) + .state! .config ?.googleMapsKey ?? ''; diff --git a/teta_widgets/lib/src/elements/widgets/map.dart b/teta_widgets/lib/src/elements/widgets/map.dart index 9ce9074f..3469ae25 100644 --- a/teta_widgets/lib/src/elements/widgets/map.dart +++ b/teta_widgets/lib/src/elements/widgets/map.dart @@ -55,9 +55,11 @@ class _WMapState extends State { Future init() async { final page = BlocProvider.of(context).state; if (widget.controller.type == FTextTypeEnum.param) { - variable = page.params.firstWhereOrNull((final e) => e.name == widget.controller.paramName); + variable = page.params + .firstWhereOrNull((final e) => e.name == widget.controller.paramName); } else { - variable = page.states.firstWhereOrNull((final e) => e.name == widget.controller.stateName); + variable = page.states + .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } variable?.mapController ??= MapController( location: LatLng(41.52, 12.30), @@ -136,8 +138,8 @@ class _WMapState extends State { return NodeSelectionBuilder( node: widget.state.node, forPlay: widget.state.forPlay, - child: !(BlocProvider.of(context).state as ProjectLoaded) - .prj + child: !BlocProvider.of(context) + .state! .config! .mapEnabled ? const DecoratedBox( @@ -154,7 +156,9 @@ class _WMapState extends State { final markers = []; for (final child in widget.children) { if ((child as NDynamic).intrinsicState.type == NType.marker) { - final lat = (child.body.attributes[DBKeys.latitude] as FTextTypeInput).get( + final lat = (child.body.attributes[DBKeys.latitude] + as FTextTypeInput) + .get( widget.state.params, widget.state.states, widget.state.dataset, @@ -162,7 +166,9 @@ class _WMapState extends State { widget.state.loop, context, ); - final lng = (child.body.attributes[DBKeys.longitude] as FTextTypeInput).get( + final lng = (child.body.attributes[DBKeys.longitude] + as FTextTypeInput) + .get( widget.state.params, widget.state.states, widget.state.dataset, @@ -191,7 +197,8 @@ class _WMapState extends State { ) .toList(); for (var i = 0; i < markersChildren.length; i++) { - if ((widget.children[i] as NDynamic).intrinsicState.type == NType.marker) { + if ((widget.children[i] as NDynamic).intrinsicState.type == + NType.marker) { markersWidgets.add( widget.children[i].toWidget(state: widget.state), ); @@ -218,11 +225,12 @@ class _WMapState extends State { if (variable != null && variable?.mapController != null) Map( controller: variable!.mapController!, - builder: (final context, final x, final y, final z) { + builder: + (final context, final x, final y, final z) { final url = - 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${(BlocProvider.of(context).state as ProjectLoaded).prj.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; final darkUrl = - 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${(BlocProvider.of(context).state as ProjectLoaded).prj.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; return CNetworkImage( nid: widget.state.node.nid, src: widget.flag ? darkUrl : url, @@ -305,7 +313,9 @@ double _eclipticObliquity(final double julianDay) { (46.836769 / 3600 - T * (0.0001831 / 3600 + - T * (0.00200340 / 3600 - T * (0.576e-6 / 3600 - T * 4.34e-8 / 3600)))); + T * + (0.00200340 / 3600 - + T * (0.576e-6 / 3600 - T * 4.34e-8 / 3600)))); return epsilon; } diff --git a/teta_widgets/lib/src/elements/widgets/map_builder.dart b/teta_widgets/lib/src/elements/widgets/map_builder.dart index eee93b0d..26aa18d7 100644 --- a/teta_widgets/lib/src/elements/widgets/map_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/map_builder.dart @@ -69,9 +69,11 @@ class _WMapBuilderState extends State { Future init() async { final page = BlocProvider.of(context).state; if (widget.controller.type == FTextTypeEnum.param) { - variable = page.params.firstWhereOrNull((final e) => e.name == widget.controller.paramName); + variable = page.params + .firstWhereOrNull((final e) => e.name == widget.controller.paramName); } else { - variable = page.states.firstWhereOrNull((final e) => e.name == widget.controller.stateName); + variable = page.states + .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } variable?.mapController ??= MapController( location: LatLng(41.52, 12.30), @@ -160,16 +162,18 @@ class _WMapBuilderState extends State { _setDataset(); final index = widget.datasetInput.datasetName != null ? widget.state.dataset.indexWhere( - (final element) => element.getName == widget.datasetInput.datasetName, + (final element) => + element.getName == widget.datasetInput.datasetName, ) : -1; - final db = index != -1 ? widget.state.dataset[index] : DatasetObject.empty(); + final db = + index != -1 ? widget.state.dataset[index] : DatasetObject.empty(); return NodeSelectionBuilder( node: widget.state.node, forPlay: widget.state.forPlay, - child: !(BlocProvider.of(context).state as ProjectLoaded) - .prj + child: !BlocProvider.of(context) + .state! .config! .mapEnabled ? const DecoratedBox( @@ -186,9 +190,11 @@ class _WMapBuilderState extends State { final markers = []; for (var i = 0; i < db.getMap.length; i++) { - if ((widget.child as NDynamic?)?.intrinsicState.type == NType.marker) { - final lat = - (widget.child!.body.attributes[DBKeys.latitude] as FTextTypeInput).get( + if ((widget.child as NDynamic?)?.intrinsicState.type == + NType.marker) { + final lat = (widget.child!.body.attributes[DBKeys.latitude] + as FTextTypeInput) + .get( widget.state.params, widget.state.states, widget.state.dataset, @@ -196,8 +202,9 @@ class _WMapBuilderState extends State { i, context, ); - final lng = - (widget.child!.body.attributes[DBKeys.longitude] as FTextTypeInput).get( + final lng = (widget.child!.body.attributes[DBKeys.longitude] + as FTextTypeInput) + .get( widget.state.params, widget.state.states, widget.state.dataset, @@ -218,14 +225,16 @@ class _WMapBuilderState extends State { final markersWidgets = []; final normalWidgets = db.getMap .map( - (final e) => widget.child!.intrinsicState.type != NType.marker - ? widget.child!.toWidget(state: widget.state) - : const SizedBox(), + (final e) => + widget.child!.intrinsicState.type != NType.marker + ? widget.child!.toWidget(state: widget.state) + : const SizedBox(), ) .toList(); for (var i = 0; i < markersChildren.length; i++) { - if ((widget.child as NDynamic?)?.intrinsicState.type == NType.marker) { + if ((widget.child as NDynamic?)?.intrinsicState.type == + NType.marker) { markersWidgets.add( widget.child!.toWidget(state: widget.state), ); @@ -252,11 +261,12 @@ class _WMapBuilderState extends State { if (variable != null && variable?.mapController != null) Map( controller: variable!.mapController!, - builder: (final context, final x, final y, final z) { + builder: + (final context, final x, final y, final z) { final url = - 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${(BlocProvider.of(context).state as ProjectLoaded).prj.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; final darkUrl = - 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${(BlocProvider.of(context).state as ProjectLoaded).prj.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; return CNetworkImage( nid: widget.state.node.nid, src: widget.flag ? darkUrl : url, @@ -283,7 +293,8 @@ class _WMapBuilderState extends State { final index = widget.state.dataset.indexWhere( (final element) => element.getName == widget.datasetInput.datasetName, ); - final db = index != -1 ? widget.state.dataset[index] : DatasetObject.empty(); + final db = + index != -1 ? widget.state.dataset[index] : DatasetObject.empty(); if (mounted) { if (db.getName != '') { setState(() { @@ -355,7 +366,9 @@ double _eclipticObliquity(final double julianDay) { (46.836769 / 3600 - T * (0.0001831 / 3600 + - T * (0.00200340 / 3600 - T * (0.576e-6 / 3600 - T * 4.34e-8 / 3600)))); + T * + (0.00200340 / 3600 - + T * (0.576e-6 / 3600 - T * 4.34e-8 / 3600)))); return epsilon; } diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart index 6904fa01..cb8bf018 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart @@ -38,8 +38,8 @@ class _WCMSLoggedUserState extends State { Future load() async { final user = await TetaCMS.instance.auth.user.get; - if (((BlocProvider.of(context).state as ProjectLoaded) - .prj + if ((BlocProvider.of(context) + .state! .config ?.isRevenueCatEnabled ?? false) && @@ -90,7 +90,9 @@ class _WCMSLoggedUserState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { From 0f463988ef212e7dff2a819441c5927d38547bf4 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Fri, 30 Dec 2022 15:46:39 +0100 Subject: [PATCH 02/23] freat(working on drag & drop) --- .../src/elements/builder/drag_and_drop.dart | 47 ++++++++ .../src/elements/builder/node_selection.dart | 107 +++++++++++------- .../elements/builder/reorder_children.dart | 19 ++++ .../lib/src/elements/widgets/column.dart | 93 +++++++++++---- .../lib/src/elements/widgets/listview.dart | 97 ++++++++++++---- .../lib/src/elements/widgets/row.dart | 92 +++++++++++---- 6 files changed, 355 insertions(+), 100 deletions(-) create mode 100644 teta_widgets/lib/src/elements/builder/drag_and_drop.dart create mode 100644 teta_widgets/lib/src/elements/builder/reorder_children.dart diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart new file mode 100644 index 00000000..084ebf75 --- /dev/null +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:teta_core/teta_core.dart'; + +class DragAndDropBuilder extends StatefulWidget { + const DragAndDropBuilder({ + final Key? key, + required this.child, + }) : super(key: key); + + final Widget child; + + @override + State createState() => _DragAndDropBuilderState(); +} + +class _DragAndDropBuilderState extends State { + bool isDragging = false; + + @override + Widget build(final BuildContext context) { + return DragTarget( + onAccept: (final data) { + setState(() { + isDragging = true; + }); + }, + onMove: (final details) { + setState(() { + isDragging = true; + }); + }, + onLeave: (final details) { + setState(() { + isDragging = false; + }); + }, + builder: (final context, final candidateData, final rejectedData) { + if (!isDragging) return widget.child; + return DecoratedBox( + position: DecorationPosition.foreground, + decoration: const BoxDecoration(color: Colors.white30), + child: widget.child, + ); + }, + ); + } +} diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index b76c2475..6caa6bc8 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/rendering/find.dart'; import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/elements/builder/drag_and_drop.dart'; // Project imports: import 'package:teta_widgets/src/elements/nodes/node.dart'; @@ -49,21 +50,23 @@ class NodeSelectionState extends State { @override Widget build(final BuildContext context) { if (widget.forPlay) return body(); - return MouseRegion( - onEnter: (final e) { - BlocProvider.of(context).add(OnHover(node: widget.node)); - }, - onExit: (final e) { - if (parent != null) { - BlocProvider.of(context).add(OnHover(node: parent!)); - } - }, - child: GestureDetector( - onTap: () { - BlocProvider.of(context).add(OnFocus(node: widget.node)); - BlocProvider.of(context).jumpTo(context, widget.node); + return DragAndDropBuilder( + child: MouseRegion( + onEnter: (final e) { + BlocProvider.of(context).add(OnHover(node: widget.node)); + }, + onExit: (final e) { + if (parent != null) { + BlocProvider.of(context).add(OnHover(node: parent!)); + } }, - child: body(), + child: GestureDetector( + onTap: () { + BlocProvider.of(context).add(OnFocus(node: widget.node)); + BlocProvider.of(context).jumpTo(context, widget.node); + }, + child: body(), + ), ), ); /*return BlocBuilder>( @@ -161,35 +164,61 @@ class NodeSelectionState extends State { Widget body() { return BlocBuilder>( - buildWhen: (final previous, final current) => current != previous, builder: (final context, final onFocusNodes) { return BlocBuilder( - buildWhen: (final previous, final current) => current != previous, builder: (final context, final onHover) { - return DecoratedBox( - decoration: BoxDecoration( - border: Border.all( - color: onFocusNodes.firstWhereOrNull( - (final element) => - element.nid == widget.node.nid || - onHover.nid == widget.node.nid, - ) != - null - ? primaryColor - : Colors.transparent, - style: - (widget.forPlay) ? BorderStyle.none : BorderStyle.solid, - width: onFocusNodes.firstWhereOrNull( - (final element) => element.nid == widget.node.nid, - ) != - null - ? 1 - : onHover.nid == widget.node.nid - ? 2 - : 0, + return Stack( + clipBehavior: Clip.none, + children: [ + DecoratedBox( + position: DecorationPosition.foreground, + decoration: BoxDecoration( + border: Border.all( + color: onFocusNodes.firstWhereOrNull( + (final element) => + element.nid == widget.node.nid, + ) != + null || + onHover.nid == widget.node.nid + ? primaryColor + : Colors.transparent, + style: (widget.forPlay) + ? BorderStyle.none + : BorderStyle.solid, + width: onFocusNodes.firstWhereOrNull( + (final element) => + element.nid == widget.node.nid, + ) != + null + ? 1 + : onHover.nid == widget.node.nid + ? 2 + : 0, + ), + ), + child: widget.child, ), - ), - child: widget.child, + if (onFocusNodes.firstWhereOrNull( + (final element) => element.nid == widget.node.nid, + ) != + null || + onHover.nid == widget.node.nid) + Transform.translate( + offset: const Offset(0, -20), + child: ColoredBox( + color: primaryColor, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 2, + horizontal: 4, + ), + child: TDetailLabel( + widget.node.intrinsicState.displayName, + ), + ), + ), + ), + ], ); /*Positioned( bottom: 0, diff --git a/teta_widgets/lib/src/elements/builder/reorder_children.dart b/teta_widgets/lib/src/elements/builder/reorder_children.dart new file mode 100644 index 00000000..773474b5 --- /dev/null +++ b/teta_widgets/lib/src/elements/builder/reorder_children.dart @@ -0,0 +1,19 @@ +import 'package:teta_repositories/teta_repositories.dart'; +import 'package:teta_widgets/src/elements/index.dart'; + +class ReorderChildren { + static void reorder( + final CNode node, + final List children, + final int oldIndex, + final int newIndex, + ) { + final child = children.removeAt(oldIndex); + children.insert(newIndex, child); + final id = node.childrenIds.ids.removeAt(oldIndex); + node.childrenIds.ids.insert(newIndex, id); + NodeRepository.changeNode( + node: node, + ); + } +} diff --git a/teta_widgets/lib/src/elements/widgets/column.dart b/teta_widgets/lib/src/elements/widgets/column.dart index 905013d3..34d0fbd6 100644 --- a/teta_widgets/lib/src/elements/widgets/column.dart +++ b/teta_widgets/lib/src/elements/widgets/column.dart @@ -1,13 +1,17 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:reorderables/reorderables.dart'; +import 'package:teta_core/teta_core.dart'; // Package imports: import 'package:teta_widgets/src/core/teta_widget/index.dart'; +import 'package:teta_widgets/src/elements/builder/reorder_children.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; // ignore_for_file: public_member_api_docs -class WColumn extends StatelessWidget { +class WColumn extends StatefulWidget { /// Returns [Column] widget in Teta const WColumn( final Key? key, { @@ -24,27 +28,78 @@ class WColumn extends StatelessWidget { final FCrossAxisAlignment crossAxisAlignment; final FMainAxisSize mainAxisSize; + @override + State createState() => _WColumnState(); +} + +class _WColumnState extends State { + List children = []; + + @override + void initState() { + children = widget.children; + super.initState(); + } + @override Widget build(final BuildContext context) { return TetaWidget( - state: state, - child: Column( - mainAxisSize: mainAxisSize.get, - mainAxisAlignment: mainAxisAlignment.get, - crossAxisAlignment: crossAxisAlignment.get, - children: children.isNotEmpty - ? children - .map( - (final e) => e.toWidget(state: state), - ) - .toList() - : [ - PlaceholderChildBuilder( - name: state.node.intrinsicState.displayName, - node: state.node, - forPlay: state.forPlay, - ), - ], + state: widget.state, + child: BlocBuilder>( + builder: (final context, final nodes) { + if (nodes.length == 1) { + final index = children + .indexWhere((final element) => element.nid == nodes.first.nid); + if (index != -1) { + return ReorderableColumn( + onReorder: (final oldIndex, final newIndex) { + ReorderChildren.reorder( + widget.state.node, + children, + oldIndex, + newIndex, + ); + setState(() {}); + }, + needsLongPressDraggable: false, + mainAxisSize: widget.mainAxisSize.get, + mainAxisAlignment: widget.mainAxisAlignment.get, + crossAxisAlignment: widget.crossAxisAlignment.get, + children: children.isNotEmpty + ? children + .map( + (final e) => e.toWidget(state: widget.state), + ) + .toList() + : [ + PlaceholderChildBuilder( + name: widget.state.node.intrinsicState.displayName, + node: widget.state.node, + forPlay: widget.state.forPlay, + ), + ], + ); + } + } + return Column( + mainAxisSize: widget.mainAxisSize.get, + mainAxisAlignment: widget.mainAxisAlignment.get, + crossAxisAlignment: widget.crossAxisAlignment.get, + children: children.isNotEmpty + ? children + .map( + (final e) => e.toWidget(state: widget.state), + ) + .toList() + : [ + PlaceholderChildBuilder( + name: widget.state.node.intrinsicState.displayName, + node: widget.state.node, + forPlay: widget.state.forPlay, + ), + ], + ); + }, ), ); } diff --git a/teta_widgets/lib/src/elements/widgets/listview.dart b/teta_widgets/lib/src/elements/widgets/listview.dart index 2d9251a8..8832258d 100644 --- a/teta_widgets/lib/src/elements/widgets/listview.dart +++ b/teta_widgets/lib/src/elements/widgets/listview.dart @@ -4,14 +4,16 @@ // Flutter imports: import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; // Package imports: import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; +import 'package:teta_widgets/src/elements/builder/reorder_children.dart'; import 'package:teta_widgets/src/elements/features/physic.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; -class WListView extends StatelessWidget { +class WListView extends StatefulWidget { /// Returns a ListView in Teta const WListView( final Key? key, { @@ -38,31 +40,42 @@ class WListView extends StatelessWidget { final bool isReverse; final bool shrinkWrap; + @override + State createState() => _WListViewState(); +} + +class _WListViewState extends State { + List children = []; + + @override + void initState() { + children = widget.children; + super.initState(); + } + @override Widget build(final BuildContext context) { return TetaWidget( - state: state, + state: widget.state, child: NotificationListener( onNotification: (final scrollEnd) { final metrics = scrollEnd.metrics; if (metrics.atEdge) { final isTop = metrics.pixels == 0; if (isTop) { - Logger.printMessage('At the top'); GestureBuilder.get( context: context, - state: state, + state: widget.state, gesture: ActionGesture.scrollToTop, - action: action, + action: widget.action, actionValue: null, ); } else { - Logger.printMessage('At the bottom'); GestureBuilder.get( context: context, - state: state, + state: widget.state, gesture: ActionGesture.scrollToBottom, - action: action, + action: widget.action, actionValue: null, ); } @@ -71,21 +84,59 @@ class WListView extends StatelessWidget { }, child: ScrollConfiguration( behavior: _MyCustomScrollBehavior(), - child: ListView.builder( - reverse: isReverse, - physics: physic.physics, - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - scrollDirection: isVertical ? Axis.vertical : Axis.horizontal, - itemCount: children.isEmpty ? 1 : children.length, - itemBuilder: (final context, final index) { - return children.isNotEmpty - ? children[index].toWidget(state: state) - : PlaceholderChildBuilder( - name: state.node.intrinsicState.displayName, - node: state.node, - forPlay: state.forPlay, - ); + child: BlocBuilder>( + builder: (final context, final nodes) { + if (nodes.length == 1) { + final index = widget.children.indexWhere( + (final element) => element.nid == nodes.first.nid, + ); + if (index != -1) { + return ReorderableListView.builder( + onReorder: (final oldIndex, final newIndex) { + ReorderChildren.reorder( + widget.state.node, + children, + oldIndex, + newIndex, + ); + setState(() {}); + }, + reverse: widget.isReverse, + physics: widget.physic.physics, + scrollDirection: + widget.isVertical ? Axis.vertical : Axis.horizontal, + itemCount: children.isEmpty ? 1 : children.length, + itemBuilder: (final context, final index) { + return children.isNotEmpty + ? children[index].toWidget(state: widget.state) + : PlaceholderChildBuilder( + name: + widget.state.node.intrinsicState.displayName, + node: widget.state.node, + forPlay: widget.state.forPlay, + ); + }, + ); + } + } + return ListView.builder( + reverse: widget.isReverse, + physics: widget.physic.physics, + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + scrollDirection: + widget.isVertical ? Axis.vertical : Axis.horizontal, + itemCount: children.isEmpty ? 1 : children.length, + itemBuilder: (final context, final index) { + return children.isNotEmpty + ? children[index].toWidget(state: widget.state) + : PlaceholderChildBuilder( + name: widget.state.node.intrinsicState.displayName, + node: widget.state.node, + forPlay: widget.state.forPlay, + ); + }, + ); }, ), ), diff --git a/teta_widgets/lib/src/elements/widgets/row.dart b/teta_widgets/lib/src/elements/widgets/row.dart index f656f33d..3fe33867 100644 --- a/teta_widgets/lib/src/elements/widgets/row.dart +++ b/teta_widgets/lib/src/elements/widgets/row.dart @@ -3,11 +3,15 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:reorderables/reorderables.dart'; +import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; +import 'package:teta_widgets/src/elements/builder/reorder_children.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; -class WRow extends StatelessWidget { +class WRow extends StatefulWidget { /// Constructor const WRow( final Key? key, { @@ -29,27 +33,77 @@ class WRow extends StatelessWidget { final FCrossAxisAlignment _crossAxisAlignment; final FMainAxisSize _mainAxisSize; + @override + State createState() => _WRowState(); +} + +class _WRowState extends State { + List children = []; + + @override + void initState() { + children = widget._children; + super.initState(); + } + @override Widget build(final BuildContext context) { return TetaWidget( - state: _state, - child: Row( - mainAxisAlignment: _mainAxisAlignment.get, - crossAxisAlignment: _crossAxisAlignment.get, - mainAxisSize: _mainAxisSize.get, - children: _children.isNotEmpty - ? _children - .map( - (final e) => e.toWidget(state: _state), - ) - .toList() - : [ - PlaceholderChildBuilder( - name: _state.node.intrinsicState.displayName, - node: _state.node, - forPlay: _state.forPlay, - ), - ], + state: widget._state, + child: BlocBuilder>( + builder: (final context, final nodes) { + if (nodes.length == 1) { + final index = widget._children + .indexWhere((final element) => element.nid == nodes.first.nid); + if (index != -1) { + return ReorderableRow( + onReorder: (final oldIndex, final newIndex) { + ReorderChildren.reorder( + widget._state.node, + children, + oldIndex, + newIndex, + ); + setState(() {}); + }, + mainAxisAlignment: widget._mainAxisAlignment.get, + crossAxisAlignment: widget._crossAxisAlignment.get, + mainAxisSize: widget._mainAxisSize.get, + children: children.isNotEmpty + ? children + .map( + (final e) => e.toWidget(state: widget._state), + ) + .toList() + : [ + PlaceholderChildBuilder( + name: widget._state.node.intrinsicState.displayName, + node: widget._state.node, + forPlay: widget._state.forPlay, + ), + ], + ); + } + } + return Row( + mainAxisAlignment: widget._mainAxisAlignment.get, + crossAxisAlignment: widget._crossAxisAlignment.get, + mainAxisSize: widget._mainAxisSize.get, + children: widget._children.isNotEmpty + ? widget._children + .map( + (final e) => e.toWidget(state: widget._state), + ) + .toList() + : [ + PlaceholderChildBuilder( + name: widget._state.node.intrinsicState.displayName, + node: widget._state.node, + forPlay: widget._state.forPlay, + ), + ], + ); + }, ), ); } From e1f9418093db43b59c83b4ea2221380b7997b9f9 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Fri, 30 Dec 2022 17:25:11 +0100 Subject: [PATCH 03/23] feat(improving state) --- .../lib/src/core/teta_widget/teta_widget.dart | 3 +- .../core/teta_widget/teta_widget_state.dart | 3 + .../src/elements/builder/drag_and_drop.dart | 65 +++++++++++++++++-- .../src/elements/builder/node_selection.dart | 40 ++++++------ .../builder/node_selection_builder.dart | 16 ++--- .../src/elements/widgets/adapty/paywalls.dart | 16 +++-- .../src/elements/widgets/airtable/fetch.dart | 3 +- .../widgets/animations/anim_config_grid.dart | 3 +- .../widgets/animations/anim_config_list.dart | 3 +- .../widgets/animations/fade_in.dart.dart | 3 +- .../elements/widgets/animations/scale.dart | 3 +- .../elements/widgets/animations/slide.dart | 3 +- .../widgets/apicalls/api_calls_fetch.dart | 24 ++++--- .../src/elements/widgets/bottombaritem.dart | 3 +- .../src/elements/widgets/bouncing_widget.dart | 3 +- .../lib/src/elements/widgets/button.dart | 3 +- .../lib/src/elements/widgets/camera.dart | 3 +- .../lib/src/elements/widgets/checkbox.dart | 6 +- .../lib/src/elements/widgets/component.dart | 4 +- .../widgets/components/login_section.dart | 9 ++- .../lib/src/elements/widgets/cta/apple.dart | 3 +- .../src/elements/widgets/cta/facebook.dart | 3 +- .../lib/src/elements/widgets/cta/github.dart | 3 +- .../lib/src/elements/widgets/cta/google.dart | 3 +- .../src/elements/widgets/cta/microsoft.dart | 3 +- .../lib/src/elements/widgets/cta/twitter.dart | 3 +- .../elements/widgets/cupertino_picker.dart | 3 +- .../widgets/cupertino_segmented_control.dart | 3 +- .../elements/widgets/cupertino_switch.dart | 3 +- .../firebase/firebase_future_builder.dart | 3 +- .../firebase/firebase_is_authenticated.dart | 12 ++-- .../widgets/firebase/firebase_pagination.dart | 4 +- .../firebase/firebase_stream_builder.dart | 3 +- .../widgets/http_requests/future_builder.dart | 15 +++-- .../custom_http_request.dart | 23 +++---- .../lib/src/elements/widgets/map.dart | 3 +- .../lib/src/elements/widgets/map_builder.dart | 3 +- .../lib/src/elements/widgets/mapbox.dart | 3 +- .../src/elements/widgets/material_appbar.dart | 6 +- .../elements/widgets/material_bottombar.dart | 3 +- .../elements/widgets/numeric_step_button.dart | 3 +- .../lib/src/elements/widgets/radio.dart | 3 +- .../elements/widgets/refresh_indicator.dart | 3 +- .../widgets/responsive/wrapper_container.dart | 4 +- .../widgets/supabase/future_builder.dart | 19 ++++-- .../supabase/supabase_stream_builder.dart | 13 ++-- .../lib/src/elements/widgets/tcard.dart | 3 +- .../src/elements/widgets/tcard_builder.dart | 3 +- .../src/elements/widgets/teta_cms/count.dart | 13 ++-- .../widgets/teta_cms/custom_query.dart | 16 +++-- .../src/elements/widgets/teta_cms/fetch.dart | 13 ++-- .../widgets/teta_cms/logged_user.dart | 3 +- .../src/elements/widgets/teta_cms/stream.dart | 16 +++-- .../lib/src/elements/widgets/text.dart | 3 +- .../lib/src/elements/widgets/textbutton.dart | 3 +- .../lib/src/elements/widgets/textfield.dart | 3 +- 56 files changed, 243 insertions(+), 199 deletions(-) diff --git a/teta_widgets/lib/src/core/teta_widget/teta_widget.dart b/teta_widgets/lib/src/core/teta_widget/teta_widget.dart index ff58d451..91ee5432 100644 --- a/teta_widgets/lib/src/core/teta_widget/teta_widget.dart +++ b/teta_widgets/lib/src/core/teta_widget/teta_widget.dart @@ -16,8 +16,7 @@ class TetaWidget extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: GestureBuilderBase.get( context: context, state: state, diff --git a/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart b/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart index afcb1416..4f471aa9 100644 --- a/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart +++ b/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart @@ -9,6 +9,7 @@ class TetaWidgetState { required this.params, required this.states, required this.dataset, + this.isVertical = true, }); /// The original CNode @@ -31,6 +32,8 @@ class TetaWidgetState { /// The dataset list created by other widgets inside the same page final List dataset; + final bool isVertical; + TetaWidgetState copyWith({ final CNode? node, final bool? forPlay, diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart index 084ebf75..bfd6eafb 100644 --- a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -1,12 +1,15 @@ import 'package:flutter/material.dart'; import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/core/teta_widget/index.dart'; class DragAndDropBuilder extends StatefulWidget { const DragAndDropBuilder({ - final Key? key, + required this.state, required this.child, + final Key? key, }) : super(key: key); + final TetaWidgetState state; final Widget child; @override @@ -15,33 +18,83 @@ class DragAndDropBuilder extends StatefulWidget { class _DragAndDropBuilderState extends State { bool isDragging = false; + bool? onLeft; + final key = GlobalKey(); @override Widget build(final BuildContext context) { return DragTarget( + key: key, onAccept: (final data) { + Logger.printDefault('On accept'); setState(() { isDragging = true; }); }, onMove: (final details) { + final leftFlag = details.offset.dx > key.globalPaintBounds!.left && + details.offset.dx <= key.globalPaintBounds!.center.dx; + Logger.printSuccess('Is on left: $leftFlag'); setState(() { isDragging = true; + if (key.globalPaintBounds != null) { + onLeft = leftFlag; + } }); }, onLeave: (final details) { setState(() { isDragging = false; + onLeft = false; }); }, builder: (final context, final candidateData, final rejectedData) { - if (!isDragging) return widget.child; - return DecoratedBox( - position: DecorationPosition.foreground, - decoration: const BoxDecoration(color: Colors.white30), - child: widget.child, + if (!isDragging) { + return widget.child; + } + return Stack( + children: [ + widget.child, + Positioned.fill( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (onLeft ?? false) + TContainer( + width: 5, + height: key.globalPaintBounds!.height, + decoration: const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + if (!(onLeft ?? true)) + TContainer( + width: 5, + height: key.globalPaintBounds!.height, + decoration: const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + ], + ), + ), + ], ); }, ); } } + +extension GlobalKeyExtension on GlobalKey { + Rect? get globalPaintBounds { + final renderObject = currentContext?.findRenderObject(); + final translation = renderObject?.getTransformTo(null).getTranslation(); + if (translation != null && renderObject?.paintBounds != null) { + final offset = Offset(translation.x, translation.y); + return renderObject!.paintBounds.shift(offset); + } else { + return null; + } + } +} diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 6caa6bc8..2beccbf9 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/rendering/find.dart'; import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/core/teta_widget/index.dart'; import 'package:teta_widgets/src/elements/builder/drag_and_drop.dart'; // Project imports: import 'package:teta_widgets/src/elements/nodes/node.dart'; @@ -16,17 +17,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class NodeSelection extends StatefulWidget { /// Make a widget selectable const NodeSelection({ - required this.node, + required this.state, required this.child, - required this.forPlay, - required this.nid, final Key? key, }) : super(key: key); - final CNode node; + final TetaWidgetState state; final Widget child; - final bool forPlay; - final int nid; @override NodeSelectionState createState() => NodeSelectionState(); @@ -42,18 +39,20 @@ class NodeSelectionState extends State { void initState() { parent = FindNodeRendering.findParentByChildrenIds( flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.node, + element: widget.state.node, ); super.initState(); } @override Widget build(final BuildContext context) { - if (widget.forPlay) return body(); + if (widget.state.forPlay) return body(); return DragAndDropBuilder( + state: widget.state, child: MouseRegion( onEnter: (final e) { - BlocProvider.of(context).add(OnHover(node: widget.node)); + BlocProvider.of(context) + .add(OnHover(node: widget.state.node)); }, onExit: (final e) { if (parent != null) { @@ -62,8 +61,10 @@ class NodeSelectionState extends State { }, child: GestureDetector( onTap: () { - BlocProvider.of(context).add(OnFocus(node: widget.node)); - BlocProvider.of(context).jumpTo(context, widget.node); + BlocProvider.of(context) + .add(OnFocus(node: widget.state.node)); + BlocProvider.of(context) + .jumpTo(context, widget.state.node); }, child: body(), ), @@ -176,22 +177,22 @@ class NodeSelectionState extends State { border: Border.all( color: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.node.nid, + element.nid == widget.state.node.nid, ) != null || - onHover.nid == widget.node.nid + onHover.nid == widget.state.node.nid ? primaryColor : Colors.transparent, - style: (widget.forPlay) + style: (widget.state.forPlay) ? BorderStyle.none : BorderStyle.solid, width: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.node.nid, + element.nid == widget.state.node.nid, ) != null ? 1 - : onHover.nid == widget.node.nid + : onHover.nid == widget.state.node.nid ? 2 : 0, ), @@ -199,10 +200,11 @@ class NodeSelectionState extends State { child: widget.child, ), if (onFocusNodes.firstWhereOrNull( - (final element) => element.nid == widget.node.nid, + (final element) => + element.nid == widget.state.node.nid, ) != null || - onHover.nid == widget.node.nid) + onHover.nid == widget.state.node.nid) Transform.translate( offset: const Offset(0, -20), child: ColoredBox( @@ -213,7 +215,7 @@ class NodeSelectionState extends State { horizontal: 4, ), child: TDetailLabel( - widget.node.intrinsicState.displayName, + widget.state.node.intrinsicState.displayName, ), ), ), diff --git a/teta_widgets/lib/src/elements/builder/node_selection_builder.dart b/teta_widgets/lib/src/elements/builder/node_selection_builder.dart index 2763f7be..387b6449 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection_builder.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection_builder.dart @@ -1,5 +1,6 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:teta_widgets/src/core/teta_widget/index.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -8,25 +9,20 @@ class NodeSelectionBuilder extends StatelessWidget { /// Constructor const NodeSelectionBuilder({ required final Widget child, - required final CNode node, - required final bool forPlay, + required final TetaWidgetState state, final Key? key, }) : _child = child, - _node = node, - _forPlay = forPlay, + _state = state, super(key: key); final Widget _child; - final CNode _node; - final bool _forPlay; + final TetaWidgetState _state; @override Widget build(final BuildContext context) { - return !_forPlay + return !_state.forPlay ? NodeSelection( - node: _node, - forPlay: _forPlay, - nid: _node.nid, + state: _state, child: _child, ) : _child; diff --git a/teta_widgets/lib/src/elements/widgets/adapty/paywalls.dart b/teta_widgets/lib/src/elements/widgets/adapty/paywalls.dart index 7371297d..943dac65 100644 --- a/teta_widgets/lib/src/elements/widgets/adapty/paywalls.dart +++ b/teta_widgets/lib/src/elements/widgets/adapty/paywalls.dart @@ -41,14 +41,17 @@ class _WAdaptyProductsListState extends State { void initState() { getProducts(); _map = DatasetObject( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: [{}], ); super.initState(); } Future getProducts() async { - if (UniversalPlatform.isIOS || UniversalPlatform.isAndroid || UniversalPlatform.isMacOS) { + if (UniversalPlatform.isIOS || + UniversalPlatform.isAndroid || + UniversalPlatform.isMacOS) { try { AdaptyPaywall? myPaywall; final getPaywallsResult = await Adapty.getPaywalls(); @@ -87,22 +90,23 @@ class _WAdaptyProductsListState extends State { ); } _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, //! Commented out because .toJson() method is not available in AdaptyProduct // map: products.map((final e) => e.toJson()).toList(), ); final datasets = addDataset(context, widget.state.dataset, _map); return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: ListView.builder( shrinkWrap: true, itemCount: widget.child == null ? 1 : products.length, itemBuilder: (final context, final index) => ChildConditionBuilder( ValueKey('${widget.state.node.nid} ${widget.state.loop}'), state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: + widget.state.dataset.isEmpty ? datasets : widget.state.dataset, ), child: widget.child, ), diff --git a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart index 020e24b3..1ab6bd79 100644 --- a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart @@ -98,8 +98,7 @@ class _WAirtableFetchState extends State { } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: widget.children.isEmpty ? const THeadline3('This node requires at least one child') : RepaintBoundary( diff --git a/teta_widgets/lib/src/elements/widgets/animations/anim_config_grid.dart b/teta_widgets/lib/src/elements/widgets/animations/anim_config_grid.dart index 72f0b52e..0759588c 100644 --- a/teta_widgets/lib/src/elements/widgets/animations/anim_config_grid.dart +++ b/teta_widgets/lib/src/elements/widgets/animations/anim_config_grid.dart @@ -30,8 +30,7 @@ class WAnimationConfigGridView extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: AnimationConfiguration.staggeredGrid( columnCount: int.tryParse( numberColumns.get( diff --git a/teta_widgets/lib/src/elements/widgets/animations/anim_config_list.dart b/teta_widgets/lib/src/elements/widgets/animations/anim_config_list.dart index fb3baa7f..10a38e53 100644 --- a/teta_widgets/lib/src/elements/widgets/animations/anim_config_list.dart +++ b/teta_widgets/lib/src/elements/widgets/animations/anim_config_list.dart @@ -28,8 +28,7 @@ class WAnimationConfigurationListView extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: AnimationConfiguration.staggeredList( position: int.tryParse( index.get( diff --git a/teta_widgets/lib/src/elements/widgets/animations/fade_in.dart.dart b/teta_widgets/lib/src/elements/widgets/animations/fade_in.dart.dart index 665a50a3..66a8c27d 100644 --- a/teta_widgets/lib/src/elements/widgets/animations/fade_in.dart.dart +++ b/teta_widgets/lib/src/elements/widgets/animations/fade_in.dart.dart @@ -24,8 +24,7 @@ class WFadeInAnimation extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: FadeInAnimation( child: ChildConditionBuilder( ValueKey(state.toKey), diff --git a/teta_widgets/lib/src/elements/widgets/animations/scale.dart b/teta_widgets/lib/src/elements/widgets/animations/scale.dart index e3effd26..9f216280 100644 --- a/teta_widgets/lib/src/elements/widgets/animations/scale.dart +++ b/teta_widgets/lib/src/elements/widgets/animations/scale.dart @@ -24,8 +24,7 @@ class WScaleAnimation extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: ScaleAnimation( child: ChildConditionBuilder( ValueKey(state.toKey), diff --git a/teta_widgets/lib/src/elements/widgets/animations/slide.dart b/teta_widgets/lib/src/elements/widgets/animations/slide.dart index f5da7ce7..1dc8f81c 100644 --- a/teta_widgets/lib/src/elements/widgets/animations/slide.dart +++ b/teta_widgets/lib/src/elements/widgets/animations/slide.dart @@ -24,8 +24,7 @@ class WSlideAnimation extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SlideAnimation( child: ChildConditionBuilder( ValueKey(state.toKey), diff --git a/teta_widgets/lib/src/elements/widgets/apicalls/api_calls_fetch.dart b/teta_widgets/lib/src/elements/widgets/apicalls/api_calls_fetch.dart index 849e4cd8..17ad0825 100644 --- a/teta_widgets/lib/src/elements/widgets/apicalls/api_calls_fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/apicalls/api_calls_fetch.dart @@ -2,13 +2,12 @@ // Flutter imports: import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; - // Package imports: import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; - // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -78,7 +77,7 @@ class _WApiCallsFetchState extends State { } if (key == 'headers') { mapHeaders = value as Map; - var mapHeaders2 = {}; + final mapHeaders2 = {}; mapHeaders.forEach( (final key, final dynamic value) { var changeKey = key; @@ -111,7 +110,7 @@ class _WApiCallsFetchState extends State { } if (key == 'body') { mapBody = value as Map; - var mapBody2 = {}; + final mapBody2 = {}; mapBody.forEach( (final key, final dynamic value) { var changeKey = key; @@ -144,7 +143,7 @@ class _WApiCallsFetchState extends State { } if (key == 'params') { mapParameters = value as Map; - var mapParameters2 = {}; + final mapParameters2 = {}; mapParameters.forEach( (final key, final dynamic value) { @@ -180,7 +179,7 @@ class _WApiCallsFetchState extends State { try { var newURL = url; var firstLoop = true; - mapParameters.forEach((key, dynamic value) { + mapParameters.forEach((final key, final dynamic value) { if (firstLoop) { newURL = '$newURL?$key=${value.toString()}'; firstLoop = false; @@ -191,14 +190,14 @@ class _WApiCallsFetchState extends State { final uri = Uri.parse(newURL); - var headersNew = { + final headersNew = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale', 'Access-Control-Allow-Methods': 'POST, OPTIONS' }; - mapHeaders.forEach((key, dynamic value) { + mapHeaders.forEach((final key, final dynamic value) { headersNew[key] = value.toString(); }); @@ -206,7 +205,7 @@ class _WApiCallsFetchState extends State { final json = response.body; - dynamic resp = jsonDecode(json); + final dynamic resp = jsonDecode(json); if (resp is List) { final data = resp; if (mounted) { @@ -226,7 +225,7 @@ class _WApiCallsFetchState extends State { } } } catch (e) { - print("error:" + e.toString()); + print('error:$e'); } } @@ -237,7 +236,7 @@ class _WApiCallsFetchState extends State { } @override - Widget build(BuildContext context) { + Widget build(final BuildContext context) { final datasets = _addFetchDataToDataset(list); if (list.isEmpty) { @@ -257,8 +256,7 @@ class _WApiCallsFetchState extends State { } } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: widget.children.isEmpty ? const THeadline3('Api Calls Fetch requires at least one child') : RepaintBoundary( diff --git a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart index 0e84175f..2619c642 100644 --- a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart +++ b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart @@ -43,8 +43,7 @@ class WBottomBarItem extends StatelessWidget { if (element.name == fill.paletteStyle) model = element; }); return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: GestureDetector( onTap: () => GestureBuilder.get( context: context, diff --git a/teta_widgets/lib/src/elements/widgets/bouncing_widget.dart b/teta_widgets/lib/src/elements/widgets/bouncing_widget.dart index 8d87f118..409a50ed 100644 --- a/teta_widgets/lib/src/elements/widgets/bouncing_widget.dart +++ b/teta_widgets/lib/src/elements/widgets/bouncing_widget.dart @@ -45,8 +45,7 @@ class WBouncingWidget extends StatelessWidget { context, ); return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: BouncingWidget( duration: Duration(milliseconds: int.tryParse(val) ?? 200), scaleFactor: double.tryParse(scale) ?? 1, diff --git a/teta_widgets/lib/src/elements/widgets/button.dart b/teta_widgets/lib/src/elements/widgets/button.dart index b6ec526d..ead4e444 100644 --- a/teta_widgets/lib/src/elements/widgets/button.dart +++ b/teta_widgets/lib/src/elements/widgets/button.dart @@ -40,8 +40,7 @@ class WButton extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: IgnorePointer( ignoring: !state.forPlay, child: GestureDetector( diff --git a/teta_widgets/lib/src/elements/widgets/camera.dart b/teta_widgets/lib/src/elements/widgets/camera.dart index f54dc689..4634e22c 100644 --- a/teta_widgets/lib/src/elements/widgets/camera.dart +++ b/teta_widgets/lib/src/elements/widgets/camera.dart @@ -41,8 +41,7 @@ class _WCameraState extends State { .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: variable?.controller != null ? SizedBox( width: double.infinity, diff --git a/teta_widgets/lib/src/elements/widgets/checkbox.dart b/teta_widgets/lib/src/elements/widgets/checkbox.dart index 0348ccd9..970f8b9a 100644 --- a/teta_widgets/lib/src/elements/widgets/checkbox.dart +++ b/teta_widgets/lib/src/elements/widgets/checkbox.dart @@ -42,8 +42,7 @@ class _WCheckBoxState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: Checkbox( onChanged: (final value) { if (widget.state.forPlay) { @@ -58,7 +57,8 @@ class _WCheckBoxState extends State { }, value: val == 'true', mouseCursor: const FCursor().get(), - fillColor: MaterialStateProperty.resolveWith((final states) => Colors.black), + fillColor: + MaterialStateProperty.resolveWith((final states) => Colors.black), ), ); } diff --git a/teta_widgets/lib/src/elements/widgets/component.dart b/teta_widgets/lib/src/elements/widgets/component.dart index 1cee820e..c621d299 100644 --- a/teta_widgets/lib/src/elements/widgets/component.dart +++ b/teta_widgets/lib/src/elements/widgets/component.dart @@ -138,9 +138,7 @@ class _WComponentState extends State { return (page.scaffold == null) ? const SizedBox() : NodeSelection( - node: widget.state.node, - forPlay: widget.state.forPlay, - nid: widget.state.node.nid, + state: widget.state, child: GestureBuilderBase.get( context: context, state: widget.state, diff --git a/teta_widgets/lib/src/elements/widgets/components/login_section.dart b/teta_widgets/lib/src/elements/widgets/components/login_section.dart index a4b656c7..b58a1e6b 100644 --- a/teta_widgets/lib/src/elements/widgets/components/login_section.dart +++ b/teta_widgets/lib/src/elements/widgets/components/login_section.dart @@ -1,7 +1,5 @@ // Flutter imports: -import 'package:auth_buttons/auth_buttons.dart'; import 'package:flutter/material.dart'; -import 'package:gap/gap.dart'; // Package imports: import 'package:teta_core/teta_core.dart'; // Project imports: @@ -51,11 +49,12 @@ class WLoginSection extends StatelessWidget { @override Widget build(final BuildContext context) { + return const SizedBox(); + /* final w = width.get(context: context, isWidth: true); final h = height.get(context: context, isWidth: true); return NodeSelectionBuilder( - node: node, - forPlay: forPlay, + state: state, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, @@ -100,6 +99,6 @@ class WLoginSection extends StatelessWidget { ), ], ), - ); + );*/ } } diff --git a/teta_widgets/lib/src/elements/widgets/cta/apple.dart b/teta_widgets/lib/src/elements/widgets/cta/apple.dart index 99f6175c..da47854a 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/apple.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/apple.dart @@ -32,8 +32,7 @@ class WLoginWithApple extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cta/facebook.dart b/teta_widgets/lib/src/elements/widgets/cta/facebook.dart index 675d5cb6..83b3da63 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/facebook.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/facebook.dart @@ -30,8 +30,7 @@ class WLoginWithFacebook extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cta/github.dart b/teta_widgets/lib/src/elements/widgets/cta/github.dart index 1a5680f7..bb0358c6 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/github.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/github.dart @@ -30,8 +30,7 @@ class WLoginWithGitHub extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cta/google.dart b/teta_widgets/lib/src/elements/widgets/cta/google.dart index c30f1be3..ef30d7d7 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/google.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/google.dart @@ -30,8 +30,7 @@ class WLoginWithGoogle extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cta/microsoft.dart b/teta_widgets/lib/src/elements/widgets/cta/microsoft.dart index 642cd058..a76fd4a4 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/microsoft.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/microsoft.dart @@ -30,8 +30,7 @@ class WLoginWithMicrosoft extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cta/twitter.dart b/teta_widgets/lib/src/elements/widgets/cta/twitter.dart index 22375651..c8e6537e 100644 --- a/teta_widgets/lib/src/elements/widgets/cta/twitter.dart +++ b/teta_widgets/lib/src/elements/widgets/cta/twitter.dart @@ -30,8 +30,7 @@ class WLoginWithTwitter extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: SizedBox( width: width.get(context: context, isWidth: true), height: height.get(context: context, isWidth: false), diff --git a/teta_widgets/lib/src/elements/widgets/cupertino_picker.dart b/teta_widgets/lib/src/elements/widgets/cupertino_picker.dart index 79a56db8..046694ca 100644 --- a/teta_widgets/lib/src/elements/widgets/cupertino_picker.dart +++ b/teta_widgets/lib/src/elements/widgets/cupertino_picker.dart @@ -33,8 +33,7 @@ class _WCupertinoPickerState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: CupertinoPicker( itemExtent: widget.height.get(context: context, isWidth: false) ?? 44, onSelectedItemChanged: (final index) { diff --git a/teta_widgets/lib/src/elements/widgets/cupertino_segmented_control.dart b/teta_widgets/lib/src/elements/widgets/cupertino_segmented_control.dart index a84183fa..8e93fec5 100644 --- a/teta_widgets/lib/src/elements/widgets/cupertino_segmented_control.dart +++ b/teta_widgets/lib/src/elements/widgets/cupertino_segmented_control.dart @@ -64,8 +64,7 @@ class _WCupertinoSegmentedControlState ); } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: IgnorePointer( ignoring: !widget.state.forPlay, child: CupertinoSegmentedControl( diff --git a/teta_widgets/lib/src/elements/widgets/cupertino_switch.dart b/teta_widgets/lib/src/elements/widgets/cupertino_switch.dart index 30f0a01f..72430967 100644 --- a/teta_widgets/lib/src/elements/widgets/cupertino_switch.dart +++ b/teta_widgets/lib/src/elements/widgets/cupertino_switch.dart @@ -31,8 +31,7 @@ class _WCupertinoSwitchState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: CupertinoSwitch( onChanged: (final value) { GestureBuilder.get( diff --git a/teta_widgets/lib/src/elements/widgets/firebase/firebase_future_builder.dart b/teta_widgets/lib/src/elements/widgets/firebase/firebase_future_builder.dart index 576fd8d5..8da3ff73 100644 --- a/teta_widgets/lib/src/elements/widgets/firebase/firebase_future_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/firebase/firebase_future_builder.dart @@ -37,8 +37,7 @@ class WFirebaseFutureBuilderState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: const Center( child: THeadline3( 'Firebase is not initialized yet', diff --git a/teta_widgets/lib/src/elements/widgets/firebase/firebase_is_authenticated.dart b/teta_widgets/lib/src/elements/widgets/firebase/firebase_is_authenticated.dart index ac485cd0..647e95be 100644 --- a/teta_widgets/lib/src/elements/widgets/firebase/firebase_is_authenticated.dart +++ b/teta_widgets/lib/src/elements/widgets/firebase/firebase_is_authenticated.dart @@ -30,10 +30,12 @@ class WFirebaseIsAuthenticatedBuilder extends StatefulWidget { final CNode? child; @override - WFirebaseIsAuthenticatedBuilderState createState() => WFirebaseIsAuthenticatedBuilderState(); + WFirebaseIsAuthenticatedBuilderState createState() => + WFirebaseIsAuthenticatedBuilderState(); } -class WFirebaseIsAuthenticatedBuilderState extends State { +class WFirebaseIsAuthenticatedBuilderState + extends State { DatasetObject _map = DatasetObject( name: key, map: [ @@ -44,8 +46,7 @@ class WFirebaseIsAuthenticatedBuilderState extends State( builder: (final context, final state) => state ? FutureBuilder( @@ -58,7 +59,8 @@ class WFirebaseIsAuthenticatedBuilderState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: const SizedBox(), ); } diff --git a/teta_widgets/lib/src/elements/widgets/firebase/firebase_stream_builder.dart b/teta_widgets/lib/src/elements/widgets/firebase/firebase_stream_builder.dart index 502a8c23..6b3877eb 100644 --- a/teta_widgets/lib/src/elements/widgets/firebase/firebase_stream_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/firebase/firebase_stream_builder.dart @@ -31,8 +31,7 @@ class WFirebaseStreamBuilderState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: const SizedBox(), ); } diff --git a/teta_widgets/lib/src/elements/widgets/http_requests/future_builder.dart b/teta_widgets/lib/src/elements/widgets/http_requests/future_builder.dart index b6e5fbe9..8254fe56 100644 --- a/teta_widgets/lib/src/elements/widgets/http_requests/future_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/http_requests/future_builder.dart @@ -32,7 +32,8 @@ class WHTTPRequestFutureBuilder extends StatefulWidget { final List children; @override - _WHTTPRequestFutureBuilderState createState() => _WHTTPRequestFutureBuilderState(); + _WHTTPRequestFutureBuilderState createState() => + _WHTTPRequestFutureBuilderState(); } class _WHTTPRequestFutureBuilderState extends State { @@ -73,8 +74,7 @@ class _WHTTPRequestFutureBuilderState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: FutureBuilder( future: _future, builder: (final context, final snapshot) { @@ -97,7 +97,9 @@ class _WHTTPRequestFutureBuilderState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { @@ -165,7 +167,10 @@ class _WHTTPRequestFutureBuilderState extends State { ) { map.forEach((final dynamic key, final dynamic value) { try { - if (value is String || value is int || value is double || value is bool) { + if (value is String || + value is int || + value is double || + value is bool) { parent.children.add( TreeObject( id: idIndex, diff --git a/teta_widgets/lib/src/elements/widgets/https_requests_custom_backend/custom_http_request.dart b/teta_widgets/lib/src/elements/widgets/https_requests_custom_backend/custom_http_request.dart index cfe063a7..680a5fa6 100644 --- a/teta_widgets/lib/src/elements/widgets/https_requests_custom_backend/custom_http_request.dart +++ b/teta_widgets/lib/src/elements/widgets/https_requests_custom_backend/custom_http_request.dart @@ -2,13 +2,12 @@ // Flutter imports: import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; - // Package imports: import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; - // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -55,11 +54,11 @@ class _WCustomHttpRequestState extends State { var newURL = url; for (var i = 0; i < widget.addParams!.length; i++) { if (i == 0) { - newURL = url + - '?${widget.addParams![i].key.toString()}=${widget.addParams![i].value.value.toString()}'; + newURL = + '$url?${widget.addParams![i].key.toString()}=${widget.addParams![i].value.value.toString()}'; } else { - newURL = newURL + - "&${widget.addParams![i].key.toString()}=${widget.addParams![i].value.value.toString()}"; + newURL = + "$newURL&${widget.addParams![i].key.toString()}=${widget.addParams![i].value.value.toString()}"; } } // print("new URL : " + newURL); @@ -81,7 +80,7 @@ class _WCustomHttpRequestState extends State { final json = response.body; - dynamic resp = jsonDecode(json); + final dynamic resp = jsonDecode(json); if (resp is List) { final data = resp; if (mounted) { @@ -130,8 +129,7 @@ class _WCustomHttpRequestState extends State { } } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: widget.children.isEmpty ? const THeadline3('Custom Http Request requires at least one child') : RepaintBoundary( @@ -144,8 +142,11 @@ class _WCustomHttpRequestState extends State { List _addFetchDataToDataset(final List? list) { _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, - map: (list ?? const []).map((final dynamic e) => e as Map).toList(), + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, + map: (list ?? const []) + .map((final dynamic e) => e as Map) + .toList(), ); final datasets = addDataset(context, widget.state.dataset, _map); diff --git a/teta_widgets/lib/src/elements/widgets/map.dart b/teta_widgets/lib/src/elements/widgets/map.dart index 3469ae25..8698182a 100644 --- a/teta_widgets/lib/src/elements/widgets/map.dart +++ b/teta_widgets/lib/src/elements/widgets/map.dart @@ -136,8 +136,7 @@ class _WMapState extends State { ); } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: !BlocProvider.of(context) .state! .config! diff --git a/teta_widgets/lib/src/elements/widgets/map_builder.dart b/teta_widgets/lib/src/elements/widgets/map_builder.dart index 26aa18d7..2dd3746b 100644 --- a/teta_widgets/lib/src/elements/widgets/map_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/map_builder.dart @@ -170,8 +170,7 @@ class _WMapBuilderState extends State { index != -1 ? widget.state.dataset[index] : DatasetObject.empty(); return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: !BlocProvider.of(context) .state! .config! diff --git a/teta_widgets/lib/src/elements/widgets/mapbox.dart b/teta_widgets/lib/src/elements/widgets/mapbox.dart index c5d25bd1..3c7a0ff1 100644 --- a/teta_widgets/lib/src/elements/widgets/mapbox.dart +++ b/teta_widgets/lib/src/elements/widgets/mapbox.dart @@ -64,8 +64,7 @@ class _WMapBoxState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: Stack( children: const [ /*MapboxMap( diff --git a/teta_widgets/lib/src/elements/widgets/material_appbar.dart b/teta_widgets/lib/src/elements/widgets/material_appbar.dart index 2356715d..db0025a7 100644 --- a/teta_widgets/lib/src/elements/widgets/material_appbar.dart +++ b/teta_widgets/lib/src/elements/widgets/material_appbar.dart @@ -24,12 +24,12 @@ class WMaterialAppBar extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: AppBar( elevation: 0, backgroundColor: HexColor(fill.getHexColor(context)), - leading: children.length >= 2 ? children[1].toWidget(state: state) : null, + leading: + children.length >= 2 ? children[1].toWidget(state: state) : null, title: children.isNotEmpty ? children[0].toWidget(state: state) : null, actions: [ if (children.length >= 3) children[2].toWidget(state: state), diff --git a/teta_widgets/lib/src/elements/widgets/material_bottombar.dart b/teta_widgets/lib/src/elements/widgets/material_bottombar.dart index 6f976c71..5712fefc 100644 --- a/teta_widgets/lib/src/elements/widgets/material_bottombar.dart +++ b/teta_widgets/lib/src/elements/widgets/material_bottombar.dart @@ -24,8 +24,7 @@ class WMaterialBottomBar extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: BottomNavigationBar( items: const [], backgroundColor: HexColor(fill.getHexColor(context)), diff --git a/teta_widgets/lib/src/elements/widgets/numeric_step_button.dart b/teta_widgets/lib/src/elements/widgets/numeric_step_button.dart index 717abcb4..0ea1e7c7 100644 --- a/teta_widgets/lib/src/elements/widgets/numeric_step_button.dart +++ b/teta_widgets/lib/src/elements/widgets/numeric_step_button.dart @@ -32,8 +32,7 @@ class _WNumericStepButtonState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ diff --git a/teta_widgets/lib/src/elements/widgets/radio.dart b/teta_widgets/lib/src/elements/widgets/radio.dart index 2a1bdb60..784be15c 100644 --- a/teta_widgets/lib/src/elements/widgets/radio.dart +++ b/teta_widgets/lib/src/elements/widgets/radio.dart @@ -31,8 +31,7 @@ class _WRadioState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: Radio( groupValue: widget.groupValue.get( widget.state.params, diff --git a/teta_widgets/lib/src/elements/widgets/refresh_indicator.dart b/teta_widgets/lib/src/elements/widgets/refresh_indicator.dart index c51c03af..4a4ecc22 100644 --- a/teta_widgets/lib/src/elements/widgets/refresh_indicator.dart +++ b/teta_widgets/lib/src/elements/widgets/refresh_indicator.dart @@ -32,8 +32,7 @@ class WRefreshIndicator extends StatelessWidget { Widget build(final BuildContext context) { final val = height.get(context: context, isWidth: false) ?? 150; return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: CustomRefreshIndicator( offsetToArmed: val, child: children.isNotEmpty diff --git a/teta_widgets/lib/src/elements/widgets/responsive/wrapper_container.dart b/teta_widgets/lib/src/elements/widgets/responsive/wrapper_container.dart index 844f41e5..994d5702 100644 --- a/teta_widgets/lib/src/elements/widgets/responsive/wrapper_container.dart +++ b/teta_widgets/lib/src/elements/widgets/responsive/wrapper_container.dart @@ -28,9 +28,7 @@ class WWrapperContainer extends StatelessWidget { Widget build(final BuildContext context) { Logger.printWarning('${MediaQuery.of(context).size.width}'); return NodeSelection( - node: state.node, - forPlay: state.forPlay, - nid: state.node.nid, + state: state, child: GestureBuilderBase.get( context: context, state: state, diff --git a/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart b/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart index f9541ad7..765fa614 100644 --- a/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart @@ -112,7 +112,8 @@ class _WSupabaseFutureBuilderState extends State { widget.state.loop, context, ); - final valueFromRange = int.tryParse(fromRange) != null ? int.parse(fromRange) : 0; + final valueFromRange = + int.tryParse(fromRange) != null ? int.parse(fromRange) : 0; final toRange = widget.toRange.get( widget.state.params, widget.state.states, @@ -121,7 +122,8 @@ class _WSupabaseFutureBuilderState extends State { widget.state.loop, context, ); - final valueToRange = int.tryParse(toRange) != null ? int.parse(toRange) : 15; + final valueToRange = + int.tryParse(toRange) != null ? int.parse(toRange) : 15; final numberPage = widget.numberPage.get( widget.state.params, widget.state.states, @@ -130,7 +132,8 @@ class _WSupabaseFutureBuilderState extends State { widget.state.loop, context, ); - final valueToPage = int.tryParse(numberPage) != null ? int.parse(numberPage) : 1; + final valueToPage = + int.tryParse(numberPage) != null ? int.parse(numberPage) : 1; final searchName = widget.searchName.get( widget.state.params, @@ -203,8 +206,7 @@ class _WSupabaseFutureBuilderState extends State { } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: FutureBuilder( future: _future, builder: (final context, final snapshot) { @@ -227,7 +229,8 @@ class _WSupabaseFutureBuilderState extends State { } final list = response?.data as List?; _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: (list ?? const []) .map((final dynamic e) => e as Map) .toList(), @@ -238,7 +241,9 @@ class _WSupabaseFutureBuilderState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { diff --git a/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart b/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart index 8116e2f9..501c8a8d 100644 --- a/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart @@ -80,7 +80,8 @@ class _WSupabaseStreamBuilderState extends State { widget.state.loop, context, ); - final valueFromRange = int.tryParse(fromRange) != null ? int.parse(fromRange) : 0; + final valueFromRange = + int.tryParse(fromRange) != null ? int.parse(fromRange) : 0; client = BlocProvider.of(context).state; final query = client!.from(from).stream(['id']); @@ -109,8 +110,7 @@ class _WSupabaseStreamBuilderState extends State { } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: StreamBuilder( stream: _stream, builder: (final context, final snapshot) { @@ -132,7 +132,8 @@ class _WSupabaseStreamBuilderState extends State { // TODO: Returns a error widget } _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: response?.map((final Map e) => e).toList(), ); final datasets = addDataset(context, widget.state.dataset, _map); @@ -141,7 +142,9 @@ class _WSupabaseStreamBuilderState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { diff --git a/teta_widgets/lib/src/elements/widgets/tcard.dart b/teta_widgets/lib/src/elements/widgets/tcard.dart index f9971a79..1648dbbb 100644 --- a/teta_widgets/lib/src/elements/widgets/tcard.dart +++ b/teta_widgets/lib/src/elements/widgets/tcard.dart @@ -97,8 +97,7 @@ class _WTCardState extends State { ); final delay = int.tryParse(delayStr) ?? 500; return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: IgnorePointer( ignoring: !widget.state.forPlay, child: TCard( diff --git a/teta_widgets/lib/src/elements/widgets/tcard_builder.dart b/teta_widgets/lib/src/elements/widgets/tcard_builder.dart index cf8e731a..0c49ed7a 100644 --- a/teta_widgets/lib/src/elements/widgets/tcard_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/tcard_builder.dart @@ -90,8 +90,7 @@ class _WTCardState extends State { ); final delay = int.tryParse(delayStr) ?? 500; return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: IgnorePointer( ignoring: !widget.state.forPlay, child: TCard( diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/count.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/count.dart index 56af8518..2fe138cc 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/count.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/count.dart @@ -103,7 +103,8 @@ class _WCmsCountState extends State { _future = TetaCMS.instance.client.getCollectionCount( collectionId, filters: [ - if (keyName.isNotEmpty && keyValue.isNotEmpty) Filter(keyName, keyValue), + if (keyName.isNotEmpty && keyValue.isNotEmpty) + Filter(keyName, keyValue), ], limit: int.tryParse(limit) ?? 20, page: int.tryParse(page) ?? 0, @@ -115,8 +116,7 @@ class _WCmsCountState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: RepaintBoundary( child: FutureBuilder( future: _future, @@ -134,7 +134,8 @@ class _WCmsCountState extends State { final count = snapshot.data ?? 0; _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: [ { 'count': count, @@ -147,7 +148,9 @@ class _WCmsCountState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/custom_query.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/custom_query.dart index b74de441..2c41a662 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/custom_query.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/custom_query.dart @@ -71,8 +71,7 @@ class _WCmsCustomQueryState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: RepaintBoundary( child: FutureBuilder( future: _future, @@ -90,13 +89,16 @@ class _WCmsCustomQueryState extends State { // TODO: Returns a error widget } - final list = (snapshot.data as TetaResponse?)?.data as List?; + final list = + (snapshot.data as TetaResponse?)?.data as List?; Logger.printWarning('list: $list'); _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: (list ?? const []) .map( - (final dynamic e) => e as Map? ?? {}, + (final dynamic e) => + e as Map? ?? {}, ) .toList(), ); @@ -106,7 +108,9 @@ class _WCmsCustomQueryState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/fetch.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/fetch.dart index 2c06cda7..9e20670d 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/fetch.dart @@ -99,7 +99,8 @@ class _WCmsFetchState extends State { final dbElements = await TetaCMS.instance.client.getCollection( collectionId, filters: [ - if (keyName.isNotEmpty && keyValue.isNotEmpty) Filter(keyName, keyValue), + if (keyName.isNotEmpty && keyValue.isNotEmpty) + Filter(keyName, keyValue), ], limit: int.tryParse(limit) ?? 20, page: int.tryParse(page) ?? 0, @@ -140,8 +141,7 @@ class _WCmsFetchState extends State { } return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: widget.children.isEmpty ? const THeadline3('CMS Fetch requires at least one child') : RepaintBoundary( @@ -154,8 +154,11 @@ class _WCmsFetchState extends State { List _addFetchDataToDataset(final List? list) { _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, - map: (list ?? const []).map((final dynamic e) => e as Map).toList(), + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, + map: (list ?? const []) + .map((final dynamic e) => e as Map) + .toList(), ); final datasets = addDataset(context, widget.state.dataset, _map); diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart index cb8bf018..d96f08a4 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart @@ -58,8 +58,7 @@ class _WCMSLoggedUserState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: FutureBuilder( future: _future, builder: (final context, final snapshot) { diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/stream.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/stream.dart index eb114a3a..97df07f0 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/stream.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/stream.dart @@ -111,7 +111,8 @@ class _WCmsStreamState extends State { _stream = TetaCMS.instance.realtime.streamCollection( collectionId, filters: [ - if (keyName.isNotEmpty && keyValue.isNotEmpty) Filter(keyName, keyValue), + if (keyName.isNotEmpty && keyValue.isNotEmpty) + Filter(keyName, keyValue), ], limit: int.tryParse(limit) ?? 20, page: int.tryParse(page) ?? 0, @@ -124,13 +125,13 @@ class _WCmsStreamState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: RepaintBoundary( child: StreamBuilder( stream: _stream.stream, builder: (final context, final snapshot) { - if (!snapshot.hasData || ((snapshot.data as List?)?.isEmpty ?? false)) { + if (!snapshot.hasData || + ((snapshot.data as List?)?.isEmpty ?? false)) { if (widget.children.isNotEmpty) { return widget.children.last.toWidget(state: widget.state); } else { @@ -139,7 +140,8 @@ class _WCmsStreamState extends State { } else { final list = snapshot.data as List?; _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: (list ?? const []) .map((final dynamic e) => e as Map) .toList(), @@ -150,7 +152,9 @@ class _WCmsStreamState extends State { if (widget.children.isNotEmpty) { return widget.children.first.toWidget( state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), ); } else { diff --git a/teta_widgets/lib/src/elements/widgets/text.dart b/teta_widgets/lib/src/elements/widgets/text.dart index 86ea880d..06aa3029 100644 --- a/teta_widgets/lib/src/elements/widgets/text.dart +++ b/teta_widgets/lib/src/elements/widgets/text.dart @@ -55,8 +55,7 @@ class _WTextState extends State { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { diff --git a/teta_widgets/lib/src/elements/widgets/textbutton.dart b/teta_widgets/lib/src/elements/widgets/textbutton.dart index 20272307..1fb21c52 100644 --- a/teta_widgets/lib/src/elements/widgets/textbutton.dart +++ b/teta_widgets/lib/src/elements/widgets/textbutton.dart @@ -24,8 +24,7 @@ class WTextButton extends StatelessWidget { @override Widget build(final BuildContext context) { return NodeSelectionBuilder( - node: state.node, - forPlay: state.forPlay, + state: state, child: TextButton( onPressed: () => GestureBuilder.get( context: context, diff --git a/teta_widgets/lib/src/elements/widgets/textfield.dart b/teta_widgets/lib/src/elements/widgets/textfield.dart index 9035c0cb..b7f332b3 100644 --- a/teta_widgets/lib/src/elements/widgets/textfield.dart +++ b/teta_widgets/lib/src/elements/widgets/textfield.dart @@ -105,8 +105,7 @@ class _WTextFieldState extends State { final hintOpacity = tempHintOpacity >= 0 && tempHintOpacity <= 1 ? tempHintOpacity : 1.0; return NodeSelectionBuilder( - node: widget.state.node, - forPlay: widget.state.forPlay, + state: widget.state, child: Center( child: TContainer( margin: widget.margins.get(context), From 3bb117bcd801c3ad98997554843a1a71736c9227 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Sat, 31 Dec 2022 20:53:58 +0100 Subject: [PATCH 04/23] feat(drag and drop) --- .../core/teta_widget/teta_widget_state.dart | 2 + .../src/elements/bodies/airtable/fetch.dart | 2 +- .../bodies/animations/anim_config_grid.dart | 2 +- .../bodies/animations/anim_config_list.dart | 2 +- .../elements/bodies/animations/fade_in.dart | 2 +- .../src/elements/bodies/animations/scale.dart | 2 +- .../src/elements/bodies/animations/slide.dart | 2 +- .../bodies/api_calls/api_calls_fetch.dart | 2 +- .../src/elements/bodies/bottombaritem.dart | 4 +- .../src/elements/bodies/bouncing_widget.dart | 2 +- .../lib/src/elements/bodies/checkbox.dart | 2 +- .../elements/bodies/concentric_page_view.dart | 5 +- .../lib/src/elements/bodies/condition.dart | 2 +- .../lib/src/elements/bodies/cta/apple.dart | 2 +- .../lib/src/elements/bodies/cta/facebook.dart | 2 +- .../lib/src/elements/bodies/cta/github.dart | 2 +- .../lib/src/elements/bodies/cta/google.dart | 2 +- .../src/elements/bodies/cta/microsoft.dart | 2 +- .../lib/src/elements/bodies/cta/twitter.dart | 2 +- .../bodies/cupertino_segmented_control.dart | 2 +- .../bodies/firebase/future_builder.dart | 2 +- .../bodies/firebase/is_authenticated.dart | 2 +- .../elements/bodies/firebase/pagination.dart | 2 +- .../bodies/firebase/stream_builder.dart | 2 +- teta_widgets/lib/src/elements/bodies/gap.dart | 2 +- .../lib/src/elements/bodies/gridview.dart | 2 +- .../src/elements/bodies/gridview_builder.dart | 2 +- .../lib/src/elements/bodies/hero.dart | 2 +- .../custom_http_request.dart | 2 +- .../lib/src/elements/bodies/icon.dart | 2 +- .../lib/src/elements/bodies/icon_feather.dart | 2 +- .../elements/bodies/icon_font_awesome.dart | 2 +- .../lib/src/elements/bodies/icon_line.dart | 2 +- .../src/elements/bodies/ignore_pointer.dart | 2 +- .../lib/src/elements/bodies/index_stack.dart | 2 +- .../lib/src/elements/bodies/limitedBox.dart | 2 +- .../lib/src/elements/bodies/listview.dart | 2 +- .../src/elements/bodies/listview_builder.dart | 2 +- .../lib/src/elements/bodies/lottie.dart | 2 +- teta_widgets/lib/src/elements/bodies/map.dart | 4 +- .../lib/src/elements/bodies/marker.dart | 4 +- .../lib/src/elements/bodies/opacity.dart | 2 +- .../lib/src/elements/bodies/page_view.dart | 10 +- .../lib/src/elements/bodies/radio.dart | 2 +- .../elements/bodies/responsive/wrapper.dart | 4 +- .../elements/bodies/responsive_condition.dart | 2 +- .../lib/src/elements/bodies/stack.dart | 2 +- .../bodies/supabase/future_builder.dart | 2 +- .../supabase/future_stream_builder.dart | 2 +- .../elements/bodies/supabase/logged_user.dart | 2 +- .../lib/src/elements/bodies/tcard.dart | 2 +- .../src/elements/bodies/tcard_builder.dart | 2 +- .../lib/src/elements/bodies/template.dart | 4 +- .../src/elements/bodies/teta_cms/count.dart | 2 +- .../bodies/teta_cms/custom_query.dart | 2 +- .../src/elements/bodies/teta_cms/fetch.dart | 2 +- .../elements/bodies/teta_cms/logged_user.dart | 2 +- .../src/elements/bodies/teta_cms/stream.dart | 2 +- .../lib/src/elements/bodies/textbutton.dart | 2 +- .../lib/src/elements/bodies/textfield.dart | 2 +- .../lib/src/elements/bodies/tooltip.dart | 2 +- .../lib/src/elements/bodies/visibility.dart | 2 +- .../lib/src/elements/bodies/webview.dart | 2 +- .../lib/src/elements/bodies/wrap.dart | 2 +- .../src/elements/builder/drag_and_drop.dart | 121 +++++++++--- .../lib/src/elements/builder/drag_target.dart | 101 ---------- .../lib/src/elements/builder/draggable.dart | 48 ----- .../src/elements/builder/node_selection.dart | 179 ++++++------------ teta_widgets/lib/src/elements/index.dart | 3 +- .../lib/src/elements/nodes/categories.dart | 21 +- .../lib/src/elements/nodes/dynamic.dart | 10 +- .../lib/src/elements/nodes/nnull.dart | 9 +- teta_widgets/lib/src/elements/nodes/node.dart | 6 +- .../lib/src/elements/widgets/listview.dart | 10 +- .../elements/widgets/listview_builder.dart | 1 + .../lib/src/elements/widgets/row.dart | 10 +- 76 files changed, 271 insertions(+), 397 deletions(-) delete mode 100644 teta_widgets/lib/src/elements/builder/drag_target.dart delete mode 100644 teta_widgets/lib/src/elements/builder/draggable.dart diff --git a/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart b/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart index 4f471aa9..1bf81a18 100644 --- a/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart +++ b/teta_widgets/lib/src/core/teta_widget/teta_widget_state.dart @@ -41,6 +41,7 @@ class TetaWidgetState { final List? params, final List? states, final List? dataset, + final bool? isVertical, }) { return TetaWidgetState( node: node ?? this.node, @@ -49,6 +50,7 @@ class TetaWidgetState { params: params ?? this.params, states: states ?? this.states, dataset: dataset ?? this.dataset, + isVertical: isVertical ?? this.isVertical, ); } diff --git a/teta_widgets/lib/src/elements/bodies/airtable/fetch.dart b/teta_widgets/lib/src/elements/bodies/airtable/fetch.dart index 93d35feb..b95e0342 100644 --- a/teta_widgets/lib/src/elements/bodies/airtable/fetch.dart +++ b/teta_widgets/lib/src/elements/bodies/airtable/fetch.dart @@ -44,7 +44,7 @@ final airtableFetchIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.experimental, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [ diff --git a/teta_widgets/lib/src/elements/bodies/animations/anim_config_grid.dart b/teta_widgets/lib/src/elements/bodies/animations/anim_config_grid.dart index 57a2c482..381e4280 100644 --- a/teta_widgets/lib/src/elements/bodies/animations/anim_config_grid.dart +++ b/teta_widgets/lib/src/elements/bodies/animations/anim_config_grid.dart @@ -32,7 +32,7 @@ final animationConfigGridIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/animations/anim_config_list.dart b/teta_widgets/lib/src/elements/bodies/animations/anim_config_list.dart index 59941f4e..c22855f2 100644 --- a/teta_widgets/lib/src/elements/bodies/animations/anim_config_list.dart +++ b/teta_widgets/lib/src/elements/bodies/animations/anim_config_list.dart @@ -32,7 +32,7 @@ final animationConfigListIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/animations/fade_in.dart b/teta_widgets/lib/src/elements/bodies/animations/fade_in.dart index 6dd12e4a..90d785f7 100644 --- a/teta_widgets/lib/src/elements/bodies/animations/fade_in.dart +++ b/teta_widgets/lib/src/elements/bodies/animations/fade_in.dart @@ -29,7 +29,7 @@ final fadeInAnimationIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/animations/scale.dart b/teta_widgets/lib/src/elements/bodies/animations/scale.dart index b6a3ef49..feb14feb 100644 --- a/teta_widgets/lib/src/elements/bodies/animations/scale.dart +++ b/teta_widgets/lib/src/elements/bodies/animations/scale.dart @@ -29,7 +29,7 @@ final scaleAnimationIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/animations/slide.dart b/teta_widgets/lib/src/elements/bodies/animations/slide.dart index 452376dd..8cb4bcdf 100644 --- a/teta_widgets/lib/src/elements/bodies/animations/slide.dart +++ b/teta_widgets/lib/src/elements/bodies/animations/slide.dart @@ -29,7 +29,7 @@ final slideAnimationIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/api_calls/api_calls_fetch.dart b/teta_widgets/lib/src/elements/bodies/api_calls/api_calls_fetch.dart index 6c56d1bd..84382e3f 100644 --- a/teta_widgets/lib/src/elements/bodies/api_calls/api_calls_fetch.dart +++ b/teta_widgets/lib/src/elements/bodies/api_calls/api_calls_fetch.dart @@ -47,7 +47,7 @@ final apiCallsFetchIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [ diff --git a/teta_widgets/lib/src/elements/bodies/bottombaritem.dart b/teta_widgets/lib/src/elements/bodies/bottombaritem.dart index 8606dcaa..9bf7ffe4 100644 --- a/teta_widgets/lib/src/elements/bodies/bottombaritem.dart +++ b/teta_widgets/lib/src/elements/bodies/bottombaritem.dart @@ -41,9 +41,9 @@ final bottombaritemIntrinsicStates = IntrinsicStates( blockedTypes: [], synonymous: ['bottom', 'bottom bar', 'bottombar', 'bottombaritem'], advicedChildrenCanHaveAtLeastAChild: [], - displayName: NodeType.name(_globalType), + displayName: 'BottomBar Item', type: _globalType, - category: NodeCategories.navigation, + category: NodeCategories.layout, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/bouncing_widget.dart b/teta_widgets/lib/src/elements/bodies/bouncing_widget.dart index 51980152..eb2c96a4 100644 --- a/teta_widgets/lib/src/elements/bodies/bouncing_widget.dart +++ b/teta_widgets/lib/src/elements/bodies/bouncing_widget.dart @@ -39,7 +39,7 @@ final bouncingWidgetIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/checkbox.dart b/teta_widgets/lib/src/elements/bodies/checkbox.dart index 494804a1..e5de3d22 100644 --- a/teta_widgets/lib/src/elements/bodies/checkbox.dart +++ b/teta_widgets/lib/src/elements/bodies/checkbox.dart @@ -33,7 +33,7 @@ final checkBoxIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/concentric_page_view.dart b/teta_widgets/lib/src/elements/bodies/concentric_page_view.dart index 2d9ca220..c807f531 100644 --- a/teta_widgets/lib/src/elements/bodies/concentric_page_view.dart +++ b/teta_widgets/lib/src/elements/bodies/concentric_page_view.dart @@ -36,7 +36,7 @@ final concentricPageViewIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], @@ -48,7 +48,8 @@ final concentricPageViewIntrinsicStates = IntrinsicStates( const Suggestion( title: 'Why use Concentric PageView in Teta?', description: 'Test', - linkToOpen: 'https://docs.teta.so/teta-docs/widget/list-widgets/concentric-pageview', + linkToOpen: + 'https://docs.teta.so/teta-docs/widget/list-widgets/concentric-pageview', ) ], ); diff --git a/teta_widgets/lib/src/elements/bodies/condition.dart b/teta_widgets/lib/src/elements/bodies/condition.dart index fdee2b35..c83d4750 100644 --- a/teta_widgets/lib/src/elements/bodies/condition.dart +++ b/teta_widgets/lib/src/elements/bodies/condition.dart @@ -41,7 +41,7 @@ final conditionIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.logic, + category: NodeCategories.visibility, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: ['Add Widget If True', 'Add Widget If False'], diff --git a/teta_widgets/lib/src/elements/bodies/cta/apple.dart b/teta_widgets/lib/src/elements/bodies/cta/apple.dart index b9f5b989..d01d8438 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/apple.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/apple.dart @@ -38,7 +38,7 @@ final loginAppleIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with Apple', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cta/facebook.dart b/teta_widgets/lib/src/elements/bodies/cta/facebook.dart index 1328bd45..18d473da 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/facebook.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/facebook.dart @@ -38,7 +38,7 @@ final loginFacebookIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with Facebook', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cta/github.dart b/teta_widgets/lib/src/elements/bodies/cta/github.dart index 9a48e7c8..f76be4b9 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/github.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/github.dart @@ -38,7 +38,7 @@ final loginGitHubIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with GitHub', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cta/google.dart b/teta_widgets/lib/src/elements/bodies/cta/google.dart index f78428fc..48f91437 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/google.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/google.dart @@ -38,7 +38,7 @@ final loginGoogleIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with Google', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cta/microsoft.dart b/teta_widgets/lib/src/elements/bodies/cta/microsoft.dart index 62ec32d6..7c6e5fff 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/microsoft.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/microsoft.dart @@ -38,7 +38,7 @@ final loginMicrosoftIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with Microsoft', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cta/twitter.dart b/teta_widgets/lib/src/elements/bodies/cta/twitter.dart index d8b1f2b4..c8c07360 100644 --- a/teta_widgets/lib/src/elements/bodies/cta/twitter.dart +++ b/teta_widgets/lib/src/elements/bodies/cta/twitter.dart @@ -38,7 +38,7 @@ final loginTwitterIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Login with Twitter', type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/cupertino_segmented_control.dart b/teta_widgets/lib/src/elements/bodies/cupertino_segmented_control.dart index 6d8d4346..4cfb9220 100644 --- a/teta_widgets/lib/src/elements/bodies/cupertino_segmented_control.dart +++ b/teta_widgets/lib/src/elements/bodies/cupertino_segmented_control.dart @@ -48,7 +48,7 @@ final cupertinoSegmentedControlIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 4, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/firebase/future_builder.dart b/teta_widgets/lib/src/elements/bodies/firebase/future_builder.dart index 01743af1..fdcc60f9 100644 --- a/teta_widgets/lib/src/elements/bodies/firebase/future_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/firebase/future_builder.dart @@ -41,7 +41,7 @@ final firebaseFutureBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.firebase, + category: NodeCategories.unclassified, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/firebase/is_authenticated.dart b/teta_widgets/lib/src/elements/bodies/firebase/is_authenticated.dart index 5c36b6d5..e050a8a2 100644 --- a/teta_widgets/lib/src/elements/bodies/firebase/is_authenticated.dart +++ b/teta_widgets/lib/src/elements/bodies/firebase/is_authenticated.dart @@ -39,7 +39,7 @@ final firebaseIsAuthenticatedIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.firebase, + category: NodeCategories.unclassified, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/firebase/pagination.dart b/teta_widgets/lib/src/elements/bodies/firebase/pagination.dart index f3edd30b..dc567f30 100644 --- a/teta_widgets/lib/src/elements/bodies/firebase/pagination.dart +++ b/teta_widgets/lib/src/elements/bodies/firebase/pagination.dart @@ -41,7 +41,7 @@ final firebasePaginationIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.firebase, + category: NodeCategories.unclassified, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/firebase/stream_builder.dart b/teta_widgets/lib/src/elements/bodies/firebase/stream_builder.dart index eb22008e..a5357b92 100644 --- a/teta_widgets/lib/src/elements/bodies/firebase/stream_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/firebase/stream_builder.dart @@ -39,7 +39,7 @@ final firebaseStreamBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.firebase, + category: NodeCategories.unclassified, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/gap.dart b/teta_widgets/lib/src/elements/bodies/gap.dart index 74a4d282..dd90e011 100644 --- a/teta_widgets/lib/src/elements/bodies/gap.dart +++ b/teta_widgets/lib/src/elements/bodies/gap.dart @@ -28,7 +28,7 @@ final gapIntrinsicStates = IntrinsicStates( displayName: NodeType.name(_globalType), type: _globalType, maxChildren: 0, - category: NodeCategories.space, + category: NodeCategories.unclassified, canHave: ChildrenEnum.none, addChildLabels: [], gestures: [], diff --git a/teta_widgets/lib/src/elements/bodies/gridview.dart b/teta_widgets/lib/src/elements/bodies/gridview.dart index 7b25fdc3..032ecb1b 100644 --- a/teta_widgets/lib/src/elements/bodies/gridview.dart +++ b/teta_widgets/lib/src/elements/bodies/gridview.dart @@ -40,7 +40,7 @@ final gridIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/gridview_builder.dart b/teta_widgets/lib/src/elements/bodies/gridview_builder.dart index f21cfb14..cbd2f963 100644 --- a/teta_widgets/lib/src/elements/bodies/gridview_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/gridview_builder.dart @@ -41,7 +41,7 @@ final gridViewBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/hero.dart b/teta_widgets/lib/src/elements/bodies/hero.dart index b7ba13ba..3a622f57 100644 --- a/teta_widgets/lib/src/elements/bodies/hero.dart +++ b/teta_widgets/lib/src/elements/bodies/hero.dart @@ -37,7 +37,7 @@ final heroIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.animated, + category: NodeCategories.animations, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/https_requests_custom_backend/custom_http_request.dart b/teta_widgets/lib/src/elements/bodies/https_requests_custom_backend/custom_http_request.dart index d1cfb26a..6d046225 100644 --- a/teta_widgets/lib/src/elements/bodies/https_requests_custom_backend/custom_http_request.dart +++ b/teta_widgets/lib/src/elements/bodies/https_requests_custom_backend/custom_http_request.dart @@ -45,7 +45,7 @@ final customHttpRequestIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [ diff --git a/teta_widgets/lib/src/elements/bodies/icon.dart b/teta_widgets/lib/src/elements/bodies/icon.dart index f209555a..7a568fb3 100644 --- a/teta_widgets/lib/src/elements/bodies/icon.dart +++ b/teta_widgets/lib/src/elements/bodies/icon.dart @@ -38,7 +38,7 @@ final iconIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Material Icon', type: _globalType, - category: NodeCategories.icon, + category: NodeCategories.advanced, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/icon_feather.dart b/teta_widgets/lib/src/elements/bodies/icon_feather.dart index 05fe7264..c0ecc670 100644 --- a/teta_widgets/lib/src/elements/bodies/icon_feather.dart +++ b/teta_widgets/lib/src/elements/bodies/icon_feather.dart @@ -39,7 +39,7 @@ final featherIconIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Feather Icon', type: _globalType, - category: NodeCategories.icon, + category: NodeCategories.basic, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/icon_font_awesome.dart b/teta_widgets/lib/src/elements/bodies/icon_font_awesome.dart index d1a8ace8..e463556f 100644 --- a/teta_widgets/lib/src/elements/bodies/icon_font_awesome.dart +++ b/teta_widgets/lib/src/elements/bodies/icon_font_awesome.dart @@ -39,7 +39,7 @@ final fontAwesomeIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'FA Icon', type: _globalType, - category: NodeCategories.icon, + category: NodeCategories.advanced, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/icon_line.dart b/teta_widgets/lib/src/elements/bodies/icon_line.dart index 5b7aecf7..83502065 100644 --- a/teta_widgets/lib/src/elements/bodies/icon_line.dart +++ b/teta_widgets/lib/src/elements/bodies/icon_line.dart @@ -39,7 +39,7 @@ final lineIconIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: 'Line Icon', type: _globalType, - category: NodeCategories.icon, + category: NodeCategories.advanced, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/ignore_pointer.dart b/teta_widgets/lib/src/elements/bodies/ignore_pointer.dart index d9fc6128..f1622b57 100644 --- a/teta_widgets/lib/src/elements/bodies/ignore_pointer.dart +++ b/teta_widgets/lib/src/elements/bodies/ignore_pointer.dart @@ -34,7 +34,7 @@ final ignorePointIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.logic, + category: NodeCategories.visibility, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/index_stack.dart b/teta_widgets/lib/src/elements/bodies/index_stack.dart index a1e9cf1e..e79185e2 100644 --- a/teta_widgets/lib/src/elements/bodies/index_stack.dart +++ b/teta_widgets/lib/src/elements/bodies/index_stack.dart @@ -37,7 +37,7 @@ final indexedStackIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.logic, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/limitedBox.dart b/teta_widgets/lib/src/elements/bodies/limitedBox.dart index 0278a148..9b47132f 100644 --- a/teta_widgets/lib/src/elements/bodies/limitedBox.dart +++ b/teta_widgets/lib/src/elements/bodies/limitedBox.dart @@ -37,7 +37,7 @@ final limitedBoxIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.advanced, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/listview.dart b/teta_widgets/lib/src/elements/bodies/listview.dart index acd3e3dd..1d47b5f1 100644 --- a/teta_widgets/lib/src/elements/bodies/listview.dart +++ b/teta_widgets/lib/src/elements/bodies/listview.dart @@ -38,7 +38,7 @@ final listIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/listview_builder.dart b/teta_widgets/lib/src/elements/bodies/listview_builder.dart index c2872f1e..73edb1c5 100644 --- a/teta_widgets/lib/src/elements/bodies/listview_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/listview_builder.dart @@ -38,7 +38,7 @@ final listViewBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/lottie.dart b/teta_widgets/lib/src/elements/bodies/lottie.dart index 5b107333..5c728814 100644 --- a/teta_widgets/lib/src/elements/bodies/lottie.dart +++ b/teta_widgets/lib/src/elements/bodies/lottie.dart @@ -36,7 +36,7 @@ final lottieIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.animations, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/map.dart b/teta_widgets/lib/src/elements/bodies/map.dart index 43f9ed86..656f5489 100644 --- a/teta_widgets/lib/src/elements/bodies/map.dart +++ b/teta_widgets/lib/src/elements/bodies/map.dart @@ -34,9 +34,9 @@ final mapIntrinsicStates = IntrinsicStates( blockedTypes: [], synonymous: ['map'], advicedChildrenCanHaveAtLeastAChild: [], - displayName: NodeType.name(_globalType), + displayName: 'Mapbox', type: _globalType, - category: NodeCategories.map, + category: NodeCategories.advanced, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/marker.dart b/teta_widgets/lib/src/elements/bodies/marker.dart index ec86c8c8..8bb2c92f 100644 --- a/teta_widgets/lib/src/elements/bodies/marker.dart +++ b/teta_widgets/lib/src/elements/bodies/marker.dart @@ -35,9 +35,9 @@ final markerIntrinsicStates = IntrinsicStates( blockedTypes: [], synonymous: [NodeType.name(_globalType), 'map', 'icon'], advicedChildrenCanHaveAtLeastAChild: [], - displayName: NodeType.name(_globalType), + displayName: 'Mapbox Marker', type: _globalType, - category: NodeCategories.map, + category: NodeCategories.advanced, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/opacity.dart b/teta_widgets/lib/src/elements/bodies/opacity.dart index b7466689..55adcf22 100644 --- a/teta_widgets/lib/src/elements/bodies/opacity.dart +++ b/teta_widgets/lib/src/elements/bodies/opacity.dart @@ -37,7 +37,7 @@ final opacityIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.logic, + category: NodeCategories.visibility, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/page_view.dart b/teta_widgets/lib/src/elements/bodies/page_view.dart index 79f83afc..a8ffb73b 100644 --- a/teta_widgets/lib/src/elements/bodies/page_view.dart +++ b/teta_widgets/lib/src/elements/bodies/page_view.dart @@ -35,7 +35,7 @@ final pageViewIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], @@ -105,5 +105,11 @@ class PageViewBody extends NodeBody { final int? loop, ) => PageViewCodeTemplate.toCode( - context, pageId, this, node, children ?? [], loop); + context, + pageId, + this, + node, + children ?? [], + loop, + ); } diff --git a/teta_widgets/lib/src/elements/bodies/radio.dart b/teta_widgets/lib/src/elements/bodies/radio.dart index feb63203..1e31b35b 100644 --- a/teta_widgets/lib/src/elements/bodies/radio.dart +++ b/teta_widgets/lib/src/elements/bodies/radio.dart @@ -41,7 +41,7 @@ final radioIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: null, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/responsive/wrapper.dart b/teta_widgets/lib/src/elements/bodies/responsive/wrapper.dart index af16aa7a..c7db6334 100644 --- a/teta_widgets/lib/src/elements/bodies/responsive/wrapper.dart +++ b/teta_widgets/lib/src/elements/bodies/responsive/wrapper.dart @@ -28,9 +28,9 @@ final wrapperIntrinsicStates = IntrinsicStates( blockedTypes: [], synonymous: [NodeType.name(_globalType), 'baseline', 'bottom'], advicedChildrenCanHaveAtLeastAChild: [], - displayName: 'Responsive wrapper', + displayName: 'Section', type: _globalType, - category: NodeCategories.responsive, + category: NodeCategories.basic, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/responsive_condition.dart b/teta_widgets/lib/src/elements/bodies/responsive_condition.dart index 432ffff2..8ad8dd0f 100644 --- a/teta_widgets/lib/src/elements/bodies/responsive_condition.dart +++ b/teta_widgets/lib/src/elements/bodies/responsive_condition.dart @@ -40,7 +40,7 @@ final responsiveIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.responsive, + category: NodeCategories.visibility, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/stack.dart b/teta_widgets/lib/src/elements/bodies/stack.dart index 88b2cbba..2dd9defe 100644 --- a/teta_widgets/lib/src/elements/bodies/stack.dart +++ b/teta_widgets/lib/src/elements/bodies/stack.dart @@ -28,7 +28,7 @@ final stackIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart b/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart index 7a31dda8..79a9de4f 100644 --- a/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart @@ -43,7 +43,7 @@ final supabaseFutureBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.supabase, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart b/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart index 7449bd99..fb6ed8b9 100644 --- a/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart @@ -41,7 +41,7 @@ final supabaseStreamBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.supabase, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/supabase/logged_user.dart b/teta_widgets/lib/src/elements/bodies/supabase/logged_user.dart index 903a0997..f8098908 100644 --- a/teta_widgets/lib/src/elements/bodies/supabase/logged_user.dart +++ b/teta_widgets/lib/src/elements/bodies/supabase/logged_user.dart @@ -37,7 +37,7 @@ final supabaseLoggedUserIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.supabase, + category: NodeCategories.dynamicCollection, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/tcard.dart b/teta_widgets/lib/src/elements/bodies/tcard.dart index dccc2e6c..bdd17a1f 100644 --- a/teta_widgets/lib/src/elements/bodies/tcard.dart +++ b/teta_widgets/lib/src/elements/bodies/tcard.dart @@ -44,7 +44,7 @@ final tcardIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/tcard_builder.dart b/teta_widgets/lib/src/elements/bodies/tcard_builder.dart index fb454300..0c2890fb 100644 --- a/teta_widgets/lib/src/elements/bodies/tcard_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/tcard_builder.dart @@ -52,7 +52,7 @@ final tcardBuilderIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/template.dart b/teta_widgets/lib/src/elements/bodies/template.dart index 78ee54d7..0e2156c7 100644 --- a/teta_widgets/lib/src/elements/bodies/template.dart +++ b/teta_widgets/lib/src/elements/bodies/template.dart @@ -38,6 +38,7 @@ class NTemplate extends CNode { @override Widget toWidget({ required final TetaWidgetState state, + final bool isVertical = true, final CNode? child, final List? children, }) => @@ -47,5 +48,6 @@ class NTemplate extends CNode { String toString() => 'NNull { nid: $nid }'; @override - Future toCode(final BuildContext context) => Future.value('Container(),'); + Future toCode(final BuildContext context) => + Future.value('Container(),'); } diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/count.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/count.dart index 44516690..46b2c8dc 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/count.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/count.dart @@ -45,7 +45,7 @@ final cmsCountIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: ['Add new if successful', 'Add new if empty or failed'], diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/custom_query.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/custom_query.dart index 7ffeaca7..c680d070 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/custom_query.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/custom_query.dart @@ -45,7 +45,7 @@ final cmsCustomQueryStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/fetch.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/fetch.dart index 0ce71cc0..cc50fc57 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/fetch.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/fetch.dart @@ -45,7 +45,7 @@ final cmsFetchIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [ diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart index 3aa80751..44563878 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart @@ -38,7 +38,7 @@ final cmsLoggedUserIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/stream.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/stream.dart index bc3ceabc..c18c902e 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/stream.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/stream.dart @@ -47,7 +47,7 @@ final cmsStreamIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.dynamicCollection, maxChildren: 2, canHave: ChildrenEnum.children, addChildLabels: [ diff --git a/teta_widgets/lib/src/elements/bodies/textbutton.dart b/teta_widgets/lib/src/elements/bodies/textbutton.dart index 43305514..caa9d03e 100644 --- a/teta_widgets/lib/src/elements/bodies/textbutton.dart +++ b/teta_widgets/lib/src/elements/bodies/textbutton.dart @@ -37,7 +37,7 @@ final textButtonIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/textfield.dart b/teta_widgets/lib/src/elements/bodies/textfield.dart index 509a93e5..c80c3f02 100644 --- a/teta_widgets/lib/src/elements/bodies/textfield.dart +++ b/teta_widgets/lib/src/elements/bodies/textfield.dart @@ -45,7 +45,7 @@ final textFieldIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 0, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/tooltip.dart b/teta_widgets/lib/src/elements/bodies/tooltip.dart index b7e70d9f..3670910f 100644 --- a/teta_widgets/lib/src/elements/bodies/tooltip.dart +++ b/teta_widgets/lib/src/elements/bodies/tooltip.dart @@ -33,7 +33,7 @@ final tooltipIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.input, + category: NodeCategories.form, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/visibility.dart b/teta_widgets/lib/src/elements/bodies/visibility.dart index eda8f594..c1c6e307 100644 --- a/teta_widgets/lib/src/elements/bodies/visibility.dart +++ b/teta_widgets/lib/src/elements/bodies/visibility.dart @@ -37,7 +37,7 @@ final visibilityIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.logic, + category: NodeCategories.visibility, maxChildren: 1, canHave: ChildrenEnum.child, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/webview.dart b/teta_widgets/lib/src/elements/bodies/webview.dart index 4b4e33f6..462fc3ec 100644 --- a/teta_widgets/lib/src/elements/bodies/webview.dart +++ b/teta_widgets/lib/src/elements/bodies/webview.dart @@ -36,7 +36,7 @@ final webviewIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.basic, + category: NodeCategories.advanced, maxChildren: 1, canHave: ChildrenEnum.none, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/bodies/wrap.dart b/teta_widgets/lib/src/elements/bodies/wrap.dart index 90bc9bc8..bc2410f2 100644 --- a/teta_widgets/lib/src/elements/bodies/wrap.dart +++ b/teta_widgets/lib/src/elements/bodies/wrap.dart @@ -33,7 +33,7 @@ final wrapIntrinsicStates = IntrinsicStates( advicedChildrenCanHaveAtLeastAChild: [], displayName: NodeType.name(_globalType), type: _globalType, - category: NodeCategories.list, + category: NodeCategories.layout, maxChildren: null, canHave: ChildrenEnum.children, addChildLabels: [], diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart index bfd6eafb..3639f389 100644 --- a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/src/rendering/find.dart'; import 'package:teta_core/teta_core.dart'; +import 'package:teta_repositories/teta_repositories.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; +import 'package:teta_widgets/src/elements/index.dart'; class DragAndDropBuilder extends StatefulWidget { const DragAndDropBuilder({ @@ -17,35 +21,65 @@ class DragAndDropBuilder extends StatefulWidget { } class _DragAndDropBuilderState extends State { + bool canReceiveDrag = false; bool isDragging = false; bool? onLeft; + CNode? parent; final key = GlobalKey(); + @override + void initState() { + parent = FindNodeRendering.findParentByChildrenIds( + flatList: BlocProvider.of(context).state.flatList ?? [], + element: widget.state.node, + ); + canReceiveDrag = parent?.globalType == NType.row || + parent?.globalType == NType.column || + parent?.globalType == NType.listView; + + super.initState(); + } + @override Widget build(final BuildContext context) { + if (!canReceiveDrag) return widget.child; return DragTarget( key: key, - onAccept: (final data) { - Logger.printDefault('On accept'); + onAccept: (final data) async { setState(() { isDragging = true; }); + final currentIndex = + parent?.childrenIds.ids.indexOf(widget.state.node.nid); + if (currentIndex == null) return; + if (parent == null) return; + final id = await NodeRepository.addNodeWithCustomIndex( + node: data.node!, + parent: parent!, + index: onLeft ?? false ? currentIndex : currentIndex + 1, + pageId: BlocProvider.of(context).state.id, + ); }, onMove: (final details) { - final leftFlag = details.offset.dx > key.globalPaintBounds!.left && - details.offset.dx <= key.globalPaintBounds!.center.dx; - Logger.printSuccess('Is on left: $leftFlag'); + late bool leftFlag; + if (widget.state.isVertical) { + leftFlag = details.offset.dy > key.globalPaintBounds!.top && + details.offset.dy <= key.globalPaintBounds!.center.dy; + } else { + leftFlag = details.offset.dx > key.globalPaintBounds!.left && + details.offset.dx <= key.globalPaintBounds!.center.dx; + } setState(() { isDragging = true; if (key.globalPaintBounds != null) { - onLeft = leftFlag; + onLeft = !leftFlag; } }); }, onLeave: (final details) { setState(() { isDragging = false; - onLeft = false; + onLeft = null; }); }, builder: (final context, final candidateData, final rejectedData) { @@ -56,28 +90,59 @@ class _DragAndDropBuilderState extends State { children: [ widget.child, Positioned.fill( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (onLeft ?? false) - TContainer( - width: 5, - height: key.globalPaintBounds!.height, - decoration: const BoxDecoration(color: primaryColor), - ) - else - const Spacer(), - if (!(onLeft ?? true)) - TContainer( - width: 5, - height: key.globalPaintBounds!.height, - decoration: const BoxDecoration(color: primaryColor), + child: widget.state.isVertical + ? Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (onLeft ?? false) + TContainer( + margin: EI.smH, + width: key.globalPaintBounds!.width, + height: 5, + decoration: + const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + if (!(onLeft ?? true)) + TContainer( + margin: EI.smH, + width: key.globalPaintBounds!.width, + height: 5, + decoration: + const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + ], ) - else - const Spacer(), - ], - ), + : Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (onLeft ?? false) + TContainer( + margin: EI.smV, + width: 5, + height: key.globalPaintBounds!.height, + decoration: + const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + if (!(onLeft ?? true)) + TContainer( + margin: EI.smV, + width: 5, + height: key.globalPaintBounds!.height, + decoration: + const BoxDecoration(color: primaryColor), + ) + else + const Spacer(), + ], + ), ), ], ); diff --git a/teta_widgets/lib/src/elements/builder/drag_target.dart b/teta_widgets/lib/src/elements/builder/drag_target.dart deleted file mode 100644 index 85133992..00000000 --- a/teta_widgets/lib/src/elements/builder/drag_target.dart +++ /dev/null @@ -1,101 +0,0 @@ -/*import 'package:fast_immutable_collections/fast_immutable_collections.dart'; - -// Flutter imports: -import 'package:flutter/material.dart'; - -// Package imports: -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:mobile_editor/src/blocs/focus/index.dart'; -import 'package:mobile_editor/src/blocs/focus_page/bloc.dart'; -import 'package:mobile_editor/src/blocs/focus_project/index.dart'; -import 'package:mobile_editor/src/blocs/nodes/index.dart'; -import 'package:mobile_editor/src/elements/nodes/node.dart'; -import 'package:mobile_editor/src/models/drag_target.dart'; -import 'package:mobile_editor/src/models/page.dart'; -import 'package:mobile_editor/src/repositories/node.dart'; -import 'package:nil/nil.dart'; - -class DragTargetWidget extends StatefulWidget { - DragTargetWidget({ - Key? key, - required this.node, - this.width, - this.height, - this.child, - }) : super(key: key); - - final CNode _node; - final double? _width; - final double? _height; - final Widget? _child; - - @override - _DragTargetState createState() => _DragTargetState(); -} - -class _DragTargetState extends State { - bool isActive = false; - bool flagInto = false; - - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, prjState) { - if (prjState is ProjectLoaded) - return BlocBuilder( - builder: (context, pageState) { - return BlocBuilder>( - builder: (context, nodesState) { - return DragTarget( - builder: (context, list, list2) { - return Opacity( - opacity: isActive ? 0.5 : 1, child: widget.child); - }, - onMove: (details) { - if (!flagInto) { - BlocProvider.of(context) - ..add(OnFocus(node: widget.node)); - setState(() { - flagInto = true; - isActive = true; - }); - } - }, - onAccept: (item) { - setState(() { - isActive = true; - }); - NodeRepository.addNode( - prj: prjState.prj, - page: pageState, - nodes: nodesState, - parent: widget.node, - index: (widget.node.children != null) - ? widget.node.children!.length.toDouble() - : 0, - item: item, - context: context, - ); - setState(() { - isActive = false; - flagInto = false; - }); - }, - onLeave: (item) { - setState(() { - isActive = false; - flagInto = false; - }); - }, - ); - }, - ); - }, - ); - else - return const SizedBox(); - }, - ); - } -} -*/ diff --git a/teta_widgets/lib/src/elements/builder/draggable.dart b/teta_widgets/lib/src/elements/builder/draggable.dart deleted file mode 100644 index eb0aeaa0..00000000 --- a/teta_widgets/lib/src/elements/builder/draggable.dart +++ /dev/null @@ -1,48 +0,0 @@ -/*import 'package:flutter/material.dart'; - -// Package imports: -import 'package:mobile_editor/src/elements/nodes/node.dart'; - -class DraggableNode extends StatefulWidget { - final bool forPlay; - final CNode node; - final Widget child; - - DraggableNode({ - required this.node, - required this.child, - required this.forPlay, - }); - - @override - _DraggableState createState() => _DraggableState(); -} - -class _DraggableState extends State { - bool isDragged = false; - - @override - Widget build(BuildContext context) { - return (widget.forPlay) ? widget.child : widget.child; - /*LongPressDraggable( - data: widget.node, - onDragStarted: () { - setState(() { - isDragged = true; - }); - }, - onDragEnd: (details) { - setState(() { - isDragged = false; - }); - }, - onDraggableCanceled: (velocity, offset) { - setState(() { - isDragged = false; - }); - }, - feedback: widget.child, - child: widget.child);*/ - } -} -*/ diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 2beccbf9..fc236cdc 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -3,15 +3,15 @@ // Package imports: import 'package:collection/collection.dart'; +import 'package:flutter/gestures.dart'; // Flutter imports: import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/rendering/find.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; -import 'package:teta_widgets/src/elements/builder/drag_and_drop.dart'; +import 'package:teta_widgets/src/elements/index.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/node.dart'; /// Node Selection class NodeSelection extends StatefulWidget { @@ -46,7 +46,12 @@ class NodeSelectionState extends State { @override Widget build(final BuildContext context) { - if (widget.state.forPlay) return body(); + if (widget.state.forPlay) { + return _Body( + state: widget.state, + child: widget.child, + ); + } return DragAndDropBuilder( state: widget.state, child: MouseRegion( @@ -59,111 +64,49 @@ class NodeSelectionState extends State { BlocProvider.of(context).add(OnHover(node: parent!)); } }, - child: GestureDetector( - onTap: () { - BlocProvider.of(context) - .add(OnFocus(node: widget.state.node)); - BlocProvider.of(context) - .jumpTo(context, widget.state.node); + child: Listener( + onPointerDown: (final event) { + if (event.kind == PointerDeviceKind.mouse && + event.buttons == kSecondaryMouseButton) { + if (widget.state.node.intrinsicState.type != NType.scaffold && + widget.state.node.intrinsicState.type != NType.appBar && + widget.state.node.intrinsicState.type != NType.bottomBar && + widget.state.node.intrinsicState.type != NType.drawer) { + RightContextMenu.instance.open( + event, + context, + widget.state.node, + ); + } + } }, - child: body(), + child: GestureDetector( + onTap: () { + BlocProvider.of(context) + .add(OnFocus(node: widget.state.node)); + BlocProvider.of(context) + .jumpTo(context, widget.state.node); + }, + child: _Body( + state: widget.state, + child: widget.child, + ), + ), ), ), ); - /*return BlocBuilder>( - builder: (context, authorsState) { - var authorColor = Colors.transparent; - var isSelectFromOtherAuthors = false; - var isHoveredFromOtherAuthors = false; - final index = authorsState.indexWhere((element) => - element.focusNode == widget.node.nid || - element.hoverNode == widget.node.nid); - if (index != -1) { - final item = authorsState[index]; - final userState = BlocProvider.of(context).state - as Authenticated; - if (item.id != userState.user.id && - item.focusNode != BlocProvider.of(context).state.nid) { - if (item.focusNode == widget.node.nid) { - isSelectFromOtherAuthors = item.isOnline ?? false; - authorColor = item.color!; - } else { - isHoveredFromOtherAuthors = item.isOnline ?? false; - authorColor = item.color!; - } - } else { - authorColor = Colors.transparent; - isSelectFromOtherAuthors = false; - } - } - return BlocBuilder( - builder: (context, authState) { - if (authState is Authenticated) { - return BlocBuilder( - builder: (context, prjState) { - if (prjState is ProjectLoaded) { - return InkWell( - onTap: () { - if (!widget.forPlay) { - BlocProvider.of(context) - .add(OnFocus(node: widget.node)); - if (BlocProvider.of(context).state == - PanelsEnum.tutorials) { - BlocProvider.of(context) - .add(ChangeIndex(type: PanelsEnum.none)); - } - if (BlocProvider.of(context) - .state - .where((element) => - element.isOnline! && - element.page == - BlocProvider.of( - context) - .state - .id) - .length > - 1) { - ProjectRepository.setFocusNode( - prjId: prjState.prj.id, - userId: authState.user.id, - nodeId: widget.node.nid, - ); - } - } - }, - child: MouseRegion( - onEnter: (e) { - BlocProvider.of(context) - .add(OnHover(node: widget.node)); - }, - onExit: (e) { - if (parent != null) { - BlocProvider.of(context) - .add(OnHover(node: parent!)); - } - }, - child: body( - authState, - prjState, - authorColor, - isSelectFromOtherAuthors, - isHoveredFromOtherAuthors, - ), - ), - ); - } - return const SizedBox(); - }, - ); - } - return const SizedBox(); - }, - ); - }, - );*/ } +} + +class _Body extends StatelessWidget { + const _Body({final Key? key, required this.state, required this.child}) + : super(key: key); + + final TetaWidgetState state; + final Widget child; - Widget body() { + @override + Widget build(final BuildContext context) { return BlocBuilder>( builder: (final context, final onFocusNodes) { return BlocBuilder( @@ -177,34 +120,33 @@ class NodeSelectionState extends State { border: Border.all( color: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.state.node.nid, + element.nid == state.node.nid, ) != null || - onHover.nid == widget.state.node.nid + onHover.nid == state.node.nid ? primaryColor : Colors.transparent, - style: (widget.state.forPlay) + style: (state.forPlay) ? BorderStyle.none : BorderStyle.solid, width: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.state.node.nid, + element.nid == state.node.nid, ) != null ? 1 - : onHover.nid == widget.state.node.nid + : onHover.nid == state.node.nid ? 2 : 0, ), ), - child: widget.child, + child: child, ), if (onFocusNodes.firstWhereOrNull( - (final element) => - element.nid == widget.state.node.nid, + (final element) => element.nid == state.node.nid, ) != null || - onHover.nid == widget.state.node.nid) + onHover.nid == state.node.nid) Transform.translate( offset: const Offset(0, -20), child: ColoredBox( @@ -215,26 +157,13 @@ class NodeSelectionState extends State { horizontal: 4, ), child: TDetailLabel( - widget.state.node.intrinsicState.displayName, + state.node.intrinsicState.displayName, ), ), ), ), ], ); - /*Positioned( - bottom: 0, - left: 0, - right: 0, - child: (widget.node.canHaveChildren(widget.node.type)) - ? InsideDragTargetWidget( - node: widget.node, - width: double.maxFinite, - height: 10, - index: widget.index, - ) - : const SizedBox(), - ),*/ }, ); }, diff --git a/teta_widgets/lib/src/elements/index.dart b/teta_widgets/lib/src/elements/index.dart index 6eb5d65b..fdd86c39 100644 --- a/teta_widgets/lib/src/elements/index.dart +++ b/teta_widgets/lib/src/elements/index.dart @@ -1,7 +1,6 @@ export './builder/add_dataset.dart'; export './builder/child_condition.dart'; -export './builder/drag_target.dart'; -export './builder/draggable.dart'; +export './builder/drag_and_drop.dart'; export './builder/gesture.dart'; export './builder/inside_drag_target.dart'; export './builder/node_selection.dart'; diff --git a/teta_widgets/lib/src/elements/nodes/categories.dart b/teta_widgets/lib/src/elements/nodes/categories.dart index dab89ab1..b4cd64b4 100644 --- a/teta_widgets/lib/src/elements/nodes/categories.dart +++ b/teta_widgets/lib/src/elements/nodes/categories.dart @@ -3,20 +3,11 @@ enum NodeCategories { unclassified, basic, - advanced, - space, - list, - input, - map, - icon, - firebase, - supabase, - revenueCat, + layout, + dynamicCollection, + form, subscriptions, - wordpress, - logic, - navigation, - responsive, - experimental, - animated, + visibility, + animations, + advanced, } diff --git a/teta_widgets/lib/src/elements/nodes/dynamic.dart b/teta_widgets/lib/src/elements/nodes/dynamic.dart index f64b5c46..fc50d1a9 100644 --- a/teta_widgets/lib/src/elements/nodes/dynamic.dart +++ b/teta_widgets/lib/src/elements/nodes/dynamic.dart @@ -221,9 +221,15 @@ class NDynamic extends CNode { '$globalType { nid: $nid, children: $children, child: $child }'; @override - Widget toWidget({required final TetaWidgetState state}) { + Widget toWidget({ + required final TetaWidgetState state, + final bool isVertical = true, + }) { return body.toWidget( - state: state.copyWith(node: this), + state: state.copyWith( + node: this, + isVertical: isVertical, + ), child: child, children: children, ); diff --git a/teta_widgets/lib/src/elements/nodes/nnull.dart b/teta_widgets/lib/src/elements/nodes/nnull.dart index 52add596..853ed834 100644 --- a/teta_widgets/lib/src/elements/nodes/nnull.dart +++ b/teta_widgets/lib/src/elements/nodes/nnull.dart @@ -45,11 +45,16 @@ class NNull extends CNode { Map toJson() => {}; @override - Widget toWidget({required final TetaWidgetState state}) => const SizedBox(); + Widget toWidget({ + required final TetaWidgetState state, + final bool isVertical = true, + }) => + const SizedBox(); @override String toString() => 'NNull { nid: $nid }'; @override - Future toCode(final BuildContext context) => Future.value('const SizedBox(),'); + Future toCode(final BuildContext context) => + Future.value('const SizedBox(),'); } diff --git a/teta_widgets/lib/src/elements/nodes/node.dart b/teta_widgets/lib/src/elements/nodes/node.dart index bc883ab4..e1ca4672 100644 --- a/teta_widgets/lib/src/elements/nodes/node.dart +++ b/teta_widgets/lib/src/elements/nodes/node.dart @@ -74,7 +74,11 @@ abstract class CNode extends Equatable { static List get names => NType.values.map(NodeType.name).toList(); /// Render a Widget from node - Widget toWidget({required final TetaWidgetState state}) => const SizedBox(); + Widget toWidget({ + required final TetaWidgetState state, + final bool isVertical = true, + }) => + const SizedBox(); /// Render a Widget from node Widget toWidgetFromParams({ diff --git a/teta_widgets/lib/src/elements/widgets/listview.dart b/teta_widgets/lib/src/elements/widgets/listview.dart index 8832258d..6e592279 100644 --- a/teta_widgets/lib/src/elements/widgets/listview.dart +++ b/teta_widgets/lib/src/elements/widgets/listview.dart @@ -108,7 +108,10 @@ class _WListViewState extends State { itemCount: children.isEmpty ? 1 : children.length, itemBuilder: (final context, final index) { return children.isNotEmpty - ? children[index].toWidget(state: widget.state) + ? children[index].toWidget( + state: widget.state, + isVertical: widget.isVertical, + ) : PlaceholderChildBuilder( name: widget.state.node.intrinsicState.displayName, @@ -129,7 +132,10 @@ class _WListViewState extends State { itemCount: children.isEmpty ? 1 : children.length, itemBuilder: (final context, final index) { return children.isNotEmpty - ? children[index].toWidget(state: widget.state) + ? children[index].toWidget( + state: widget.state, + isVertical: widget.isVertical, + ) : PlaceholderChildBuilder( name: widget.state.node.intrinsicState.displayName, node: widget.state.node, diff --git a/teta_widgets/lib/src/elements/widgets/listview_builder.dart b/teta_widgets/lib/src/elements/widgets/listview_builder.dart index 8cadaec2..515b36f5 100644 --- a/teta_widgets/lib/src/elements/widgets/listview_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/listview_builder.dart @@ -147,6 +147,7 @@ class WListViewBuilderState extends State { state: widget.state.copyWith( loop: index, ), + isVertical: widget.isVertical, ) : PlaceholderChildBuilder( name: widget.state.node.intrinsicState.displayName, diff --git a/teta_widgets/lib/src/elements/widgets/row.dart b/teta_widgets/lib/src/elements/widgets/row.dart index 3fe33867..14c0a08a 100644 --- a/teta_widgets/lib/src/elements/widgets/row.dart +++ b/teta_widgets/lib/src/elements/widgets/row.dart @@ -72,7 +72,10 @@ class _WRowState extends State { children: children.isNotEmpty ? children .map( - (final e) => e.toWidget(state: widget._state), + (final e) => e.toWidget( + state: widget._state, + isVertical: false, + ), ) .toList() : [ @@ -92,7 +95,10 @@ class _WRowState extends State { children: widget._children.isNotEmpty ? widget._children .map( - (final e) => e.toWidget(state: widget._state), + (final e) => e.toWidget( + state: widget._state, + isVertical: false, + ), ) .toList() : [ From cc50f4e2086639a9d892541e9b5a58de92c2e699 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Mon, 2 Jan 2023 11:18:38 +0100 Subject: [PATCH 05/23] fix(nodes order) --- .../src/elements/builder/node_selection.dart | 61 ++++---- .../elements/builder/placeholder_child.dart | 133 ++++++------------ .../src/elements/widgets/bottombaritem.dart | 25 ++-- 3 files changed, 92 insertions(+), 127 deletions(-) diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index fc236cdc..868d8ad1 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -1,9 +1,7 @@ // Flutter imports: // ignore_for_file: public_member_api_docs -// Package imports: import 'package:collection/collection.dart'; -import 'package:flutter/gestures.dart'; // Flutter imports: import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -66,19 +64,11 @@ class NodeSelectionState extends State { }, child: Listener( onPointerDown: (final event) { - if (event.kind == PointerDeviceKind.mouse && - event.buttons == kSecondaryMouseButton) { - if (widget.state.node.intrinsicState.type != NType.scaffold && - widget.state.node.intrinsicState.type != NType.appBar && - widget.state.node.intrinsicState.type != NType.bottomBar && - widget.state.node.intrinsicState.type != NType.drawer) { - RightContextMenu.instance.open( - event, - context, - widget.state.node, - ); - } - } + RightContextMenu.instance.open( + event, + context, + widget.state.node, + ); }, child: GestureDetector( onTap: () { @@ -98,13 +88,23 @@ class NodeSelectionState extends State { } } -class _Body extends StatelessWidget { - const _Body({final Key? key, required this.state, required this.child}) - : super(key: key); +class _Body extends StatefulWidget { + const _Body({ + final Key? key, + required this.state, + required this.child, + }) : super(key: key); final TetaWidgetState state; final Widget child; + @override + State<_Body> createState() => _BodyState(); +} + +class _BodyState extends State<_Body> { + final key = GlobalKey(); + @override Widget build(final BuildContext context) { return BlocBuilder>( @@ -115,40 +115,45 @@ class _Body extends StatelessWidget { clipBehavior: Clip.none, children: [ DecoratedBox( + key: key, position: DecorationPosition.foreground, decoration: BoxDecoration( border: Border.all( color: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == state.node.nid, + element.nid == widget.state.node.nid, ) != null || - onHover.nid == state.node.nid + onHover.nid == widget.state.node.nid ? primaryColor : Colors.transparent, - style: (state.forPlay) + style: (widget.state.forPlay) ? BorderStyle.none : BorderStyle.solid, width: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == state.node.nid, + element.nid == widget.state.node.nid, ) != null ? 1 - : onHover.nid == state.node.nid + : onHover.nid == widget.state.node.nid ? 2 : 0, ), ), - child: child, + child: widget.child, ), if (onFocusNodes.firstWhereOrNull( - (final element) => element.nid == state.node.nid, + (final element) => + element.nid == widget.state.node.nid, ) != null || - onHover.nid == state.node.nid) + onHover.nid == widget.state.node.nid) Transform.translate( - offset: const Offset(0, -20), + offset: const Offset( + 0, + -20, + ), child: ColoredBox( color: primaryColor, child: Padding( @@ -157,7 +162,7 @@ class _Body extends StatelessWidget { horizontal: 4, ), child: TDetailLabel( - state.node.intrinsicState.displayName, + widget.state.node.intrinsicState.displayName, ), ), ), diff --git a/teta_widgets/lib/src/elements/builder/placeholder_child.dart b/teta_widgets/lib/src/elements/builder/placeholder_child.dart index 62e7e3c5..f7c7b435 100644 --- a/teta_widgets/lib/src/elements/builder/placeholder_child.dart +++ b/teta_widgets/lib/src/elements/builder/placeholder_child.dart @@ -1,17 +1,15 @@ // Flutter imports: import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_feather_icons/flutter_feather_icons.dart'; -import 'package:gap/gap.dart'; -import 'package:hovering/hovering.dart'; -// Package imports: import 'package:teta_core/teta_core.dart'; +import 'package:teta_repositories/teta_repositories.dart'; +// Package imports: import 'package:teta_widgets/src/elements/index.dart'; /// It displays the name of a CNode /// ATTENTION: Use this only inside a ChildConditionBuilder /// /builder/child_condition.dart -class PlaceholderChildBuilder extends StatelessWidget { +class PlaceholderChildBuilder extends StatefulWidget { /// Constructor const PlaceholderChildBuilder({ required this.name, @@ -25,92 +23,49 @@ class PlaceholderChildBuilder extends StatelessWidget { final CNode node; final bool forPlay; + @override + State createState() => + _PlaceholderChildBuilderState(); +} + +class _PlaceholderChildBuilderState extends State { + bool isDragging = false; + @override Widget build(final BuildContext context) { - return BlocBuilder( - builder: (final context, final state) { - if (forPlay) return const SizedBox(); - //if (!state) return THeadline3(name); - return Padding( - padding: const EdgeInsets.all(16), - child: BounceLarge( - onTap: () { - final prj = BlocProvider.of(context).state!; - final focusPageBloc = BlocProvider.of(context); - final refreshCubit = BlocProvider.of(context); - final focusBloc = BlocProvider.of(context); - showDialog( - context: context, - builder: (final c) => BlocProvider.value( - value: refreshCubit, - child: BlocProvider.value( - value: focusPageBloc, - child: BlocProvider.value( - value: focusBloc, - child: WidgetDialogDialog( - node: node, - prj: prj, - page: focusPageBloc.state, - forNewNode: true, - betweenNodes: false, - ), - ), - ), - ), - ); - }, - child: HoverWidget( - onHover: (final e) {}, - hoverChild: AnimatedContainer( - duration: const Duration(milliseconds: 200), - decoration: BoxDecoration( - color: Palette.blue.withOpacity(0.5), - borderRadius: BR(8), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Icon( - FeatherIcons.plus, - color: Colors.white, - ), - const Gap(Grid.small), - TParagraph( - BlocProvider.of(context).state.isPage - ? 'Add in $name' - : 'Add in ${name.contains('Page') ? name.replaceFirst('Page', 'Component') : name}', - ), - ], - ), - ), - ), - child: AnimatedContainer( - duration: const Duration(milliseconds: 200), - decoration: BoxDecoration( - color: Palette.blue.withOpacity(0.2), - borderRadius: BR(8), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Icon( - FeatherIcons.plus, - color: Colors.white, - ), - const Gap(Grid.small), - TParagraph( - BlocProvider.of(context).state.isPage - ? 'Add in $name' - : 'Add in ${name.contains('Page') ? name.replaceFirst('Page', 'Component') : name}', - ), - ], - ), - ), - ), + if (widget.forPlay) return const SizedBox(); + return DragTarget( + onAccept: (final data) async { + setState(() { + isDragging = true; + }); + + final id = await NodeRepository.addNodeWithCustomIndex( + node: data.node!, + parent: widget.node, + index: 0, + pageId: BlocProvider.of(context).state.id, + ); + }, + onMove: (final details) { + setState(() { + isDragging = true; + }); + }, + onLeave: (final details) { + setState(() { + isDragging = false; + }); + }, + builder: (final context, final candidateData, final rejectedData) { + return TContainer( + width: double.infinity, + height: 24, + decoration: BoxDecoration( + color: + isDragging ? primaryColor.withOpacity(0.3) : Colors.transparent, + border: Border.all( + color: Palette.txtGrey.withOpacity(0.3), ), ), ); diff --git a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart index 2619c642..175f741a 100644 --- a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart +++ b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart @@ -36,12 +36,6 @@ class WBottomBarItem extends StatelessWidget { @override Widget build(final BuildContext context) { - final isLight = BlocProvider.of(context).state; - PaletteModel? model; - BlocProvider.of(context).state.forEach((final element) { - if (element.id == fill.paletteStyle) model = element; - if (element.name == fill.paletteStyle) model = element; - }); return NodeSelectionBuilder( state: state, child: GestureDetector( @@ -68,10 +62,21 @@ class WBottomBarItem extends StatelessWidget { ), child: Column( children: [ - Icon( - MdiIcons.fromString(icon), - color: _getBottomBarItemColor(model, isLight), - size: width!.get(context: context, isWidth: true), + BlocBuilder>( + builder: (final context, final state) { + final isLight = + BlocProvider.of(context).state; + PaletteModel? model; + for (final element in state) { + if (element.id == fill.paletteStyle) model = element; + if (element.name == fill.paletteStyle) model = element; + } + return Icon( + MdiIcons.fromString(icon), + color: _getBottomBarItemColor(model, isLight), + size: width!.get(context: context, isWidth: true), + ); + }, ), TextBuilder( textStyle: textStyle, From 1d9380071424e42a4a6176f2e947877c325ba445 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Mon, 2 Jan 2023 13:53:44 +0100 Subject: [PATCH 06/23] feat(drag and drop) --- .../lib/src/elements/bodies/scaffold.dart | 4 +-- .../src/elements/builder/node_selection.dart | 6 ++-- .../elements/builder/placeholder_child.dart | 35 ++++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/teta_widgets/lib/src/elements/bodies/scaffold.dart b/teta_widgets/lib/src/elements/bodies/scaffold.dart index d72870fa..69b620e6 100644 --- a/teta_widgets/lib/src/elements/bodies/scaffold.dart +++ b/teta_widgets/lib/src/elements/bodies/scaffold.dart @@ -74,8 +74,8 @@ class ScaffoldBody extends NodeBody { paletteStyle: 'Background / Primary', ), DBKeys.action: FAction(), - DBKeys.showAppBar: false, - DBKeys.showBottomBar: false, + DBKeys.showAppBar: true, + DBKeys.showBottomBar: true, DBKeys.showDrawer: false, DBKeys.flag: true, }; diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 868d8ad1..2d15a700 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -150,9 +150,11 @@ class _BodyState extends State<_Body> { null || onHover.nid == widget.state.node.nid) Transform.translate( - offset: const Offset( + offset: Offset( 0, - -20, + (key.globalPaintBounds?.top ?? 0) < 100 + ? (key.globalPaintBounds?.height ?? 0) + : -20, ), child: ColoredBox( color: primaryColor, diff --git a/teta_widgets/lib/src/elements/builder/placeholder_child.dart b/teta_widgets/lib/src/elements/builder/placeholder_child.dart index f7c7b435..4be6f8bd 100644 --- a/teta_widgets/lib/src/elements/builder/placeholder_child.dart +++ b/teta_widgets/lib/src/elements/builder/placeholder_child.dart @@ -58,14 +58,33 @@ class _PlaceholderChildBuilderState extends State { }); }, builder: (final context, final candidateData, final rejectedData) { - return TContainer( - width: double.infinity, - height: 24, - decoration: BoxDecoration( - color: - isDragging ? primaryColor.withOpacity(0.3) : Colors.transparent, - border: Border.all( - color: Palette.txtGrey.withOpacity(0.3), + return MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { + BlocProvider.of(context).add( + OnFocus( + node: widget.node, + ), + ); + }, + child: TContainer( + width: double.infinity, + padding: EI.smA, + decoration: BoxDecoration( + color: isDragging + ? primaryColor.withOpacity(0.3) + : Colors.transparent, + border: Border.all( + color: Colors.grey, + ), + ), + child: Center( + child: THeadline3( + 'Add in ${widget.name}', + color: Colors.grey, + ), + ), ), ), ); From 1a6cfbe33a3fabcbd2520e81d759abf2d8c2e1d1 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Mon, 2 Jan 2023 19:17:52 +0100 Subject: [PATCH 07/23] feat(improvements) --- .../src/elements/builder/drag_and_drop.dart | 8 +-- .../src/elements/builder/node_selection.dart | 62 ++++++++++++++----- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart index 3639f389..a8a46003 100644 --- a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -53,7 +53,7 @@ class _DragAndDropBuilderState extends State { parent?.childrenIds.ids.indexOf(widget.state.node.nid); if (currentIndex == null) return; if (parent == null) return; - final id = await NodeRepository.addNodeWithCustomIndex( + await NodeRepository.addNodeWithCustomIndex( node: data.node!, parent: parent!, index: onLeft ?? false ? currentIndex : currentIndex + 1, @@ -64,15 +64,15 @@ class _DragAndDropBuilderState extends State { late bool leftFlag; if (widget.state.isVertical) { leftFlag = details.offset.dy > key.globalPaintBounds!.top && - details.offset.dy <= key.globalPaintBounds!.center.dy; + details.offset.dy <= (key.globalPaintBounds!.height / 2); } else { leftFlag = details.offset.dx > key.globalPaintBounds!.left && - details.offset.dx <= key.globalPaintBounds!.center.dx; + details.offset.dx <= (key.globalPaintBounds!.width / 2); } setState(() { isDragging = true; if (key.globalPaintBounds != null) { - onLeft = !leftFlag; + onLeft = leftFlag; } }); }, diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 2d15a700..9a4cb3c9 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -32,6 +32,7 @@ class NodeSelectionState extends State { Color authorColor = Colors.transparent; String authorNid = ''; CNode? parent; + late Widget child; @override void initState() { @@ -39,17 +40,30 @@ class NodeSelectionState extends State { flatList: BlocProvider.of(context).state.flatList ?? [], element: widget.state.node, ); + child = _Body( + state: widget.state, + child: widget.child, + ); super.initState(); } @override - Widget build(final BuildContext context) { - if (widget.state.forPlay) { - return _Body( + void didUpdateWidget(covariant final NodeSelection oldWidget) { + super.didUpdateWidget(oldWidget); + + if (widget.state != oldWidget.state) { + child = _Body( state: widget.state, child: widget.child, ); } + } + + @override + Widget build(final BuildContext context) { + if (widget.state.forPlay) { + return child; + } return DragAndDropBuilder( state: widget.state, child: MouseRegion( @@ -63,24 +77,23 @@ class NodeSelectionState extends State { } }, child: Listener( - onPointerDown: (final event) { - RightContextMenu.instance.open( - event, - context, - widget.state.node, - ); - }, + onPointerDown: (final event) => RightContextMenu.instance.open( + event, + context, + widget.state.node, + ), child: GestureDetector( onTap: () { - BlocProvider.of(context) - .add(OnFocus(node: widget.state.node)); + if (!BlocProvider.of(context) + .state + .contains(widget.state.node)) { + BlocProvider.of(context) + .add(OnFocus(node: widget.state.node)); + } BlocProvider.of(context) .jumpTo(context, widget.state.node); }, - child: _Body( - state: widget.state, - child: widget.child, - ), + child: child, ), ), ), @@ -104,6 +117,21 @@ class _Body extends StatefulWidget { class _BodyState extends State<_Body> { final key = GlobalKey(); + late Widget child; + + @override + void initState() { + child = widget.child; + super.initState(); + } + + @override + void didUpdateWidget(covariant final _Body oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.child != oldWidget.child) { + child = widget.child; + } + } @override Widget build(final BuildContext context) { @@ -141,7 +169,7 @@ class _BodyState extends State<_Body> { : 0, ), ), - child: widget.child, + child: child, ), if (onFocusNodes.firstWhereOrNull( (final element) => From bcb3da5e6069f7a23ba847bcc599ff826f3e6bbe Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 3 Jan 2023 11:48:17 +0100 Subject: [PATCH 08/23] feat(tree element) --- .../prefabs/sizes_prefab_control.dart | 4 - .../controls/prefabs/text_prefab_control.dart | 18 ---- .../lib/src/elements/controls/type.dart | 83 +------------------ teta_widgets/lib/src/elements/index.dart | 3 + teta_widgets/lib/teta_widgets.dart | 2 + 5 files changed, 7 insertions(+), 103 deletions(-) diff --git a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart index a4207ea6..3e5b52f2 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart @@ -45,8 +45,6 @@ class SizesPrefabControl extends StatelessWidget { isFromSizesPrefab: true, callBack: (final value, final old) { ControlBuilder.toDB( - prj, - page, node, context, DBKeys.width, @@ -63,8 +61,6 @@ class SizesPrefabControl extends StatelessWidget { keyAttr: DBKeys.height, isFromSizesPrefab: true, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, DBKeys.height, diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index 74ed34b5..a461ef86 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -60,8 +60,6 @@ class TextPrefabControl extends StatelessWidget { final old = textStyle; textStyle.textStyleModel = textStyleModel; ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -92,8 +90,6 @@ class TextPrefabControl extends StatelessWidget { textStyle: textStyle, callBack: (final value, final old) { ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -109,8 +105,6 @@ class TextPrefabControl extends StatelessWidget { node: node, textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -125,8 +119,6 @@ class TextPrefabControl extends StatelessWidget { node: node, textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -145,8 +137,6 @@ class TextPrefabControl extends StatelessWidget { textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -171,8 +161,6 @@ class TextPrefabControl extends StatelessWidget { node: node, textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -187,8 +175,6 @@ class TextPrefabControl extends StatelessWidget { node: node, textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -208,8 +194,6 @@ class TextPrefabControl extends StatelessWidget { final old = FTextStyle.fromJson(textStyle.toJson()); textStyle.textDirection = dir; ControlBuilder.toDB( - prj, - page, node, context, keyValue, @@ -231,8 +215,6 @@ class TextPrefabControl extends StatelessWidget { final old = FTextStyle.fromJson(textStyle.toJson()); textStyle.fill = color; ControlBuilder.toDB( - prj, - page, node, context, keyValue, diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index d7411aeb..7f56a6c8 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -24,7 +24,6 @@ import 'package:teta_widgets/src/elements/controls/atoms/cms_collections.dart'; import 'package:teta_widgets/src/elements/controls/atoms/code_field.dart'; import 'package:teta_widgets/src/elements/controls/atoms/cross_axis_alignment.dart'; import 'package:teta_widgets/src/elements/controls/atoms/dataset.dart'; -import 'package:teta_widgets/src/elements/controls/atoms/db_map.dart'; import 'package:teta_widgets/src/elements/controls/atoms/fill.dart'; import 'package:teta_widgets/src/elements/controls/atoms/firebase/path.dart'; import 'package:teta_widgets/src/elements/controls/atoms/flag.dart'; @@ -51,13 +50,11 @@ import 'package:teta_widgets/src/elements/controls/control_model.dart'; import 'package:teta_widgets/src/elements/controls/current_song_controll.dart'; import 'package:teta_widgets/src/elements/controls/google_maps_cubit_control.dart'; import 'package:teta_widgets/src/elements/controls/http_params.dart'; -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; import 'package:teta_widgets/src/elements/controls/prefabs/sizes_prefab_control.dart'; import 'package:teta_widgets/src/elements/controls/prefabs/text_prefab_control.dart'; import 'package:teta_widgets/src/elements/features/google_maps_map_style.dart'; import 'package:teta_widgets/src/elements/features/physic.dart'; import 'package:teta_widgets/src/elements/index.dart'; -import 'package:teta_widgets/src/elements/nodes/dynamic.dart'; import 'package:very_good_analysis/very_good_analysis.dart'; enum ControlType { @@ -184,14 +181,14 @@ enum ControlType { class ControlBuilder { /// It makes a call to NodeRepository.change. static Future toDB( - final ProjectObject prj, - final PageObject page, final CNode node, final BuildContext context, final String key, final dynamic value, final dynamic old, ) async { + final prj = BlocProvider.of(context).state!; + final page = BlocProvider.of(context).state; try { try { final userId = (BlocProvider.of(context).state @@ -308,8 +305,6 @@ class ControlBuilder { : FTextTypeInput(), callBack: (final value, final old) { ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -330,8 +325,6 @@ class ControlBuilder { : FTextTypeInput(), callBack: (final value, final old) { ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -355,8 +348,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = FTextTypeInput(value: value); ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -377,8 +368,6 @@ class ControlBuilder { title: control.title ?? 'Current audio player data set', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -398,8 +387,6 @@ class ControlBuilder { title: control.title ?? 'Audio Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -419,8 +406,6 @@ class ControlBuilder { title: control.title ?? 'Map Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -441,8 +426,6 @@ class ControlBuilder { title: control.title ?? 'Google Maps Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -463,8 +446,6 @@ class ControlBuilder { title: control.title ?? 'Google Maps Cubit', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -485,8 +466,6 @@ class ControlBuilder { title: control.title ?? 'Camera Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -506,8 +485,6 @@ class ControlBuilder { title: control.title ?? 'WebView Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -529,8 +506,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[DBKeys.action] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -551,8 +526,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -573,8 +546,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -593,8 +564,6 @@ class ControlBuilder { node: node, borderRadius: control.value as FBorderRadius, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -612,8 +581,6 @@ class ControlBuilder { node: node, borders: control.value as FBorder, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -630,8 +597,6 @@ class ControlBuilder { page: page, node: node, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -639,8 +604,6 @@ class ControlBuilder { old, ), callBackParameters: (final value) => ControlBuilder.toDB( - prj, - page, node, context, DBKeys.paramsToSend, @@ -658,8 +621,6 @@ class ControlBuilder { node: node, crossAxisAlignment: control.value as FCrossAxisAlignment, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -679,8 +640,6 @@ class ControlBuilder { page: page, image: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -701,8 +660,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -723,8 +680,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -745,8 +700,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -767,8 +720,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -787,8 +738,6 @@ class ControlBuilder { node: node, mainAxisAlignment: control.value as FMainAxisAlignment, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -806,8 +755,6 @@ class ControlBuilder { node: node, mapStyle: control.value as FGoogleMapsMapStyle, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -825,8 +772,6 @@ class ControlBuilder { node: node, size: control.value as FMainAxisSize, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -847,8 +792,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = FMargins.fromJson(value); ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -870,8 +813,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = FMargins.fromJson(value); ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -896,8 +837,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -919,8 +858,6 @@ class ControlBuilder { value: control.value as FDataset, isAttrRequired: control.flag, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -951,8 +888,6 @@ class ControlBuilder { callBack: (final value, final old) => { node.body.attributes[control.key] = value, ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -971,8 +906,6 @@ class ControlBuilder { callBack: (final value, final old) => { node.body.attributes[control.key] = value, ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -992,8 +925,6 @@ class ControlBuilder { node.body.attributes[DBKeys.apiCallsSelectedRequest] = apiCallsSelectedRequest, ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -1047,8 +978,6 @@ class ControlBuilder { key: ValueKey('${node.nid}'), boxFit: control.value, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -1077,8 +1006,6 @@ class ControlBuilder { callBack: (final value, final old) { node.body.attributes[control.key] = value; ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -1114,8 +1041,6 @@ class ControlBuilder { node.body.attributes[control.key] = value; if (!styled) { ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -1148,8 +1073,6 @@ class ControlBuilder { path: control.value, isForAddData: true, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, @@ -1178,8 +1101,6 @@ class ControlBuilder { isFromSizesPrefab: false, keyAttr: control.key, callBack: (final value, final old) => ControlBuilder.toDB( - prj, - page, node, context, control.key, diff --git a/teta_widgets/lib/src/elements/index.dart b/teta_widgets/lib/src/elements/index.dart index fdd86c39..d9888e0a 100644 --- a/teta_widgets/lib/src/elements/index.dart +++ b/teta_widgets/lib/src/elements/index.dart @@ -8,7 +8,10 @@ export './builder/node_selection_builder.dart'; export './builder/placeholder_child.dart'; export './builder/stream_connection.dart'; export './builder/text.dart'; +export './controls/key_constants.dart'; +export './controls/type.dart'; export './features/index.dart'; +export './nodes/children_enum.dart'; export './nodes/dynamic.dart'; export './nodes/enum.dart'; export './nodes/nnull.dart'; diff --git a/teta_widgets/lib/teta_widgets.dart b/teta_widgets/lib/teta_widgets.dart index 6726448a..bda96cfd 100644 --- a/teta_widgets/lib/teta_widgets.dart +++ b/teta_widgets/lib/teta_widgets.dart @@ -1 +1,3 @@ library teta_widgets; + +export './src/elements/index.dart'; From 2b7e4c848fb387a18e2da95c47bf197dd7392d93 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 3 Jan 2023 12:52:10 +0100 Subject: [PATCH 09/23] feat(right bar) --- .../controls/atoms/firebase/path.dart | 7 +- .../prefabs/sizes_prefab_control.dart | 4 - .../lib/src/elements/controls/type.dart | 78 ++++++------------- teta_widgets/lib/src/elements/index.dart | 1 + 4 files changed, 28 insertions(+), 62 deletions(-) diff --git a/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart b/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart index 5c541bf0..6881ad13 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart @@ -3,6 +3,7 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: @@ -12,16 +13,12 @@ import 'package:teta_widgets/src/elements/features/text_type_input.dart'; class FirestorePathControl extends StatefulWidget { const FirestorePathControl({ - required this.prj, - required this.page, required this.path, required this.isForAddData, required this.callBack, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; final FFirestorePath path; final bool isForAddData; final Function(FFirestorePath, FFirestorePath) callBack; @@ -55,7 +52,7 @@ class FirestorePathControlState extends State { children: widget.path.values! .map( (final e) => FirestoreParameterControl( - page: widget.page, + page: BlocProvider.of(context).state, title: widget.path.values!.indexOf(e).isEven ? 'Collection' : 'Doc', diff --git a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart index 3e5b52f2..9948c626 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart @@ -13,15 +13,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SizesPrefabControl extends StatelessWidget { const SizesPrefabControl({ - required this.prj, - required this.page, required this.node, required this.values, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; final CNode node; final List values; diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 7f56a6c8..14e27677 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -220,16 +220,12 @@ class ControlBuilder { /// Returns a control widget based of [control] value. static Widget builder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final ControlModel control, }) { if (control is ControlObject) { return ControlBuilder.genericControlBuilder( - prj: prj, - page: page, node: node, context: context, control: control, @@ -237,8 +233,6 @@ class ControlBuilder { } if (control is FlagControlObject) { return ControlBuilder.flagControlBuilder( - prj: prj, - page: page, node: node, context: context, control: control, @@ -246,8 +240,6 @@ class ControlBuilder { } if (control is FillControlObject) { return ControlBuilder.fillControlBuilder( - prj: prj, - page: page, node: node, isImageEnabled: control.isImageEnabled, isNoneEnabled: control.isNoneEnabled, @@ -258,8 +250,6 @@ class ControlBuilder { } if (control is SizeControlObject) { return ControlBuilder.sizeControlBuilder( - prj: prj, - page: page, node: node, context: context, control: control, @@ -267,8 +257,6 @@ class ControlBuilder { } if (control is SizesControlObject) { return ControlBuilder.sizesControlBuilder( - prj: prj, - page: page, node: node, context: context, control: control, @@ -276,8 +264,6 @@ class ControlBuilder { } if (control is BoxFitControlObject) { return ControlBuilder.boxFitControlBuilder( - prj: prj, - page: page, node: node, context: context, control: control, @@ -288,8 +274,6 @@ class ControlBuilder { /// Returns a control widget based on control.type. static Widget genericControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final ControlObject control, @@ -364,7 +348,7 @@ class ControlBuilder { control: CurrentSongControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Current audio player data set', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -383,7 +367,7 @@ class ControlBuilder { control: AudioControllerControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Audio Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -402,7 +386,7 @@ class ControlBuilder { control: MapControllerControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Map Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -422,7 +406,7 @@ class ControlBuilder { control: GoogleMapsControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Google Maps Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -442,7 +426,7 @@ class ControlBuilder { control: GoogleMapsCubitControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Google Maps Cubit', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -462,7 +446,7 @@ class ControlBuilder { control: CameraControllerControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Camera Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -481,7 +465,7 @@ class ControlBuilder { control: WebViewControllerControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'WebView Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -499,8 +483,8 @@ class ControlBuilder { description: control.description, control: ActionControl( key: ValueKey('${node.nid}'), - prj: prj, - page: page, + prj: BlocProvider.of(context).state!, + page: BlocProvider.of(context).state, node: node, action: control.value as FAction, callBack: (final value, final old) { @@ -593,8 +577,8 @@ class ControlBuilder { if (control.type == ControlType.component) { return ComponentControl( key: ValueKey('${node.nid}'), - prj: prj, - page: page, + prj: BlocProvider.of(context).state!, + page: BlocProvider.of(context).state, node: node, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -637,7 +621,7 @@ class ControlBuilder { key: ValueKey('${node.nid}'), title: 'Image', node: node, - page: page, + page: BlocProvider.of(context).state, image: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -831,7 +815,7 @@ class ControlBuilder { key: ValueKey('${node.nid}'), valueType: control.valueType, node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'Value', value: control.value as FTextTypeInput, callBack: (final value, final old) { @@ -853,7 +837,7 @@ class ControlBuilder { control: DatasetControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title ?? 'From', value: control.value as FDataset, isAttrRequired: control.flag, @@ -872,8 +856,8 @@ class ControlBuilder { title: control.title, key: ValueKey('${node.nid}'), node: node, - page: page, - prj: prj, + prj: BlocProvider.of(context).state!, + page: BlocProvider.of(context).state, textStyle: control.value as FTextStyle, keyValue: control.key, ); @@ -882,7 +866,7 @@ class ControlBuilder { return HttpParamsControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, title: control.title, list: control.value as List, callBack: (final value, final old) => { @@ -940,9 +924,11 @@ class ControlBuilder { control: PageParamsControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, callBack: (final list) async { - await ProjectRepository.updatePage(page); + await ProjectRepository.updatePage( + BlocProvider.of(context).state, + ); BlocProvider.of(context).change(); }, ), @@ -954,9 +940,11 @@ class ControlBuilder { control: StatesControl( key: ValueKey('${node.nid}'), node: node, - page: page, + page: BlocProvider.of(context).state, callBack: (final list) async { - await ProjectRepository.updatePage(page); + await ProjectRepository.updatePage( + BlocProvider.of(context).state, + ); BlocProvider.of(context).change(); }, ), @@ -968,8 +956,6 @@ class ControlBuilder { /// Returns a BoxFitControl widget. static BoxFitControl boxFitControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final BoxFitControlObject control, @@ -989,8 +975,6 @@ class ControlBuilder { /// Returns a FlagControl widget. static Widget flagControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final FlagControlObject control, @@ -1019,8 +1003,6 @@ class ControlBuilder { /// Returns a FillControl. static FillControl fillControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final bool isImageEnabled, required final bool isNoneEnabled, @@ -1060,16 +1042,12 @@ class ControlBuilder { /// Returns a FirestorePathControl. static FirestorePathControl firebasePathControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final FirestorePathControlObject control, }) { return FirestorePathControl( key: ValueKey('${node.nid}'), - prj: prj, - page: page, path: control.value, isForAddData: true, callBack: (final value, final old) => ControlBuilder.toDB( @@ -1086,8 +1064,6 @@ class ControlBuilder { /// /// This is used for width or height, not both. static SizeControl sizeControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final SizeControlObject control, @@ -1114,16 +1090,12 @@ class ControlBuilder { /// /// This is used for width and height together. static Widget sizesControlBuilder({ - required final ProjectObject prj, - required final PageObject page, required final CNode node, required final BuildContext context, required final SizesControlObject control, }) { return SizesPrefabControl( key: ValueKey('${node.nid}'), - prj: prj, - page: page, node: node, values: control.values, ); diff --git a/teta_widgets/lib/src/elements/index.dart b/teta_widgets/lib/src/elements/index.dart index d9888e0a..a23d6020 100644 --- a/teta_widgets/lib/src/elements/index.dart +++ b/teta_widgets/lib/src/elements/index.dart @@ -8,6 +8,7 @@ export './builder/node_selection_builder.dart'; export './builder/placeholder_child.dart'; export './builder/stream_connection.dart'; export './builder/text.dart'; +export './controls/control_model.dart'; export './controls/key_constants.dart'; export './controls/type.dart'; export './features/index.dart'; From 025d5d0c266ef307f875adc4f8241f4825eeea22 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 3 Jan 2023 15:12:13 +0100 Subject: [PATCH 10/23] feat(parameters) --- .../src/elements/controls/atoms/barcode.dart | 4 +- .../lib/src/elements/controls/type.dart | 61 ++++++++----------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/teta_widgets/lib/src/elements/controls/atoms/barcode.dart b/teta_widgets/lib/src/elements/controls/atoms/barcode.dart index 8f426a99..4bea985f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/barcode.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/barcode.dart @@ -13,13 +13,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class BarcodeControl extends StatefulWidget { const BarcodeControl({ - required this.node, required this.value, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; final Function(FTextTypeInput, FTextTypeInput) callBack; @@ -33,7 +31,7 @@ class BarcodeControlState extends State { @override void initState() { - nodeId = widget.node.nid; + nodeId = BlocProvider.of(context).state.first.nid; super.initState(); } diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 14e27677..f173f78f 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -46,7 +46,6 @@ import 'package:teta_widgets/src/elements/controls/atoms/src_image.dart'; import 'package:teta_widgets/src/elements/controls/atoms/states.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; import 'package:teta_widgets/src/elements/controls/atoms/webview_controller.dart'; -import 'package:teta_widgets/src/elements/controls/control_model.dart'; import 'package:teta_widgets/src/elements/controls/current_song_controll.dart'; import 'package:teta_widgets/src/elements/controls/google_maps_cubit_control.dart'; import 'package:teta_widgets/src/elements/controls/http_params.dart'; @@ -220,27 +219,23 @@ class ControlBuilder { /// Returns a control widget based of [control] value. static Widget builder({ - required final CNode node, required final BuildContext context, required final ControlModel control, }) { if (control is ControlObject) { return ControlBuilder.genericControlBuilder( - node: node, context: context, control: control, ); } if (control is FlagControlObject) { return ControlBuilder.flagControlBuilder( - node: node, context: context, control: control, ); } if (control is FillControlObject) { return ControlBuilder.fillControlBuilder( - node: node, isImageEnabled: control.isImageEnabled, isNoneEnabled: control.isNoneEnabled, isOnlySolid: control.isOnlySolid, @@ -250,21 +245,18 @@ class ControlBuilder { } if (control is SizeControlObject) { return ControlBuilder.sizeControlBuilder( - node: node, context: context, control: control, ); } if (control is SizesControlObject) { return ControlBuilder.sizesControlBuilder( - node: node, context: context, control: control, ); } if (control is BoxFitControlObject) { return ControlBuilder.boxFitControlBuilder( - node: node, context: context, control: control, ); @@ -274,13 +266,12 @@ class ControlBuilder { /// Returns a control widget based on control.type. static Widget genericControlBuilder({ - required final CNode node, required final BuildContext context, required final ControlObject control, }) { + final node = BlocProvider.of(context).state.first; if (control.type == ControlType.barcode) { return BarcodeControl( - node: node, key: ValueKey( '${node.nid} ${(control.value as FTextTypeInput).value}', ), @@ -289,7 +280,7 @@ class ControlBuilder { : FTextTypeInput(), callBack: (final value, final old) { ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value.toJson(), @@ -956,15 +947,14 @@ class ControlBuilder { /// Returns a BoxFitControl widget. static BoxFitControl boxFitControlBuilder({ - required final CNode node, required final BuildContext context, required final BoxFitControlObject control, }) { return BoxFitControl( - key: ValueKey('${node.nid}'), + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), boxFit: control.value, callBack: (final value, final old) => ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value, @@ -975,22 +965,25 @@ class ControlBuilder { /// Returns a FlagControl widget. static Widget flagControlBuilder({ - required final CNode node, required final BuildContext context, required final FlagControlObject control, }) { return descriptionControlWidget( description: control.description, control: FlagControl( - key: ValueKey('${node.nid}'), + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), title: control.title, - node: node as NDynamic, + node: BlocProvider.of(context).state.first as NDynamic, keyValue: control.key, value: control.value as bool, callBack: (final value, final old) { - node.body.attributes[control.key] = value; + BlocProvider.of(context) + .state + .first + .body + .attributes[control.key] = value; ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value, @@ -1003,7 +996,6 @@ class ControlBuilder { /// Returns a FillControl. static FillControl fillControlBuilder({ - required final CNode node, required final bool isImageEnabled, required final bool isNoneEnabled, required final bool isOnlySolid, @@ -1012,18 +1004,22 @@ class ControlBuilder { }) { return FillControl( title: control.title.isNotEmpty ? control.title : 'Fill', - key: ValueKey('${node.nid}'), - node: node, + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + node: BlocProvider.of(context).state.first, isImageEnabled: isImageEnabled, isNoneEnabled: isNoneEnabled, type: isOnlySolid ? FillTypeControlType.onlySolid : FillTypeControlType.all, fill: control.value, callBack: (final value, final styled, final old) { - node.body.attributes[control.key] = value; + BlocProvider.of(context) + .state + .first + .body + .attributes[control.key] = value; if (!styled) { ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value.toJson(), @@ -1042,16 +1038,15 @@ class ControlBuilder { /// Returns a FirestorePathControl. static FirestorePathControl firebasePathControlBuilder({ - required final CNode node, required final BuildContext context, required final FirestorePathControlObject control, }) { return FirestorePathControl( - key: ValueKey('${node.nid}'), + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), path: control.value, isForAddData: true, callBack: (final value, final old) => ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value.toJson(), @@ -1064,20 +1059,19 @@ class ControlBuilder { /// /// This is used for width or height, not both. static SizeControl sizeControlBuilder({ - required final CNode node, required final BuildContext context, required final SizeControlObject control, }) { return SizeControl( - key: ValueKey('${node.nid}'), - node: node, + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + node: BlocProvider.of(context).state.first, isWidth: control.isWidth, title: control.title, size: control.value, isFromSizesPrefab: false, keyAttr: control.key, callBack: (final value, final old) => ControlBuilder.toDB( - node, + BlocProvider.of(context).state.first, context, control.key, value, @@ -1090,13 +1084,12 @@ class ControlBuilder { /// /// This is used for width and height together. static Widget sizesControlBuilder({ - required final CNode node, required final BuildContext context, required final SizesControlObject control, }) { return SizesPrefabControl( - key: ValueKey('${node.nid}'), - node: node, + key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + node: BlocProvider.of(context).state.first, values: control.values, ); } From 608425bc03f9ff0390932204ab36f2655f8c7bd9 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 3 Jan 2023 17:09:07 +0100 Subject: [PATCH 11/23] fea(icons and undo system) --- .../lib/src/elements/bodies/navigation/appbar.dart | 7 +------ .../src/elements/controls/atoms/action_element.dart | 10 +--------- teta_widgets/lib/src/elements/controls/type.dart | 7 +------ teta_widgets/lib/src/elements/widgets/text.dart | 10 +--------- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart index e4ea3f9d..4cf89681 100644 --- a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart +++ b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart @@ -61,13 +61,8 @@ class AppBarBody extends NodeBody { description: 'Automatic AppBar is the default AppBar', networkImage: '', onTap: () { - NodeRepository.change( - nodeId: page.scaffold!.nid, + NodeRepository.changeNode( node: page.scaffold! as NDynamic, - pageId: page.id, - key: DBKeys.showAppBar, - value: true, - old: page.scaffold!.body.attributes[DBKeys.showAppBar] as bool, ); page.scaffold!.body.attributes[DBKeys.showAppBar] = true; }, diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index 2d78bcc0..898eef7a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -40,7 +40,6 @@ import 'package:teta_widgets/src/elements/controls/atoms/teta_cms/delete.dart'; import 'package:teta_widgets/src/elements/controls/atoms/teta_cms/insert.dart'; import 'package:teta_widgets/src/elements/controls/atoms/teta_cms/update.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; -import 'package:teta_widgets/src/elements/controls/type.dart'; import 'package:teta_widgets/src/elements/features/actions/enums/action_google_maps.dart'; import 'package:teta_widgets/src/elements/features/actions/enums/airtable.dart'; import 'package:teta_widgets/src/elements/features/actions/enums/apicalls.dart'; @@ -2025,15 +2024,8 @@ class ActionElementControlState extends State { } if (flag) { - NodeRepository.change( - nodeId: widget.page.scaffold!.nid, + NodeRepository.changeNode( node: widget.page.scaffold! as NDynamic, - pageId: widget.page.id, - key: 'states', - value: widget.page.states - .map((final e) => e.toJson()) - .toList(), - old: null, ); } BlocProvider.of(context) diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index f173f78f..0254d401 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -199,13 +199,8 @@ class ControlBuilder { Logger.printError('Error tracking generic project update, error: $e'); } unawaited( - NodeRepository.change( - nodeId: node.nid, + NodeRepository.changeNode( node: node as NDynamic, - pageId: page.id, - key: key, - value: value, - old: old, ), ); BlocProvider.of(context).change(); diff --git a/teta_widgets/lib/src/elements/widgets/text.dart b/teta_widgets/lib/src/elements/widgets/text.dart index 06aa3029..31028cae 100644 --- a/teta_widgets/lib/src/elements/widgets/text.dart +++ b/teta_widgets/lib/src/elements/widgets/text.dart @@ -9,7 +9,6 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_repositories/src/node_repository.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; import 'package:teta_widgets/src/elements/builder/gesture_detector_base.dart'; -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -215,15 +214,8 @@ class _WTextState extends State { widget.state.node.body.attributes[DBKeys.value] = FTextTypeInput( value: text, ); - NodeRepository.change( - nodeId: widget.state.node.nid, + NodeRepository.changeNode( node: widget.state.node as NDynamic, - pageId: BlocProvider.of(context).state.id, - key: DBKeys.value, - value: FTextTypeInput( - value: text, - ).toJson(), - old: null, ); BlocProvider.of(context).change(); } From 8e29de10260b753658e5d437fe95d160916ac149 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Sat, 14 Jan 2023 21:30:29 +0100 Subject: [PATCH 12/23] feat(minor improving) --- .../src/elements/actions/airtable/delete.dart | 2 +- .../src/elements/actions/airtable/insert.dart | 3 +- .../src/elements/actions/airtable/update.dart | 48 +++++++++---------- .../src/elements/builder/node_selection.dart | 47 ++++++++---------- .../templates/airtable/airtable_fetch.dart | 4 -- .../controls/atoms/navigation/component.dart | 8 +--- .../elements/controls/atoms/src_image.dart | 2 +- .../elements/controls/atoms/text_styles.dart | 2 +- teta_widgets/lib/src/elements/nodes/node.dart | 1 - .../src/elements/widgets/airtable/fetch.dart | 2 +- 10 files changed, 50 insertions(+), 69 deletions(-) diff --git a/teta_widgets/lib/src/elements/actions/airtable/delete.dart b/teta_widgets/lib/src/elements/actions/airtable/delete.dart index 28b43724..02bb709b 100644 --- a/teta_widgets/lib/src/elements/actions/airtable/delete.dart +++ b/teta_widgets/lib/src/elements/actions/airtable/delete.dart @@ -1,7 +1,7 @@ import 'package:dart_airtable/dart_airtable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/airtable.dart'; +import 'package:teta_core/src/cubits/airtable.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; diff --git a/teta_widgets/lib/src/elements/actions/airtable/insert.dart b/teta_widgets/lib/src/elements/actions/airtable/insert.dart index 38d11e36..275eb419 100644 --- a/teta_widgets/lib/src/elements/actions/airtable/insert.dart +++ b/teta_widgets/lib/src/elements/actions/airtable/insert.dart @@ -1,7 +1,7 @@ import 'package:dart_airtable/dart_airtable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/airtable.dart'; +import 'package:teta_core/src/cubits/airtable.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; @@ -35,6 +35,7 @@ class FAAirtableInsert { ); await airtableCubit.insert(recordName: recordName, record: record); + return null; } static String toCode( diff --git a/teta_widgets/lib/src/elements/actions/airtable/update.dart b/teta_widgets/lib/src/elements/actions/airtable/update.dart index 990bc24e..85941e48 100644 --- a/teta_widgets/lib/src/elements/actions/airtable/update.dart +++ b/teta_widgets/lib/src/elements/actions/airtable/update.dart @@ -1,60 +1,60 @@ import 'package:dart_airtable/dart_airtable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/airtable.dart'; +import 'package:teta_core/src/cubits/airtable.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; class FAAirtableUpdate { static Future action( - final BuildContext context, - final FTextTypeInput? airtableRecordName, - final List airtableData, - final List params, - final List states, - final List dataset, - final int? loop, + final BuildContext context, + final FTextTypeInput? airtableRecordName, + final List airtableData, + final List params, + final List states, + final List dataset, + final int? loop, ) async { final airtableCubit = BlocProvider.of(context); final recordName = airtableRecordName?.get( - params, - states, - dataset, - false, - loop, - context, - ) ?? + params, + states, + dataset, + false, + loop, + context, + ) ?? ''; final record = AirtableRecord( fields: airtableData .map( (final e) => AirtableRecordField(fieldName: e.key, value: e.value), - ) + ) .toList(), ); await airtableCubit.update(recordName: recordName, record: record); - } static String toCode( - final BuildContext context, - final FTextTypeInput? airtableRecordName, - final List airtableData,) { + final BuildContext context, + final FTextTypeInput? airtableRecordName, + final List airtableData, + ) { final record = AirtableRecord( fields: airtableData .map( (final e) => AirtableRecordField(fieldName: e.key, value: e.value), - ) + ) .toList(), ); return ''' context.read().update(recordName: ${airtableRecordName?.toCode( - 0, - resultType: ResultTypeEnum.string, - ) ?? ''}, record: $record) + 0, + resultType: ResultTypeEnum.string, + ) ?? ''}, record: $record) '''; } } diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 9a4cb3c9..aa2430fb 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -28,42 +28,29 @@ class NodeSelection extends StatefulWidget { } class NodeSelectionState extends State { - bool isSelectFromOtherAuthors = false; - Color authorColor = Colors.transparent; - String authorNid = ''; - CNode? parent; - late Widget child; + List parents = []; @override void initState() { - parent = FindNodeRendering.findParentByChildrenIds( - flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.state.node, - ); - child = _Body( - state: widget.state, - child: widget.child, - ); + do { + parents.add( + FindNodeRendering.findParentByChildrenIds( + flatList: BlocProvider.of(context).state.flatList ?? [], + element: widget.state.node, + ), + ); + } while (parents.isEmpty); super.initState(); } @override - void didUpdateWidget(covariant final NodeSelection oldWidget) { - super.didUpdateWidget(oldWidget); - - if (widget.state != oldWidget.state) { - child = _Body( + Widget build(final BuildContext context) { + if (widget.state.forPlay) { + return _Body( state: widget.state, child: widget.child, ); } - } - - @override - Widget build(final BuildContext context) { - if (widget.state.forPlay) { - return child; - } return DragAndDropBuilder( state: widget.state, child: MouseRegion( @@ -72,8 +59,9 @@ class NodeSelectionState extends State { .add(OnHover(node: widget.state.node)); }, onExit: (final e) { - if (parent != null) { - BlocProvider.of(context).add(OnHover(node: parent!)); + if (parents.firstOrNull != null) { + BlocProvider.of(context) + .add(OnHover(node: parents.firstOrNull!)); } }, child: Listener( @@ -93,7 +81,10 @@ class NodeSelectionState extends State { BlocProvider.of(context) .jumpTo(context, widget.state.node); }, - child: child, + child: _Body( + state: widget.state, + child: widget.child, + ), ), ), ), diff --git a/teta_widgets/lib/src/elements/code/templates/airtable/airtable_fetch.dart b/teta_widgets/lib/src/elements/code/templates/airtable/airtable_fetch.dart index 76b4e284..2263c9de 100644 --- a/teta_widgets/lib/src/elements/code/templates/airtable/airtable_fetch.dart +++ b/teta_widgets/lib/src/elements/code/templates/airtable/airtable_fetch.dart @@ -1,11 +1,7 @@ // Flutter imports: import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:teta_cms/teta_cms.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/airtable.dart'; import 'package:teta_widgets/src/elements/code/formatter_test.dart'; - // Project imports: import 'package:teta_widgets/src/elements/controls/key_constants.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; diff --git a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart index a0d064b7..126c708e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart @@ -132,12 +132,6 @@ class ComponentControlState extends State { callBackParameters: (final map) { widget.node.body .attributes[DBKeys.paramsToSend] = map; - Logger.printMessage( - 'paramsToSend: ${widget.node.body.attributes[DBKeys.paramsToSend]}', - ); - Logger.printMessage( - 'paramsToSend variable.id: ${widget.node.body.attributes[DBKeys.paramsToSend][variable.id]}', - ); widget.callBackParameters(map); }, ), @@ -206,7 +200,7 @@ class ElementState extends State { @override void initState() { super.initState(); - Logger.printMessage('${widget.page.datasets}'); + Logger.printMessage('Datasets: ${widget.page.datasets}'); Logger.printMessage('Params: ${widget.page.params}'); final params = Map.fromEntries( widget.page.params diff --git a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart index fedcc13c..e483c5b6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart @@ -7,8 +7,8 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:supabase/supabase.dart'; +import 'package:teta_core/src/cubits/panels/cubit.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/panels/cubit.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart index 9f447a3d..28f9162c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart @@ -7,8 +7,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hovering/hovering.dart'; +import 'package:teta_core/src/cubits/panels/cubit.dart'; import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; -import 'package:teta_core/src/pages/editor_page/cubits/panels/cubit.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_style.dart'; diff --git a/teta_widgets/lib/src/elements/nodes/node.dart b/teta_widgets/lib/src/elements/nodes/node.dart index e1ca4672..4a767e72 100644 --- a/teta_widgets/lib/src/elements/nodes/node.dart +++ b/teta_widgets/lib/src/elements/nodes/node.dart @@ -156,7 +156,6 @@ abstract class CNode extends Equatable { /// Instantiate new node by display name static CNode toNodeFromName( final String displayName, - final BuildContext context, ) { final enumType = NodeType.fromStringCamelCase(displayName); return NDynamic( diff --git a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart index 1ab6bd79..8ccbb79a 100644 --- a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart @@ -7,7 +7,7 @@ import 'package:dart_airtable/dart_airtable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; // Package imports: -import 'package:teta_core/src/pages/editor_page/cubits/airtable.dart'; +import 'package:teta_core/src/cubits/airtable.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; // Project imports: From 42db2d934bdbda3e5da7debe99d200ab5e520095 Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Sun, 15 Jan 2023 16:24:53 +0100 Subject: [PATCH 13/23] feaTrefactoring) --- .../actions/navigation/open_bottom_sheet.dart | 4 +-- .../actions/navigation/open_page.dart | 8 ++--- .../actions/navigation/open_snack.dart | 4 +-- .../src/elements/actions/snippets/update.dart | 6 +--- .../elements/bodies/navigation/appbar.dart | 6 ++-- .../src/elements/builder/drag_and_drop.dart | 21 ++++++------ .../src/elements/builder/node_selection.dart | 9 ++--- .../elements/builder/placeholder_child.dart | 12 +++---- .../elements/builder/reorder_children.dart | 7 ++-- .../lib/src/elements/builder/text.dart | 2 +- .../lib/src/elements/code/formatter_test.dart | 2 +- .../controls/atoms/action_element.dart | 9 +++-- .../src/elements/controls/atoms/delete.dart | 27 ++++++++------- .../lib/src/elements/controls/atoms/fill.dart | 6 ++-- .../elements/controls/atoms/fill/asset.dart | 2 +- .../elements/controls/atoms/fill/style.dart | 6 ++-- .../atoms/google_maps_map_style_controls.dart | 1 - .../elements/controls/atoms/src_image.dart | 1 - .../elements/controls/atoms/text_styles.dart | 14 ++++---- .../controls/prefabs/text_prefab_control.dart | 31 +++++++++-------- .../lib/src/elements/controls/type.dart | 33 +++++++++---------- .../lib/src/elements/features/fill.dart | 6 ++-- .../lib/src/elements/widgets/badge.dart | 4 +-- .../src/elements/widgets/bottombaritem.dart | 6 ++-- .../lib/src/elements/widgets/card.dart | 4 +-- .../widgets/circular_progress_indicator.dart | 7 ++-- .../lib/src/elements/widgets/component.dart | 8 ++--- .../widgets/concentric_page_view.dart | 9 +++-- .../lib/src/elements/widgets/divider.dart | 4 +-- .../lib/src/elements/widgets/icon.dart | 4 +-- .../src/elements/widgets/icon_feather.dart | 4 +-- .../elements/widgets/icon_font_awesome.dart | 4 +-- .../lib/src/elements/widgets/icon_line.dart | 4 +-- .../lib/src/elements/widgets/placeholder.dart | 5 +-- .../widgets/shopify/shopify_login.dart | 6 ++-- .../widgets/shopify/shopify_registration.dart | 6 ++-- .../lib/src/elements/widgets/text.dart | 9 +++-- .../src/elements/widgets/w_audio_player.dart | 23 ++++++++----- 38 files changed, 167 insertions(+), 157 deletions(-) diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart index 9d821d65..d8715781 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart @@ -10,7 +10,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:recase/recase.dart'; -import 'package:teta_core/src/rendering/nodes_original.dart'; +import 'package:teta_core/src/rendering/nodes.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_db/teta_db.dart'; // Project imports: @@ -54,7 +54,7 @@ class FActionNavigationOpenBottomSheet { ), ); } - final scaffold = NodeRendering.renderTree(nodes); + final scaffold = sl.get().renderTree(nodes); page = page.copyWith(flatList: nodes, scaffold: scaffold); await showModalBottomSheet( context: context, diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart index a0b5d46c..a6c1a1da 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart @@ -10,7 +10,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:recase/recase.dart'; -import 'package:teta_core/src/rendering/nodes_original.dart'; +import 'package:teta_core/src/rendering/nodes.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_db/teta_db.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; @@ -79,7 +79,7 @@ class FActionNavigationOpenPage { ), ); } - final scaffold = NodeRendering.renderTree(nodes); + final scaffold = sl.get().renderTree(nodes); page = page.copyWith(flatList: nodes, scaffold: scaffold); BlocProvider.of(context) @@ -89,8 +89,8 @@ class FActionNavigationOpenPage { context, MaterialPageRoute( builder: (final context) => BlocProvider( - create: (final context) => - PageCubit()..onFocus(prj: prj, page: page!, context: context), + create: (final context) => PageCubit(sl.get()) + ..onFocus(prj: prj, page: page!, context: context), child: page!.scaffold!.toWidget( state: state.copyWith( forPlay: true, diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart index a53713de..ed50e459 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:recase/recase.dart'; -import 'package:teta_core/src/rendering/nodes_original.dart'; +import 'package:teta_core/src/rendering/nodes.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_db/teta_db.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; @@ -52,7 +52,7 @@ class FActionNavigationOpenSnackBar { ), ); } - final scaffold = NodeRendering.renderTree(nodes); + final scaffold = sl.get().renderTree(nodes); page = page.copyWith(flatList: nodes, scaffold: scaffold); final snackBar = SnackBar( content: page.scaffold!.toWidget( diff --git a/teta_widgets/lib/src/elements/actions/snippets/update.dart b/teta_widgets/lib/src/elements/actions/snippets/update.dart index f399b974..d8045d70 100644 --- a/teta_widgets/lib/src/elements/actions/snippets/update.dart +++ b/teta_widgets/lib/src/elements/actions/snippets/update.dart @@ -1,10 +1,6 @@ // Flutter imports: import 'package:flutter/material.dart'; // Package imports: -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:teta_core/teta_core.dart'; /// Refreshes the changes rebuild the scaffold -void update(final BuildContext context) { - BlocProvider.of(context).change(); -} +void update(final BuildContext context) {} diff --git a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart index 4cf89681..8c373d13 100644 --- a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart +++ b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart @@ -61,9 +61,9 @@ class AppBarBody extends NodeBody { description: 'Automatic AppBar is the default AppBar', networkImage: '', onTap: () { - NodeRepository.changeNode( - node: page.scaffold! as NDynamic, - ); + sl.get().changeNode( + node: page.scaffold! as NDynamic, + ); page.scaffold!.body.attributes[DBKeys.showAppBar] = true; }, ) diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart index a8a46003..6899bc07 100644 --- a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -29,10 +29,11 @@ class _DragAndDropBuilderState extends State { @override void initState() { - parent = FindNodeRendering.findParentByChildrenIds( - flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.state.node, - ); + parent = sl.get().findParentByChildrenIds( + flatList: + BlocProvider.of(context).state.flatList ?? [], + element: widget.state.node, + ); canReceiveDrag = parent?.globalType == NType.row || parent?.globalType == NType.column || parent?.globalType == NType.listView; @@ -53,12 +54,12 @@ class _DragAndDropBuilderState extends State { parent?.childrenIds.ids.indexOf(widget.state.node.nid); if (currentIndex == null) return; if (parent == null) return; - await NodeRepository.addNodeWithCustomIndex( - node: data.node!, - parent: parent!, - index: onLeft ?? false ? currentIndex : currentIndex + 1, - pageId: BlocProvider.of(context).state.id, - ); + await sl.get().addNodeWithCustomIndex( + node: data.node!, + parent: parent!, + index: onLeft ?? false ? currentIndex : currentIndex + 1, + pageId: BlocProvider.of(context).state.id, + ); }, onMove: (final details) { late bool leftFlag; diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index aa2430fb..322cedc4 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -34,10 +34,11 @@ class NodeSelectionState extends State { void initState() { do { parents.add( - FindNodeRendering.findParentByChildrenIds( - flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.state.node, - ), + sl.get().findParentByChildrenIds( + flatList: + BlocProvider.of(context).state.flatList ?? [], + element: widget.state.node, + ), ); } while (parents.isEmpty); super.initState(); diff --git a/teta_widgets/lib/src/elements/builder/placeholder_child.dart b/teta_widgets/lib/src/elements/builder/placeholder_child.dart index 4be6f8bd..e8cf5bd5 100644 --- a/teta_widgets/lib/src/elements/builder/placeholder_child.dart +++ b/teta_widgets/lib/src/elements/builder/placeholder_child.dart @@ -40,12 +40,12 @@ class _PlaceholderChildBuilderState extends State { isDragging = true; }); - final id = await NodeRepository.addNodeWithCustomIndex( - node: data.node!, - parent: widget.node, - index: 0, - pageId: BlocProvider.of(context).state.id, - ); + await sl.get().addNodeWithCustomIndex( + node: data.node!, + parent: widget.node, + index: 0, + pageId: BlocProvider.of(context).state.id, + ); }, onMove: (final details) { setState(() { diff --git a/teta_widgets/lib/src/elements/builder/reorder_children.dart b/teta_widgets/lib/src/elements/builder/reorder_children.dart index 773474b5..14242b92 100644 --- a/teta_widgets/lib/src/elements/builder/reorder_children.dart +++ b/teta_widgets/lib/src/elements/builder/reorder_children.dart @@ -1,3 +1,4 @@ +import 'package:teta_core/get_it.dart'; import 'package:teta_repositories/teta_repositories.dart'; import 'package:teta_widgets/src/elements/index.dart'; @@ -12,8 +13,8 @@ class ReorderChildren { children.insert(newIndex, child); final id = node.childrenIds.ids.removeAt(oldIndex); node.childrenIds.ids.insert(newIndex, id); - NodeRepository.changeNode( - node: node, - ); + sl.get().changeNode( + node: node, + ); } } diff --git a/teta_widgets/lib/src/elements/builder/text.dart b/teta_widgets/lib/src/elements/builder/text.dart index 8742651a..db7c26ac 100644 --- a/teta_widgets/lib/src/elements/builder/text.dart +++ b/teta_widgets/lib/src/elements/builder/text.dart @@ -43,7 +43,7 @@ class TextBuilder extends StatelessWidget { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { FFill? finalFill; diff --git a/teta_widgets/lib/src/elements/code/formatter_test.dart b/teta_widgets/lib/src/elements/code/formatter_test.dart index 4765c511..ee01af91 100644 --- a/teta_widgets/lib/src/elements/code/formatter_test.dart +++ b/teta_widgets/lib/src/elements/code/formatter_test.dart @@ -23,7 +23,7 @@ class Test extends StatelessWidget { Logger.printError('Error formating: $e'); } if (result = false) { - ProjectRepository.sendToCodeError(code); + sl.get().sendToCodeError(code); } return result; } diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index 898eef7a..d1e4030d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -2024,14 +2024,13 @@ class ActionElementControlState extends State { } if (flag) { - NodeRepository.changeNode( - node: widget.page.scaffold! as NDynamic, - ); + sl.get().changeNode( + node: + widget.page.scaffold! as NDynamic, + ); } BlocProvider.of(context) .add(OnFocus(node: widget.node)); - BlocProvider.of(context) - .change(); }, child: Container( padding: const EdgeInsets.all(8), diff --git a/teta_widgets/lib/src/elements/controls/atoms/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/delete.dart index 5ca2eff0..09b5f433 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/delete.dart @@ -34,10 +34,10 @@ class DeleteControlState extends State { @override Widget build(final BuildContext context) { height = MediaQuery.of(context).size.height; - final parentOfNode = FindNodeRendering.findParentByChildrenIds( - flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.node, - ); + final parentOfNode = sl.get().findParentByChildrenIds( + flatList: BlocProvider.of(context).state.flatList ?? [], + element: widget.node, + ); final prj = BlocProvider.of(context).state!; final pageState = BlocProvider.of(context).state; if (widget.node.intrinsicState.canHave == @@ -58,14 +58,17 @@ class DeleteControlState extends State { padding: const EdgeInsets.only(top: 8), child: CDangerousButton( label: 'Delete node', - callback: () async => NodeRepository().removeNodeBetweenNodes( - context: context, - nodes: - BlocProvider.of(context).state.flatList ?? [], - node: widget.node as NDynamic, - prj: prj, - page: pageState, - ), + callback: () async => + sl.get().removeNodeBetweenNodes( + context: context, + nodes: BlocProvider.of(context) + .state + .flatList ?? + [], + node: widget.node as NDynamic, + prj: prj, + page: pageState, + ), ), ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill.dart b/teta_widgets/lib/src/elements/controls/atoms/fill.dart index 6d8f773d..bea9c7bf 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill.dart @@ -53,7 +53,7 @@ class FillControlState extends State { Widget build(final BuildContext context) { return Padding( padding: const EdgeInsets.only(left: 4), - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { list = BlocProvider.of(context).state.isNotEmpty ? widget.isImageEnabled @@ -172,9 +172,9 @@ class FillControlState extends State { } Widget control(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { - PaletteModel? model; + ColorStyleModel? model; if (widget.fill.paletteStyle != null) { BlocProvider.of(context) .state diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart index 585e8447..9fca2420 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart @@ -63,7 +63,7 @@ class AssetFillControlState extends State { value: widget.fill.file, items: list, onChange: (final value) { - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context) .state .forEach((final element) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart index 50b5e371..a5d7b92a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart @@ -23,7 +23,7 @@ class StyleFillControl extends StatefulWidget { final bool onlySolid; final CNode node; - final PaletteModel model; + final ColorStyleModel model; final FFill fill; final Function(FFill, bool, FFill) callBack; @@ -37,7 +37,7 @@ class StyleFillControlState extends State { return BlocBuilder>( builder: (final context, final state) { //updateState(state); - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final paletteStyles) { //updateState(state); return Row( @@ -56,7 +56,7 @@ class StyleFillControlState extends State { .map((final e) => e.name!) .toList(), onChange: (final value) { - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context) .state .forEach((final element) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart index bd585df3..2852ac0a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart @@ -92,7 +92,6 @@ class GoogleMapsMapStyleControlsState .fromJson(widget.mapStyle.toJson()); final mAA = widget.mapStyle..set(newValue); widget.callBack(mAA, old); - BlocProvider.of(context).change(); } }, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart index e483c5b6..3ef0288c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart @@ -7,7 +7,6 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:supabase/supabase.dart'; -import 'package:teta_core/src/cubits/panels/cubit.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart index 28f9162c..7ca891af 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart @@ -7,7 +7,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hovering/hovering.dart'; -import 'package:teta_core/src/cubits/panels/cubit.dart'; import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: @@ -207,11 +206,11 @@ class TextStylesControlState extends State { return ListView( shrinkWrap: true, children: state.map((final entry) { - if (entry.name!.contains(searchedText)) { + if (entry.name.contains(searchedText)) { return GestureDetector( onTap: () { updateTextStyleModel( - entry.name!, + entry.name, flag: false, ); }, @@ -222,12 +221,11 @@ class TextStylesControlState extends State { vertical: 8, ), child: Text( - entry.name!, + entry.name, style: GoogleFonts.getFont( - entry.fontFamily!, - fontSize: - entry.fontSize!.get(context), - fontWeight: entry.fontWeight!.get, + entry.fontFamily, + fontSize: entry.fontSize.get(context), + fontWeight: entry.fontWeight.get, color: Colors.white, ), ), diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index a461ef86..7c99dfaf 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -50,12 +50,13 @@ class TextPrefabControl extends StatelessWidget { node: node, textStyle: textStyle, callBack: (final textStyleModel, final flag, final old) { + if (textStyleModel == null) return; if (flag) { - ProjectRepository.addTextStyle( - prjId: prj.id, - text: node, - name: textStyleModel, - ); + sl.get().assignTextStyle( + styleName: textStyleModel, + node: node, + keyValue: keyValue, + ); } final old = textStyle; textStyle.textStyleModel = textStyleModel; @@ -221,16 +222,20 @@ class TextPrefabControl extends StatelessWidget { textStyle.toJson(), old, ); - } else { + } + //! TODO: + /*else { if (textStyle.fill!.paletteStyle is int) { - ProjectStylesRepository.updateColorStyle( - PaletteModel( - id: textStyle.fill!.paletteStyle! as int, - fill: color, - ), - ); + sl.get().updateColorStyle( + ColorStyleModel( + id: textStyle.fill!.paletteStyle! as int, + channelId: Constants.instance.currentChannelID!, + fill: color, + light: textStyle + ), + ); } - } + }*/ }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 0254d401..7510c016 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -194,16 +194,15 @@ class ControlBuilder { as Authenticated) .user .id; - ProjectRepository.track(prj.id, userId); + sl.get().track(prj.id, userId); } catch (e) { Logger.printError('Error tracking generic project update, error: $e'); } unawaited( - NodeRepository.changeNode( - node: node as NDynamic, - ), + sl.get().changeNode( + node: node as NDynamic, + ), ); - BlocProvider.of(context).change(); } catch (e) { if (kDebugMode) { // ignore: avoid_print @@ -281,7 +280,6 @@ class ControlBuilder { value.toJson(), old.toJson(), ); - BlocProvider.of(context).change(); }, ); } @@ -301,7 +299,6 @@ class ControlBuilder { value.toJson(), old.toJson(), ); - BlocProvider.of(context).change(); }, ); } @@ -912,10 +909,9 @@ class ControlBuilder { node: node, page: BlocProvider.of(context).state, callBack: (final list) async { - await ProjectRepository.updatePage( - BlocProvider.of(context).state, - ); - BlocProvider.of(context).change(); + await sl.get().updatePage( + BlocProvider.of(context).state, + ); }, ), ); @@ -928,10 +924,9 @@ class ControlBuilder { node: node, page: BlocProvider.of(context).state, callBack: (final list) async { - await ProjectRepository.updatePage( - BlocProvider.of(context).state, - ); - BlocProvider.of(context).change(); + await sl.get().updatePage( + BlocProvider.of(context).state, + ); }, ), ); @@ -1020,13 +1015,15 @@ class ControlBuilder { value.toJson(), old.toJson(), ); - } else { + } + //! TODO: + /* else { if (value.paletteStyle is int) { ProjectStylesRepository.updateColorStyle( - PaletteModel(id: value.paletteStyle! as int, fill: value), + ColorStyleModel(id: value.paletteStyle! as int, fill: value), ); } - } + }*/ }, ); } diff --git a/teta_widgets/lib/src/elements/features/fill.dart b/teta_widgets/lib/src/elements/features/fill.dart index cfe9e7e6..e8f81530 100644 --- a/teta_widgets/lib/src/elements/features/fill.dart +++ b/teta_widgets/lib/src/elements/features/fill.dart @@ -93,7 +93,7 @@ class FFill { ); } else { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == paletteStyle) model = element; if (element.name == paletteStyle) model = element; @@ -122,7 +122,7 @@ class FFill { boxFit: boxFit, ); } else { - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == paletteStyle) model = element; if (element.name == paletteStyle) model = element; @@ -325,7 +325,7 @@ class FFill { final bool? flagConst, }) { final state = BlocProvider.of(context).state; - PaletteModel? currentPaletteElement; + ColorStyleModel? currentPaletteElement; if (state.isNotEmpty) { for (final e in state) { if (e.id == fill.paletteStyle || e.name == fill.paletteStyle) { diff --git a/teta_widgets/lib/src/elements/widgets/badge.dart b/teta_widgets/lib/src/elements/widgets/badge.dart index 158984e6..928bcf38 100644 --- a/teta_widgets/lib/src/elements/widgets/badge.dart +++ b/teta_widgets/lib/src/elements/widgets/badge.dart @@ -32,7 +32,7 @@ class WBadge extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -59,7 +59,7 @@ class WBadge extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - HexColor _getbadgeColor(final PaletteModel? model, final bool isLight) { + HexColor _getbadgeColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight ? HexColor(model.light!.levels!.first.color) diff --git a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart index 175f741a..1670fd25 100644 --- a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart +++ b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart @@ -62,11 +62,11 @@ class WBottomBarItem extends StatelessWidget { ), child: Column( children: [ - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; for (final element in state) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -94,7 +94,7 @@ class WBottomBarItem extends StatelessWidget { // ignore: avoid_positional_boolean_parameters HexColor _getBottomBarItemColor( - final PaletteModel? model, + final ColorStyleModel? model, final bool isLight, ) { if (model != null) { diff --git a/teta_widgets/lib/src/elements/widgets/card.dart b/teta_widgets/lib/src/elements/widgets/card.dart index 2036bf24..4336c20c 100644 --- a/teta_widgets/lib/src/elements/widgets/card.dart +++ b/teta_widgets/lib/src/elements/widgets/card.dart @@ -37,7 +37,7 @@ class WCard extends StatelessWidget { context, ); final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == color.paletteStyle) model = element; if (element.name == color.paletteStyle) model = element; @@ -58,7 +58,7 @@ class WCard extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - HexColor _getCardColor(final PaletteModel? model, final bool isLight) { + HexColor _getCardColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight ? HexColor(model.light!.levels!.first.color) diff --git a/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart b/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart index a2bdb4e4..7fe14c45 100644 --- a/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart +++ b/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart @@ -23,7 +23,7 @@ class WCircularProgressIndicator extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -31,13 +31,14 @@ class WCircularProgressIndicator extends StatelessWidget { return TetaWidget( state: state, child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(_getCircularColor(model, isLight)), + valueColor: + AlwaysStoppedAnimation(_getCircularColor(model, isLight)), ), ); } // ignore: avoid_positional_boolean_parameters - HexColor _getCircularColor(final PaletteModel? model, final bool isLight) { + HexColor _getCircularColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight ? HexColor(model.light!.levels!.first.color) diff --git a/teta_widgets/lib/src/elements/widgets/component.dart b/teta_widgets/lib/src/elements/widgets/component.dart index c621d299..5ea1a52f 100644 --- a/teta_widgets/lib/src/elements/widgets/component.dart +++ b/teta_widgets/lib/src/elements/widgets/component.dart @@ -8,7 +8,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:recase/recase.dart'; -import 'package:teta_core/src/rendering/nodes_original.dart'; +import 'package:teta_core/src/rendering/nodes.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_repositories/src/node_repository.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; @@ -74,7 +74,7 @@ class _WComponentState extends State { Logger.printMessage('enter here'); if (component?.scaffold == null) { final nodes = await fetch(_component, context); - final scaffold = NodeRendering.renderTree(nodes); + final scaffold = sl.get().renderTree(nodes); _component = _component.copyWith(flatList: nodes, scaffold: scaffold); } if (mounted) { @@ -109,7 +109,7 @@ class _WComponentState extends State { final PageObject page, final BuildContext context, ) async { - final list = await NodeRepository.fetchNodesByPage(page.id); + final list = await sl.get().fetchNodesByPage(page.id); final nodes = []; for (final e in list) { nodes.add( @@ -125,7 +125,7 @@ class _WComponentState extends State { Widget body(final BuildContext context) { return component != null ? BlocProvider( - create: (final context) => PageCubit() + create: (final context) => PageCubit(sl.get()) ..onFocus( prj: prj, page: component!, diff --git a/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart b/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart index ed5bf318..21372b33 100644 --- a/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart +++ b/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart @@ -40,7 +40,7 @@ class _WConcentricPageViewState extends State { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == widget.fill.paletteStyle) model = element; if (element.name == widget.fill.paletteStyle) model = element; @@ -48,7 +48,10 @@ class _WConcentricPageViewState extends State { return TetaWidget( state: widget.state, child: ConcentricPageView( - colors: [_getConcentricPageColor(model, isLight), _getConcentricPageColor(model, isLight)], + colors: [ + _getConcentricPageColor(model, isLight), + _getConcentricPageColor(model, isLight) + ], itemCount: widget.children.length, itemBuilder: (final int index) { return widget.children[index].toWidget(state: widget.state); @@ -59,7 +62,7 @@ class _WConcentricPageViewState extends State { // ignore: avoid_positional_boolean_parameters HexColor _getConcentricPageColor( - final PaletteModel? model, + final ColorStyleModel? model, final bool isLight, ) { if (model != null) { diff --git a/teta_widgets/lib/src/elements/widgets/divider.dart b/teta_widgets/lib/src/elements/widgets/divider.dart index 7ef8c877..fb0d0fc7 100644 --- a/teta_widgets/lib/src/elements/widgets/divider.dart +++ b/teta_widgets/lib/src/elements/widgets/divider.dart @@ -28,7 +28,7 @@ class WDivider extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -44,7 +44,7 @@ class WDivider extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - HexColor _getDividerColor(final PaletteModel? model, final bool isLight) { + HexColor _getDividerColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight ? HexColor(model.light!.levels!.first.color) diff --git a/teta_widgets/lib/src/elements/widgets/icon.dart b/teta_widgets/lib/src/elements/widgets/icon.dart index 22b28724..aa5a208c 100644 --- a/teta_widgets/lib/src/elements/widgets/icon.dart +++ b/teta_widgets/lib/src/elements/widgets/icon.dart @@ -26,7 +26,7 @@ class WIcon extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -42,7 +42,7 @@ class WIcon extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - Color _getIconColor(final PaletteModel? model, final bool isLight) { + Color _getIconColor(final ColorStyleModel? model, final bool isLight) { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight diff --git a/teta_widgets/lib/src/elements/widgets/icon_feather.dart b/teta_widgets/lib/src/elements/widgets/icon_feather.dart index 98f87170..3184f5d2 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_feather.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_feather.dart @@ -26,7 +26,7 @@ class WFeatherIcon extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -42,7 +42,7 @@ class WFeatherIcon extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - Color _getIconColor(final PaletteModel? model, final bool isLight) { + Color _getIconColor(final ColorStyleModel? model, final bool isLight) { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight diff --git a/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart b/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart index 6c237747..e8d73284 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart @@ -25,7 +25,7 @@ class WFontAwesome extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; if (element.name == fill.paletteStyle) model = element; @@ -41,7 +41,7 @@ class WFontAwesome extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - Color _getIconColor(final PaletteModel? model, final bool isLight) { + Color _getIconColor(final ColorStyleModel? model, final bool isLight) { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight diff --git a/teta_widgets/lib/src/elements/widgets/icon_line.dart b/teta_widgets/lib/src/elements/widgets/icon_line.dart index d0ed18ed..6a09a926 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_line.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_line.dart @@ -26,7 +26,7 @@ class WLineIcon extends StatelessWidget { @override Widget build(final BuildContext context) { final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == fill.paletteStyle) model = element; }); @@ -41,7 +41,7 @@ class WLineIcon extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - Color _getIconColor(final PaletteModel? model, final bool isLight) { + Color _getIconColor(final ColorStyleModel? model, final bool isLight) { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight diff --git a/teta_widgets/lib/src/elements/widgets/placeholder.dart b/teta_widgets/lib/src/elements/widgets/placeholder.dart index 98e446b3..36e2ce38 100644 --- a/teta_widgets/lib/src/elements/widgets/placeholder.dart +++ b/teta_widgets/lib/src/elements/widgets/placeholder.dart @@ -39,7 +39,7 @@ class WPlaceholder extends StatelessWidget { context, ); final isLight = BlocProvider.of(context).state; - PaletteModel? model; + ColorStyleModel? model; BlocProvider.of(context).state.forEach((final element) { if (element.id == color.paletteStyle) model = element; if (element.name == color.paletteStyle) model = element; @@ -58,7 +58,8 @@ class WPlaceholder extends StatelessWidget { } // ignore: avoid_positional_boolean_parameters - HexColor _getPlaceHolderColor(final PaletteModel? model, final bool isLight) { + HexColor _getPlaceHolderColor( + final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight ? HexColor(model.light!.levels!.first.color) diff --git a/teta_widgets/lib/src/elements/widgets/shopify/shopify_login.dart b/teta_widgets/lib/src/elements/widgets/shopify/shopify_login.dart index 46f5e1cb..8189be07 100644 --- a/teta_widgets/lib/src/elements/widgets/shopify/shopify_login.dart +++ b/teta_widgets/lib/src/elements/widgets/shopify/shopify_login.dart @@ -163,7 +163,7 @@ class _WShopifyLoginState extends State { } Widget body(BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { if (state.isNotEmpty) { FFill? accentFill; @@ -406,7 +406,7 @@ class _WShopifyLoginState extends State { Widget textField( BuildContext context, bool isObscure, Function(String) callBack) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { if (state.isNotEmpty) { final szs = widget.sizes.get(context); @@ -500,7 +500,7 @@ class _WShopifyLoginState extends State { Widget childCondition( List radius, bool isObscure, Function(String) callBack) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { FFill? finalFill; if (state.isNotEmpty) diff --git a/teta_widgets/lib/src/elements/widgets/shopify/shopify_registration.dart b/teta_widgets/lib/src/elements/widgets/shopify/shopify_registration.dart index e56674ca..dff710aa 100644 --- a/teta_widgets/lib/src/elements/widgets/shopify/shopify_registration.dart +++ b/teta_widgets/lib/src/elements/widgets/shopify/shopify_registration.dart @@ -173,7 +173,7 @@ class _WShopifyRegistrationState extends State { } Widget body(BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { if (state != []) { FFill? accentFill; @@ -627,7 +627,7 @@ class _WShopifyRegistrationState extends State { Widget textField( BuildContext context, bool isObscure, Function(String) callBack) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { final szs = widget.sizes.get(context); final radius = widget.borderRadius.get(context); @@ -717,7 +717,7 @@ class _WShopifyRegistrationState extends State { Widget childCondition( List radius, bool isObscure, Function(String) callBack) { - return BlocBuilder>( + return BlocBuilder>( builder: (context, state) { FFill? finalFill; if (state.isNotEmpty) diff --git a/teta_widgets/lib/src/elements/widgets/text.dart b/teta_widgets/lib/src/elements/widgets/text.dart index 31028cae..8100517e 100644 --- a/teta_widgets/lib/src/elements/widgets/text.dart +++ b/teta_widgets/lib/src/elements/widgets/text.dart @@ -55,7 +55,7 @@ class _WTextState extends State { Widget build(final BuildContext context) { return NodeSelectionBuilder( state: widget.state, - child: BlocBuilder>( + child: BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { FFill? finalFill; @@ -214,10 +214,9 @@ class _WTextState extends State { widget.state.node.body.attributes[DBKeys.value] = FTextTypeInput( value: text, ); - NodeRepository.changeNode( - node: widget.state.node as NDynamic, - ); - BlocProvider.of(context).change(); + sl.get().changeNode( + node: widget.state.node as NDynamic, + ); } } diff --git a/teta_widgets/lib/src/elements/widgets/w_audio_player.dart b/teta_widgets/lib/src/elements/widgets/w_audio_player.dart index 58743917..9e6feb69 100644 --- a/teta_widgets/lib/src/elements/widgets/w_audio_player.dart +++ b/teta_widgets/lib/src/elements/widgets/w_audio_player.dart @@ -45,7 +45,8 @@ class _WAudioPlayerState extends State { final page = BlocProvider.of(context).state; _map = DatasetObject( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: [{}], ); @@ -68,11 +69,13 @@ class _WAudioPlayerState extends State { final audioPlayerDataset = widget.state.dataset .firstWhere( - (final element) => element.getName == widget.selectedDataset.datasetName, + (final element) => + element.getName == widget.selectedDataset.datasetName, ) .getMap; for (final element in audioPlayerDataset) { - final url = element['${widget.selectedDataset.datasetAttrName}'] as String?; + final url = + element['${widget.selectedDataset.datasetAttrName}'] as String?; if (url != null) { audioList.add( AudioSource.uri(Uri.parse(url)), @@ -126,7 +129,8 @@ class _WAudioPlayerState extends State { if (!snapshot.hasData) { // has data is negative _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: [ { 'is playing': ap!.playing.toString(), @@ -135,7 +139,8 @@ class _WAudioPlayerState extends State { ); } else { _map = _map.copyWith( - name: widget.state.node.name ?? widget.state.node.intrinsicState.displayName, + name: widget.state.node.name ?? + widget.state.node.intrinsicState.displayName, map: [ { ...getCurrentSongAttribute(), @@ -143,13 +148,14 @@ class _WAudioPlayerState extends State { ], ); } - BlocProvider.of(context).change(); final datasets = addDataset(context, widget.state.dataset, _map); return ChildConditionBuilder( ValueKey('${widget.state.node.nid} ${widget.state.loop}'), state: widget.state.copyWith( - dataset: widget.state.dataset.isEmpty ? datasets : widget.state.dataset, + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, ), child: widget.child, ); @@ -170,6 +176,7 @@ class _WAudioPlayerState extends State { final audioPlayerDataset = widget.state.dataset.firstWhere( (final element) => element.getName == widget.selectedDataset.datasetName, ); - return audioPlayerDataset.getMap[variable?.audioController?.currentIndex ?? 0]; + return audioPlayerDataset + .getMap[variable?.audioController?.currentIndex ?? 0]; } } From 9a99f67f642c13bc24082f41a22540c65d0cd8e0 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Sun, 15 Jan 2023 17:51:51 +0100 Subject: [PATCH 14/23] Update nnull.dart --- teta_widgets/lib/src/elements/nodes/nnull.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/teta_widgets/lib/src/elements/nodes/nnull.dart b/teta_widgets/lib/src/elements/nodes/nnull.dart index 853ed834..dadf960a 100644 --- a/teta_widgets/lib/src/elements/nodes/nnull.dart +++ b/teta_widgets/lib/src/elements/nodes/nnull.dart @@ -20,7 +20,6 @@ const globalName = 'Null'; class NNull extends CNode { /// construct NNull({ - required this.context, this.nid = 0, }) : super(childrenIds: FChildrenIds()); @@ -32,14 +31,11 @@ class NNull extends CNode { @override int nid; - BuildContext? context; - /// fromJson static NNull fromJson( final Map doc, - final BuildContext context, ) => - NNull(context: context); + NNull(); @override Map toJson() => {}; From 553b4614b61e4b4075b2a2d051e7b9ff14fd99b6 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Tue, 17 Jan 2023 14:22:50 +0100 Subject: [PATCH 15/23] Update index.dart --- teta_widgets/lib/src/elements/features/index.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/teta_widgets/lib/src/elements/features/index.dart b/teta_widgets/lib/src/elements/features/index.dart index 1206320c..8a46946c 100644 --- a/teta_widgets/lib/src/elements/features/index.dart +++ b/teta_widgets/lib/src/elements/features/index.dart @@ -19,6 +19,7 @@ export './firestore_path.dart'; export './font_size.dart'; export './font_style.dart'; export './font_style.dart'; +export './font_weight.dart'; export './keyboard_type.dart'; export './main_axis_alignment.dart'; export './main_axis_size.dart'; From 7d5f3c9f9b307d1b19aa17de9723a3c739c98cad Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Fri, 20 Jan 2023 18:55:32 +0100 Subject: [PATCH 16/23] feat(widgets) --- .../src/elements/actions/braintree/pay.dart | 23 +- .../elements/actions/camera/always_flash.dart | 10 +- .../elements/actions/camera/auto_flash.dart | 11 +- .../elements/actions/camera/off_flash.dart | 10 +- .../actions/camera/stop_recording.dart | 6 +- .../actions/camera/switch_camera.dart | 2 +- .../elements/actions/camera/take_photo.dart | 9 +- .../elements/actions/camera/torch_flash.dart | 2 +- .../actions/mixpanel/set_user_id.dart | 6 +- .../src/elements/actions/mixpanel/track.dart | 6 +- .../actions/snippets/get_page_on_code.dart | 9 +- .../actions/snippets/take_param_from.dart | 5 +- .../actions/snippets/take_state_from.dart | 3 +- .../elements/actions/teta_cms/auth/login.dart | 2 +- .../src/elements/bodies/google_maps_body.dart | 7 +- .../lib/src/elements/bodies/scaffold.dart | 4 +- .../src/elements/controls/atoms/action.dart | 6 - .../controls/atoms/action_element.dart | 12 - .../elements/controls/atoms/action_value.dart | 4 - .../widgets/add_data_element.dart | 143 +++++--- .../controls/atoms/actions/validator.dart | 108 +++--- .../controls/atoms/airtable/delete.dart | 10 - .../controls/atoms/airtable/insert.dart | 11 - .../controls/atoms/airtable/update.dart | 10 - .../src/elements/controls/atoms/aligns.dart | 4 +- .../controls/atoms/apicalls/apicalls.dart | 13 - .../controls/atoms/apicalls_request.dart | 2 - .../controls/atoms/audio_controller.dart | 6 +- .../controls/atoms/border_radius.dart | 55 +-- .../src/elements/controls/atoms/borders.dart | 173 ++++----- .../controls/atoms/camera_controller.dart | 4 - .../controls/atoms/cms_collections.dart | 2 - .../src/elements/controls/atoms/color.dart | 160 +++----- .../atoms/condition/value_of_condition.dart | 343 +++++++++--------- .../controls/atoms/cross_axis_alignment.dart | 15 +- .../src/elements/controls/atoms/dataset.dart | 4 - .../src/elements/controls/atoms/db_map.dart | 18 +- .../src/elements/controls/atoms/delete.dart | 2 - .../lib/src/elements/controls/atoms/fill.dart | 2 - .../elements/controls/atoms/fill/asset.dart | 2 - .../elements/controls/atoms/fill/image.dart | 13 +- .../elements/controls/atoms/fill/linear.dart | 29 +- .../elements/controls/atoms/fill/radial.dart | 19 +- .../elements/controls/atoms/fill/solid.dart | 55 +-- .../elements/controls/atoms/fill/style.dart | 8 +- .../controls/atoms/firebase/parameter.dart | 197 +++++----- .../controls/atoms/firebase/path.dart | 2 +- .../lib/src/elements/controls/atoms/flag.dart | 2 - .../elements/controls/atoms/flat_text.dart | 17 +- .../elements/controls/atoms/font_family.dart | 2 - .../elements/controls/atoms/font_size.dart | 16 +- .../elements/controls/atoms/font_style.dart | 2 - .../elements/controls/atoms/font_weight.dart | 2 - .../controls/atoms/google_maps_control.dart | 4 - .../atoms/google_maps_map_style_controls.dart | 21 +- .../controls/atoms/httpMethodControl.dart | 13 +- .../https_requests_custom_backend/delete.dart | 14 - .../https_requests_custom_backend/post.dart | 16 - .../https_requests_custom_backend/update.dart | 16 - .../lib/src/elements/controls/atoms/icon.dart | 2 - .../elements/controls/atoms/icon_feather.dart | 2 - .../controls/atoms/icon_fontawesome.dart | 2 - .../elements/controls/atoms/icon_line.dart | 2 - .../controls/atoms/main_axis_alignment.dart | 15 +- .../controls/atoms/main_axis_size.dart | 15 +- .../controls/atoms/map_controller.dart | 4 - .../elements/controls/atoms/map_element.dart | 19 +- .../src/elements/controls/atoms/margins.dart | 35 +- .../controls/atoms/mixpanel/set_user_id.dart | 6 - .../controls/atoms/mixpanel/track.dart | 7 - .../lib/src/elements/controls/atoms/name.dart | 2 - .../controls/atoms/navigation/component.dart | 6 - .../elements/controls/atoms/page_params.dart | 4 - .../controls/atoms/qonversion/buy.dart | 104 +++--- .../controls/atoms/revenuecat/buy.dart | 64 ++-- .../lib/src/elements/controls/atoms/size.dart | 66 ++-- .../controls/atoms/subapase/delete.dart | 10 - .../controls/atoms/subapase/insert.dart | 10 - .../controls/atoms/subapase/invoke.dart | 9 - .../atoms/subapase/storage_remove.dart | 14 - .../atoms/subapase/storage_upload.dart | 123 ++++--- .../controls/atoms/subapase/update.dart | 12 - .../controls/atoms/teta_cms/delete.dart | 9 - .../controls/atoms/teta_cms/insert.dart | 9 - .../controls/atoms/teta_cms/update.dart | 11 - .../controls/atoms/text_direction.dart | 15 +- .../controls/atoms/video/video_start_at.dart | 2 - .../controls/atoms/video/video_url.dart | 2 - .../src/elements/controls/http_params.dart | 179 ++++----- .../controls/http_params_element.dart | 78 ++-- .../controls/prefabs/text_prefab_control.dart | 6 - .../lib/src/elements/controls/type.dart | 93 +---- .../elements/features/actions/element.dart | 118 +++--- .../src/elements/widgets/airtable/fetch.dart | 6 +- .../lib/src/elements/widgets/camera.dart | 2 +- .../lib/src/elements/widgets/component.dart | 26 +- .../google_maps_web_mobile_widget.dart | 11 +- .../lib/src/elements/widgets/icon.dart | 4 +- .../src/elements/widgets/icon_feather.dart | 4 +- .../elements/widgets/icon_font_awesome.dart | 4 +- .../lib/src/elements/widgets/icon_line.dart | 4 +- .../lib/src/elements/widgets/map.dart | 14 +- .../lib/src/elements/widgets/map_builder.dart | 14 +- .../lib/src/elements/widgets/scaffold.dart | 6 +- .../src/elements/widgets/scaffold/mobile.dart | 12 +- .../widgets/teta_cms/logged_user.dart | 9 +- .../src/elements/widgets/w_audio_player.dart | 2 +- .../w_audio_player_progress_indicator.dart | 17 +- .../w_audio_player_volume_indicator.dart | 17 +- .../lib/src/elements/widgets/webview.dart | 8 +- 110 files changed, 1171 insertions(+), 1716 deletions(-) diff --git a/teta_widgets/lib/src/elements/actions/braintree/pay.dart b/teta_widgets/lib/src/elements/actions/braintree/pay.dart index 3118c5f8..7469d418 100644 --- a/teta_widgets/lib/src/elements/actions/braintree/pay.dart +++ b/teta_widgets/lib/src/elements/actions/braintree/pay.dart @@ -39,20 +39,22 @@ class FActionBraintreeBuy { final String? stateName, { final int loop = 0, }) { - final prj = BlocProvider.of(context).state!; - final isSandbox = prj.config?.braintreeIsSandbox ?? true; + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; + final isSandbox = config.braintree.isSandbox; final token = !isSandbox - ? prj.config?.braintreeClientToken - : prj.config?.braintreeClientTokenSandbox; - final companyName = prj.config?.companyName ?? ''; - final currencyCode = prj.config?.braintreeCurrencyCode ?? ''; - final countryCode = prj.config?.countryCode ?? ''; + ? config.braintree.productionInfo.clientToken + : config.braintree.sandboxInfo.clientToken; + final companyName = config.braintree.companyName; + final currencyCode = config.braintree.currencyCode; + final countryCode = config.braintree.countryCode; final amount = valueToChangeWith!.toCode( loop, resultType: ResultTypeEnum.double, defaultValue: '1.00', ); - final appleMerchantId = prj.config?.appleMerchantId; + final appleMerchantId = config.braintree.applePay.merchantId; String? paypal; String? googlePay; String? applePay; @@ -61,7 +63,6 @@ class FActionBraintreeBuy { if (amount.isEmpty) return ''; final page = getPageOnToCode(pageId, context); - if (page == null) return ''; final variable = takeStateFrom(page, stateName); if (variable == null) return ''; @@ -73,7 +74,7 @@ class FActionBraintreeBuy { displayName: '$companyName', ),'''; - if (prj.config?.googlePayFlag ?? false) { + if (config.braintree.googlePay.isEnabled) { googlePay = ''' BraintreeGooglePaymentRequest( totalPrice: $amount, @@ -81,7 +82,7 @@ class FActionBraintreeBuy { billingAddressRequired: false, ),'''; } - if (prj.config?.isApplePayReady ?? false) { + if (config.braintree.applePay.isEnabled) { applePay = ''' BraintreeApplePayRequest( displayName: '$companyName', diff --git a/teta_widgets/lib/src/elements/actions/camera/always_flash.dart b/teta_widgets/lib/src/elements/actions/camera/always_flash.dart index aa74c548..ec43de1c 100644 --- a/teta_widgets/lib/src/elements/actions/camera/always_flash.dart +++ b/teta_widgets/lib/src/elements/actions/camera/always_flash.dart @@ -14,9 +14,9 @@ import 'package:teta_widgets/src/elements/actions/snippets/get_page_on_code.dart class FACameraAlwaysFlash { static Future action(final BuildContext context) async { - final page = BlocProvider.of(context).state; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final page = BlocProvider.of(context).state as PageLoaded; + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); final controller = state?.controller; if (controller != null) { await controller.setFlashMode(FlashMode.always); @@ -29,8 +29,8 @@ class FACameraAlwaysFlash { ) { final page = getPageOnToCode(pageId, context); if (page == null) return ''; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); if (state == null) return ''; final rc = ReCase(state.name); return ''' diff --git a/teta_widgets/lib/src/elements/actions/camera/auto_flash.dart b/teta_widgets/lib/src/elements/actions/camera/auto_flash.dart index f23119e0..08d06ed3 100644 --- a/teta_widgets/lib/src/elements/actions/camera/auto_flash.dart +++ b/teta_widgets/lib/src/elements/actions/camera/auto_flash.dart @@ -18,9 +18,9 @@ class FACameraAutoFlash { final BuildContext context, final TetaWidgetState state, ) async { - final page = BlocProvider.of(context).state; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final page = BlocProvider.of(context).state as PageLoaded; + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); final controller = state?.controller; if (controller != null) { await controller.setFlashMode(FlashMode.off); @@ -32,9 +32,8 @@ class FACameraAutoFlash { final int pageId, ) { final page = getPageOnToCode(pageId, context); - if (page == null) return ''; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); if (state == null) return ''; final rc = ReCase(state.name); return ''' diff --git a/teta_widgets/lib/src/elements/actions/camera/off_flash.dart b/teta_widgets/lib/src/elements/actions/camera/off_flash.dart index 05e8698c..387e0fbd 100644 --- a/teta_widgets/lib/src/elements/actions/camera/off_flash.dart +++ b/teta_widgets/lib/src/elements/actions/camera/off_flash.dart @@ -14,9 +14,9 @@ import 'package:teta_widgets/src/elements/actions/snippets/get_page_on_code.dart class FACameraOffFlash { static Future action(final BuildContext context) async { - final page = BlocProvider.of(context).state; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final page = BlocProvider.of(context).state as PageLoaded; + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); final controller = state?.controller; if (controller != null) { await controller.setFlashMode(FlashMode.auto); @@ -29,8 +29,8 @@ class FACameraOffFlash { ) { final page = getPageOnToCode(pageId, context); if (page == null) return ''; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); if (state == null) return ''; final rc = ReCase(state.name); return ''' diff --git a/teta_widgets/lib/src/elements/actions/camera/stop_recording.dart b/teta_widgets/lib/src/elements/actions/camera/stop_recording.dart index bb5f98b9..be66e515 100644 --- a/teta_widgets/lib/src/elements/actions/camera/stop_recording.dart +++ b/teta_widgets/lib/src/elements/actions/camera/stop_recording.dart @@ -18,7 +18,7 @@ class FACameraStopRecording { final TetaWidgetState state, final String? stateName, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final stateFound = page.states.firstWhereOrNull( (final e) => e.type == VariableType.cameraController, ); @@ -41,8 +41,8 @@ class FACameraStopRecording { ) { final page = getPageOnToCode(pageId, context); if (page == null) return ''; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); if (state == null || stateName == null) return ''; final rc = ReCase(state.name); final fileStateName = ReCase(stateName); diff --git a/teta_widgets/lib/src/elements/actions/camera/switch_camera.dart b/teta_widgets/lib/src/elements/actions/camera/switch_camera.dart index f9130f88..3e139725 100644 --- a/teta_widgets/lib/src/elements/actions/camera/switch_camera.dart +++ b/teta_widgets/lib/src/elements/actions/camera/switch_camera.dart @@ -18,7 +18,7 @@ class FACameraSwitch { final BuildContext context, final String? stateName, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final state = page.states.firstWhereOrNull( (final e) => e.type == VariableType.cameraController, ); diff --git a/teta_widgets/lib/src/elements/actions/camera/take_photo.dart b/teta_widgets/lib/src/elements/actions/camera/take_photo.dart index a9635591..f1e8d31e 100644 --- a/teta_widgets/lib/src/elements/actions/camera/take_photo.dart +++ b/teta_widgets/lib/src/elements/actions/camera/take_photo.dart @@ -18,14 +18,15 @@ class FACameraTakePhoto { final TetaWidgetState state, final String? stateName, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final stateFound = page.states.firstWhereOrNull( (final e) => e.type == VariableType.cameraController, ); final controller = stateFound?.controller; if (controller != null) { final file = await controller.takePicture(); - final index = state.states.indexWhere((final element) => element.name == stateName); + final index = + state.states.indexWhere((final element) => element.name == stateName); state.states[index].file = file; } } @@ -37,8 +38,8 @@ class FACameraTakePhoto { ) { final page = getPageOnToCode(pageId, context); if (page == null) return ''; - final state = - page.states.firstWhereOrNull((final e) => e.type == VariableType.cameraController); + final state = page.states + .firstWhereOrNull((final e) => e.type == VariableType.cameraController); if (state == null || stateName == null) return ''; final rc = ReCase(state.name); final fileStateName = ReCase(stateName); diff --git a/teta_widgets/lib/src/elements/actions/camera/torch_flash.dart b/teta_widgets/lib/src/elements/actions/camera/torch_flash.dart index f9f9a592..4cb72e9c 100644 --- a/teta_widgets/lib/src/elements/actions/camera/torch_flash.dart +++ b/teta_widgets/lib/src/elements/actions/camera/torch_flash.dart @@ -17,7 +17,7 @@ class FACameraTorchFlash { final BuildContext context, final String? stateName, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final state = page.states.firstWhereOrNull( (final e) => e.type == VariableType.cameraController, ); diff --git a/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart b/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart index 09980f3e..19cfd375 100644 --- a/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart +++ b/teta_widgets/lib/src/elements/actions/mixpanel/set_user_id.dart @@ -52,8 +52,10 @@ class FAMixpanelSetUserId { final BuildContext context, final FTextTypeInput? userIdValue, ) { - final prj = BlocProvider.of(context).state!; - if (prj.config?.isMixpanelReady ?? false) { + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; + if (config.mixpanel is MixpanelConfigModelInitialized) { final userId = userIdValue?.toCode( 0, resultType: ResultTypeEnum.string, diff --git a/teta_widgets/lib/src/elements/actions/mixpanel/track.dart b/teta_widgets/lib/src/elements/actions/mixpanel/track.dart index f79b8bef..3bc90668 100644 --- a/teta_widgets/lib/src/elements/actions/mixpanel/track.dart +++ b/teta_widgets/lib/src/elements/actions/mixpanel/track.dart @@ -54,8 +54,10 @@ class FAMixpanelTrack { final FTextTypeInput? eventName, final List? props, ) { - final prj = BlocProvider.of(context).state!; - if (prj.config?.isMixpanelReady ?? false) { + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; + if (config.mixpanel is MixpanelConfigModelInitialized) { //props final mapBody = {}; for (final e in props ?? []) { diff --git a/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart b/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart index f04c554e..62855064 100644 --- a/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart +++ b/teta_widgets/lib/src/elements/actions/snippets/get_page_on_code.dart @@ -3,10 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; -PageObject? getPageOnToCode(final int pageId, final BuildContext context) { - final prj = BlocProvider.of(context).state!; - if (prj.pages != null) { - return prj.pages!.firstWhereOrNull((final element) => element.id == pageId); - } - return null; +PageLoaded getPageOnToCode(final int pageId, final BuildContext context) { + final page = BlocProvider.of(context).state; + return page as PageLoaded; } diff --git a/teta_widgets/lib/src/elements/actions/snippets/take_param_from.dart b/teta_widgets/lib/src/elements/actions/snippets/take_param_from.dart index f5594395..729764b9 100644 --- a/teta_widgets/lib/src/elements/actions/snippets/take_param_from.dart +++ b/teta_widgets/lib/src/elements/actions/snippets/take_param_from.dart @@ -2,10 +2,9 @@ // Package imports: import 'package:collection/collection.dart'; -import 'package:teta_core/src/models/page.dart'; -import 'package:teta_core/src/models/variable.dart'; +import 'package:teta_core/teta_core.dart'; -VariableObject? takeParamFrom(final PageObject page, final String condition) { +VariableObject? takeParamFrom(final PageLoaded page, final String condition) { return page.params.firstWhereOrNull( (final element) => element.name.toLowerCase() == condition.toLowerCase(), ); diff --git a/teta_widgets/lib/src/elements/actions/snippets/take_state_from.dart b/teta_widgets/lib/src/elements/actions/snippets/take_state_from.dart index e2326606..1a53c1d0 100644 --- a/teta_widgets/lib/src/elements/actions/snippets/take_state_from.dart +++ b/teta_widgets/lib/src/elements/actions/snippets/take_state_from.dart @@ -4,8 +4,9 @@ import 'package:collection/collection.dart'; import 'package:teta_core/src/models/page.dart'; import 'package:teta_core/src/models/variable.dart'; +import 'package:teta_core/teta_core.dart'; -VariableObject? takeStateFrom(final PageObject page, final String condition) { +VariableObject? takeStateFrom(final PageLoaded page, final String condition) { return page.states.firstWhereOrNull( (final element) => element.name.toLowerCase() == condition.toLowerCase(), ); diff --git a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart index 06708e26..731a5746 100644 --- a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart +++ b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart @@ -66,7 +66,7 @@ class FATetaCMSLogin { final Map? paramsToSend, ) { final prj = BlocProvider.of(context).state!; - final isRevenueCatEnabled = prj.config?.isRevenueCatEnabled ?? false; + final isRevenueCatEnabled = config?.isRevenueCatEnabled ?? false; final providerStr = provider == TetaProvider.google ? 'TetaProvider.google' : provider == TetaProvider.twitter diff --git a/teta_widgets/lib/src/elements/bodies/google_maps_body.dart b/teta_widgets/lib/src/elements/bodies/google_maps_body.dart index e9280519..9b2ee2b7 100644 --- a/teta_widgets/lib/src/elements/bodies/google_maps_body.dart +++ b/teta_widgets/lib/src/elements/bodies/google_maps_body.dart @@ -419,11 +419,10 @@ class GoogleMapsBody extends NodeBody { (attributes[DBKeys.mapCustomInitialZoomLevel] as FTextTypeInput) .toCode(loop, resultType: ResultTypeEnum.double), trackMyLocation: attributes[DBKeys.mapConfigTrackMyLocation] as bool, - googleMapsKey: BlocProvider.of(context) - .state! + googleMapsKey: + (BlocProvider.of(context).state as ConfigStateLoaded) .config - ?.googleMapsKey ?? - '', + .googleMapsKey, googleMapsCubitName: (attributes[DBKeys.googleMapsCubitController] as FTextTypeInput) .stateName ?? diff --git a/teta_widgets/lib/src/elements/bodies/scaffold.dart b/teta_widgets/lib/src/elements/bodies/scaffold.dart index 69b620e6..f0b4cb59 100644 --- a/teta_widgets/lib/src/elements/bodies/scaffold.dart +++ b/teta_widgets/lib/src/elements/bodies/scaffold.dart @@ -187,8 +187,8 @@ class ScaffoldBody extends NodeBody { final int pageId, final int? loop, ) { - final prj = BlocProvider.of(context).state!; - final page = prj.pages!.firstWhere((final element) => element.id == pageId); + final pages = BlocProvider.of(context).state; + final page = pages.firstWhere((final element) => element.id == pageId); if (!page.isHardCoded) { return pageCodeTemplate( context, diff --git a/teta_widgets/lib/src/elements/controls/atoms/action.dart b/teta_widgets/lib/src/elements/controls/atoms/action.dart index 1a679dda..eb78933a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action.dart @@ -32,17 +32,11 @@ import 'package:uuid/uuid.dart'; class ActionControl extends StatefulWidget { const ActionControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callBack, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FAction action; final Function(FAction, FAction) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index d1e4030d..ff840fba 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -66,9 +66,6 @@ class ActionElementControl extends StatefulWidget { const ActionElementControl({ required this.name, required this.element, - required this.prj, - required this.page, - required this.node, required this.callBack, required this.callBackToDelete, final Key? key, @@ -80,15 +77,6 @@ class ActionElementControl extends StatefulWidget { /// Action itself final FActionElement element; - /// Current project - final ProjectObject prj; - - /// Current page - final PageObject page; - - /// Current node - final CNode node; - /// Function to change the action's properties final Function(FActionElement, FActionElement) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_value.dart b/teta_widgets/lib/src/elements/controls/atoms/action_value.dart index 7a3c3196..57232ce7 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_value.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_value.dart @@ -11,16 +11,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class ActionvalueControl extends StatefulWidget { const ActionvalueControl({ - required this.node, - required this.page, required this.title, required this.actionValue, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; - final PageObject page; final String title; final FTextTypeInput actionValue; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/actions/firebase_firestore/widgets/add_data_element.dart b/teta_widgets/lib/src/elements/controls/atoms/actions/firebase_firestore/widgets/add_data_element.dart index acdfd39d..399e2a26 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/actions/firebase_firestore/widgets/add_data_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/actions/firebase_firestore/widgets/add_data_element.dart @@ -3,11 +3,13 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; // Package imports: import 'package:teta_core/src/design_system/dropdowns/dropdown.dart'; import 'package:teta_core/src/design_system/dropdowns/dropdown_for_type.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/src/models/page.dart'; +import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; @@ -104,58 +106,88 @@ class AddDataElementState extends State { }, ), if (value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params - .map((final e) => e.name) - .contains(value.paramName) - ? value.paramName - : null, - items: - widget.page.params.map((final e) => e.get as String).toList(), - onChange: (final newValue) { - final old = value; - value.paramName = newValue; - widget.callback(value.toJson(), old.toJson()); + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.params + .map((final e) => e.name) + .contains(value.paramName) + ? value.paramName + : null, + items: + state.params.map((final e) => e.get as String).toList(), + onChange: (final newValue) { + final old = value; + value.paramName = newValue; + widget.callback(value.toJson(), old.toJson()); + }, + ); }, ), if (value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states - .map((final e) => e.name) - .contains(value.stateName) - ? value.stateName - : null, - items: widget.page.states.map((final e) => e.name).toList(), - onChange: (final newValue) { - final old = value; - value.stateName = newValue; - widget.callback(value.toJson(), old.toJson()); + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .contains(value.stateName) + ? value.stateName + : null, + items: state.states.map((final e) => e.name).toList(), + onChange: (final newValue) { + final old = value; + value.stateName = newValue; + widget.callback(value.toJson(), old.toJson()); + }, + ); }, ), if (value.type == FTextTypeEnum.dataset) - CDropdown( - value: widget.page.datasets + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .contains(value.datasetName) + ? value.datasetName + : null, + items: state.datasets .map((final e) => e.getName) .where((final element) => element != 'null') - .contains(value.datasetName) - ? value.datasetName - : null, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - setState(() { - databaseName = newValue!; - }); - final old = value; - value.datasetName = newValue; - widget.callback(value.toJson(), old.toJson()); + .toList(), + onChange: (final newValue) { + setState(() { + databaseName = newValue!; + }); + final old = value; + value.datasetName = newValue; + widget.callback(value.toJson(), old.toJson()); + }, + ); }, ), if (value.type == FTextTypeEnum.dataset && value.datasetName != null) - CDropdown( - value: widget.page.datasets + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .firstWhere( + (final element) => + element.getName == value.datasetName, + ) + .getMap + .first + .keys + .toSet() + .contains(value.datasetAttr) + ? value.datasetAttr + : null, + items: state.datasets .firstWhere( (final element) => element.getName == value.datasetName, ) @@ -163,25 +195,16 @@ class AddDataElementState extends State { .first .keys .toSet() - .contains(value.datasetAttr) - ? value.datasetAttr - : null, - items: widget.page.datasets - .firstWhere( - (final element) => element.getName == value.datasetName, - ) - .getMap - .first - .keys - .toSet() - .toList(), - onChange: (final newValue) { - setState(() { - databaseAttribute = newValue!; - }); - final old = value; - value.datasetAttr = newValue; - widget.callback(value.toJson(), old.toJson()); + .toList(), + onChange: (final newValue) { + setState(() { + databaseAttribute = newValue!; + }); + final old = value; + value.datasetAttr = newValue; + widget.callback(value.toJson(), old.toJson()); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/actions/validator.dart b/teta_widgets/lib/src/elements/controls/atoms/actions/validator.dart index 126e01d2..6cf6da2d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/actions/validator.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/actions/validator.dart @@ -1,17 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/index.dart'; class AValidatorControl extends StatelessWidget { const AValidatorControl({ - final Key? key, - required this.page, required this.action, required this.callback, + final Key? key, }) : super(key: key); - final PageObject page; final FActionElement action; final Function(FActionElement, FActionElement) callback; @@ -27,28 +26,33 @@ class AValidatorControl extends StatelessWidget { color: Palette.txtPrimary.withOpacity(0.6), ), const Gap(Grid.medium), - CDropdown( - value: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == action.stateName, - ) != - -1 - ? action.stateName - : null, - items: page.states - .where((final element) => element.type == VariableType.string) - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = action; - action.stateName = newValue; - callback(action, old); - } + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == action.stateName, + ) != + -1 + ? action.stateName + : null, + items: state.states + .where((final element) => element.type == VariableType.string) + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + final old = action; + action.stateName = newValue; + callback(action, old); + } + }, + ); }, ), const Gap(Grid.medium), @@ -59,30 +63,36 @@ class AValidatorControl extends StatelessWidget { color: Palette.txtPrimary.withOpacity(0.6), ), const Gap(Grid.medium), - CDropdown( - value: page.states - .where( - (final element) => element.type == VariableType.string, - ) - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == action.stateName2, - ) != - -1 - ? action.stateName2 - : null, - items: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = action; - action.stateName2 = newValue; - callback(action, old); - } + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .where( + (final element) => + element.type == VariableType.string, + ) + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == action.stateName2, + ) != + -1 + ? action.stateName2 + : null, + items: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + final old = action; + action.stateName2 = newValue; + callback(action, old); + } + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/airtable/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/airtable/delete.dart index 5989e947..1594621a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/airtable/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/airtable/delete.dart @@ -8,17 +8,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AirtableDeleteControl extends StatelessWidget { const AirtableDeleteControl({ - required this.prj, - required this.node, - required this.page, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final CNode node; - final PageObject page; final FActionElement action; final Function() callback; @@ -45,9 +39,7 @@ class AirtableDeleteControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.airtableRecordName ?? FTextTypeInput(), - page: page, title: 'Record name', callBack: (final value, final old) { action.airtableRecordName = value; @@ -55,9 +47,7 @@ class AirtableDeleteControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback.call(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/airtable/insert.dart b/teta_widgets/lib/src/elements/controls/atoms/airtable/insert.dart index 5a4528c8..563512f2 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/airtable/insert.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/airtable/insert.dart @@ -8,17 +8,10 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AirtableInsertControl extends StatelessWidget { const AirtableInsertControl({ - required this.prj, - required this.node, - required this.page, required this.action, required this.callback, final Key? key, }) : super(key: key); - - final ProjectObject prj; - final CNode node; - final PageObject page; final FActionElement action; final Function() callback; @@ -45,9 +38,7 @@ class AirtableInsertControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.airtableRecordName ?? FTextTypeInput(), - page: page, title: 'Record name', callBack: (final value, final old) { action.airtableRecordName = value; @@ -55,9 +46,7 @@ class AirtableInsertControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback.call(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/airtable/update.dart b/teta_widgets/lib/src/elements/controls/atoms/airtable/update.dart index 900acb1c..ff886f31 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/airtable/update.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/airtable/update.dart @@ -8,17 +8,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AirtableUpdateControl extends StatelessWidget { const AirtableUpdateControl({ - required this.prj, - required this.node, - required this.page, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final CNode node; - final PageObject page; final FActionElement action; final Function() callback; @@ -45,9 +39,7 @@ class AirtableUpdateControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.airtableRecordName ?? FTextTypeInput(), - page: page, title: 'Record name', callBack: (final value, final old) { action.airtableRecordName = value; @@ -55,9 +47,7 @@ class AirtableUpdateControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback.call(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/aligns.dart b/teta_widgets/lib/src/elements/controls/atoms/aligns.dart index c21b18f2..57855a63 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/aligns.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/aligns.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AlignsControl extends StatefulWidget { const AlignsControl({ - required this.node, required this.align, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FAlign align; final Function(FAlign, FAlign) callBack; @@ -52,7 +50,7 @@ class AlignsControlState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(ctx: context), + builder: (final ctx) => DevicesDialog(), ); }, child: Image.asset( diff --git a/teta_widgets/lib/src/elements/controls/atoms/apicalls/apicalls.dart b/teta_widgets/lib/src/elements/controls/atoms/apicalls/apicalls.dart index 07d0063d..4191e125 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/apicalls/apicalls.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/apicalls/apicalls.dart @@ -14,17 +14,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class ApiCallsControl extends StatelessWidget { const ApiCallsControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -35,7 +29,6 @@ class ApiCallsControl extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ ApiCallsRequestControl( - node: node, //TODO request name must be unique! kasapiniz requestName: action.apiCallsRequestName ?? '', callBack: (final value, final old, final apiCallsSelectedRequest) { @@ -53,10 +46,8 @@ class ApiCallsControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestExpectedStatusCode ?? FTextTypeInput(), - page: page, title: 'Status Code', callBack: (final value, final old) { action.customHttpRequestExpectedStatusCode = value; @@ -73,9 +64,7 @@ class ApiCallsControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.apiCallsResponseName ?? FTextTypeInput(), - page: page, title: 'Response Name', callBack: (final value, final old) { action.apiCallsResponseName = value; @@ -85,8 +74,6 @@ class ApiCallsControl extends StatelessWidget { ), const Gap(Grid.small), HttpParamsControl( - node: node, - page: page, title: 'Add Dynamic Value', list: action.apiCallsDynamicValue ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart index 890ad078..1b34a11c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart @@ -16,13 +16,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class ApiCallsRequestControl extends StatefulWidget { const ApiCallsRequestControl({ - required this.node, required this.requestName, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String? requestName; final Function(String, String?, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart index 7fa4dbe6..a263ed3e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart @@ -12,22 +12,18 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AudioControllerControl extends StatefulWidget { const AudioControllerControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; @override - AudioControllerControlState createState() => AudioControllerControlState(); + AudioControllerControlState create tate() => AudioControllerControlState(); } class AudioControllerControlState extends State { diff --git a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart index bf9df863..8ee343b6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart @@ -16,13 +16,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class BorderRadiusControl extends StatefulWidget { const BorderRadiusControl({ - required this.node, required this.borderRadius, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FBorderRadius borderRadius; final Function(Map, Map) callBack; @@ -31,15 +29,12 @@ class BorderRadiusControl extends StatefulWidget { } class BorderRadiusControlState extends State { - int? nodeId; - bool? isUpdated; List? radius; List controllers = []; bool isLinked = true; @override void initState() { - nodeId = widget.node.nid; radius = widget.borderRadius.radius; for (var i = 0; i < 4; i++) { controllers.add(TextEditingController()); @@ -54,40 +49,31 @@ class BorderRadiusControlState extends State { Widget build(final BuildContext context) { return BlocListener( listener: (final context, final device) { - setState(() { - isUpdated = true; - if (device.identifier.type == DeviceType.phone) { - radius = widget.borderRadius.radius; - } else if (device.identifier.type == DeviceType.tablet) { - radius = widget.borderRadius.radiusTablet; - } else { - radius = widget.borderRadius.radiusDesktop; - } - for (var i = 0; i < 4; i++) { - controllers[i].text = '${radius![i]}'; - } - }); + if (device.identifier.type == DeviceType.phone) { + radius = widget.borderRadius.radius; + } else if (device.identifier.type == DeviceType.tablet) { + radius = widget.borderRadius.radiusTablet; + } else { + radius = widget.borderRadius.radiusDesktop; + } + for (var i = 0; i < 4; i++) { + controllers[i].text = '${radius![i]}'; + } }, child: BlocBuilder( builder: (final context, final device) => BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - if (device.identifier.type == DeviceType.phone) { - radius = widget.borderRadius.radius; - } else if (device.identifier.type == DeviceType.tablet) { - radius = widget.borderRadius.radiusTablet; - } else { - radius = widget.borderRadius.radiusDesktop; - } - for (var i = 0; i < 4; i++) { - controllers[i].text = '${radius![i]}'; - } - }); - nodeId = state.first.nid; + if (device.identifier.type == DeviceType.phone) { + radius = widget.borderRadius.radius; + } else if (device.identifier.type == DeviceType.tablet) { + radius = widget.borderRadius.radiusTablet; + } else { + radius = widget.borderRadius.radiusDesktop; + } + for (var i = 0; i < 4; i++) { + controllers[i].text = '${radius![i]}'; } } }, @@ -110,8 +96,7 @@ class BorderRadiusControlState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => - DevicesDialog(ctx: context), + builder: (final ctx) => DevicesDialog(), ); }, child: Image.asset( diff --git a/teta_widgets/lib/src/elements/controls/atoms/borders.dart b/teta_widgets/lib/src/elements/controls/atoms/borders.dart index d60166e3..9514e6d1 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/borders.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/borders.dart @@ -19,13 +19,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class BordersControl extends StatefulWidget { const BordersControl({ - required this.node, required this.borders, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FBorder borders; final Function(Map, Map) callBack; @@ -34,118 +32,101 @@ class BordersControl extends StatefulWidget { } class BordersControlState extends State { - int? nodeId; - bool? isUpdated; bool isLinked = true; @override void initState() { - nodeId = widget.node.nid; isLinked = widget.borders.style?.style == BorderStyle.solid; super.initState(); } @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } - }, - child: BlocBuilder>( - builder: (final context, final state) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 12, left: 4), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const TParagraph( - 'Borders', - ), - GestureDetector( - onTap: () { - setState(() { - isLinked = !isLinked; - }); - final old = widget.borders.toJson(); - widget.borders.style ??= - FBorderStyle(style: BorderStyle.none); - if (widget.borders.style!.style == BorderStyle.none) { - widget.borders.style!.style = BorderStyle.solid; - } else { - widget.borders.style!.style = BorderStyle.none; - } - widget.callBack(widget.borders.toJson(), old); - }, - child: HoverWidget( - hoverChild: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - ), - ), - child: Icon( - isLinked ? FeatherIcons.eye : FeatherIcons.eyeOff, - size: 24, + return BlocBuilder>( + builder: (final context, final state) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 12, left: 4), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const TParagraph( + 'Borders', + ), + GestureDetector( + onTap: () { + setState(() { + isLinked = !isLinked; + }); + final old = widget.borders.toJson(); + widget.borders.style ??= + FBorderStyle(style: BorderStyle.none); + if (widget.borders.style!.style == BorderStyle.none) { + widget.borders.style!.style = BorderStyle.solid; + } else { + widget.borders.style!.style = BorderStyle.none; + } + widget.callBack(widget.borders.toJson(), old); + }, + child: HoverWidget( + hoverChild: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( color: Colors.white, ), ), - onHover: (final e) {}, - child: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.transparent, - ), - ), - child: Icon( - isLinked ? FeatherIcons.eye : FeatherIcons.eyeOff, - size: 24, - color: Colors.white, + child: Icon( + isLinked ? FeatherIcons.eye : FeatherIcons.eyeOff, + size: 24, + color: Colors.white, + ), + ), + onHover: (final e) {}, + child: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( + color: Colors.transparent, ), ), + child: Icon( + isLinked ? FeatherIcons.eye : FeatherIcons.eyeOff, + size: 24, + color: Colors.white, + ), ), ), - ], - ), - ), - Margins( - node: widget.node, - title: 'Width', - value: widget.borders.width ?? FMargins(), - callBack: (final width, final old) { - final old = widget.borders.toJson(); - widget.borders.width ??= FMargins(); - widget.borders.width = FMargins.fromJson(width); - widget.callBack(widget.borders.toJson(), old); - }, + ), + ], ), - FillControl( - node: widget.node, - callBack: (final fill, final isStyled, final old) { - final old = widget.borders.toJson(); - widget.borders.fill = fill; - widget.callBack(widget.borders.toJson(), old); - }, - fill: widget.borders.fill ?? FFill(), - isImageEnabled: false, - isNoneEnabled: false, - type: FillTypeControlType.onlySolid, - ), - ], - ); - }, - ), + ), + Margins( + title: 'Width', + value: widget.borders.width ?? FMargins(), + callBack: (final width, final old) { + final old = widget.borders.toJson(); + widget.borders.width ??= FMargins(); + widget.borders.width = FMargins.fromJson(width); + widget.callBack(widget.borders.toJson(), old); + }, + ), + FillControl( + callBack: (final fill, final isStyled, final old) { + final old = widget.borders.toJson(); + widget.borders.fill = fill; + widget.callBack(widget.borders.toJson(), old); + }, + fill: widget.borders.fill ?? FFill(), + isImageEnabled: false, + isNoneEnabled: false, + type: FillTypeControlType.onlySolid, + ), + ], + ); + }, ); } } diff --git a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart index 5c4ecf6f..e0c407eb 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class CameraControllerControl extends StatefulWidget { const CameraControllerControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart index a4f9dae2..24b47f39 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class CMSCollectionControl extends StatefulWidget { const CMSCollectionControl({ - required this.node, required this.collectionId, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String? collectionId; final Function(String, String?) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/color.dart b/teta_widgets/lib/src/elements/controls/atoms/color.dart index 31367573..db159680 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/color.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/color.dart @@ -17,14 +17,12 @@ class SingleColorControl extends StatefulWidget { const SingleColorControl({ required this.title, required this.color, - required this.node, required this.callBack, final Key? key, }) : super(key: key); final String title; final String color; - final CNode node; final Function(String, String) callBack; @override @@ -32,9 +30,6 @@ class SingleColorControl extends StatefulWidget { } class SingleColorControlState extends State { - int? nodeId; - bool? isUpdated; - String? value; bool isVisible = true; TextEditingController controller = TextEditingController(); FFill? tempFill; @@ -42,7 +37,6 @@ class SingleColorControlState extends State { @override void initState() { - nodeId = widget.node.nid; controller.text = widget.color; tempColor = widget.color; super.initState(); @@ -58,109 +52,71 @@ class SingleColorControlState extends State { controller.text = tempColor; isUpdated = false; }*/ - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.color; - }); - nodeId = state.first.nid; - } - } - }, - child: BlocBuilder>( - builder: (final context, final state) { - //updateState(state); - return Row( - children: [ - Padding( - padding: const EdgeInsets.only(right: 4), - child: GestureDetector( - onTap: () { - showPicker(context); - }, - child: HoverWidget( - hoverChild: Container( - width: 48, - height: 48, - decoration: BoxDecoration( - color: HexColor(widget.color), - borderRadius: BorderRadius.circular(8), - border: Border.all(color: Colors.white), - ), - ), - onHover: (final e) {}, - child: Container( - width: 48, - height: 48, - decoration: BoxDecoration( - color: HexColor(widget.color), - borderRadius: BorderRadius.circular(8), - border: Border.all(color: Colors.transparent), - ), + return BlocBuilder>( + builder: (final context, final state) { + //updateState(state); + return Row( + children: [ + Padding( + padding: const EdgeInsets.only(right: 4), + child: GestureDetector( + onTap: () { + showPicker(context); + }, + child: HoverWidget( + hoverChild: Container( + width: 48, + height: 48, + decoration: BoxDecoration( + color: HexColor(widget.color), + borderRadius: BorderRadius.circular(8), + border: Border.all(color: Colors.white), ), ), - ), - ), - Expanded( - child: CMiniTextField( - controller: controller, - placeholder: tempColor, - hpadding: 4, - callBack: (final text) { - final hexCode = text.replaceAll('#', ''); - if (hexCode.length == 3) { - final hexColor = - RegExp(r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'); - if (hexColor.hasMatch(hexCode)) { - final old = widget.color; - final color = '$hexCode$hexCode'; - widget.callBack(color, old); - } - } - if (hexCode.length == 6) { - final hexColor = - RegExp(r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'); - if (hexColor.hasMatch(hexCode)) { - final old = widget.color; - final color = hexCode; - widget.callBack(color, old); - } - } - }, - ), - ), - /*GestureDetector( - onTap: () { - setState(() { - isVisible = !isVisible; - fill = fill; - widget.callBack("00$fill"); - }); - }, + onHover: (final e) {}, child: Container( - width: 40, + width: 48, height: 48, decoration: BoxDecoration( - border: Border.all(width: 1, color: Colors.black), + color: HexColor(widget.color), borderRadius: BorderRadius.circular(8), - color: Colors.white10, - ), - child: Center( - child: Icon( - isVisible ? FeatherIcons.eye : FeatherIcons.eyeOff, - size: 24, - color: Colors.white, - ), + border: Border.all(color: Colors.transparent), ), ), - ),*/ - ], - ); - }, - ), + ), + ), + ), + Expanded( + child: CMiniTextField( + controller: controller, + placeholder: tempColor, + hpadding: 4, + callBack: (final text) { + final hexCode = text.replaceAll('#', ''); + if (hexCode.length == 3) { + final hexColor = + RegExp(r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'); + if (hexColor.hasMatch(hexCode)) { + final old = widget.color; + final color = '$hexCode$hexCode'; + widget.callBack(color, old); + } + } + if (hexCode.length == 6) { + final hexColor = + RegExp(r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'); + if (hexColor.hasMatch(hexCode)) { + final old = widget.color; + final color = hexCode; + widget.callBack(color, old); + } + } + }, + ), + ), + ], + ); + }, ); } @@ -179,7 +135,6 @@ class SingleColorControlState extends State { final old = widget.color; setState(() { tempColor = color.value.toRadixString(16).substring(2, 8); - isUpdated = true; }); final valueColor = color.value.toRadixString(16).substring(2, 8); controller.text = valueColor; @@ -191,7 +146,6 @@ class SingleColorControlState extends State { context: context, builder: (final context) { return ColorPickerDialog( - context: context, color: tempColor!, fill: null, callback: updateColor, diff --git a/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart b/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart index 6c1e3253..512b869a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart @@ -14,16 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class ValueOfConditionControl extends StatefulWidget { /// Constructor const ValueOfConditionControl({ - required this.node, - required this.page, required this.title, required this.valueOfCond, required this.callBack, final Key? key, }) : super(key: key); - - final CNode node; - final PageObject page; final String title; final FTextTypeInput valueOfCond; final Function(FTextTypeInput, FTextTypeInput) callBack; @@ -33,39 +28,23 @@ class ValueOfConditionControl extends StatefulWidget { } class ValueOfConditionControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; - FTextTypeEnum typeOfInput = FTextTypeEnum.text; @override void initState() { - try { - nodeId = widget.node.nid; - text = widget.valueOfCond.value ?? ''; - controller.text = text!; - typeOfInput = widget.valueOfCond.type!; - databaseName = widget.valueOfCond.datasetName!; - databaseAttribute = widget.valueOfCond.datasetAttr!; - } catch (_) {} super.initState(); + controller.text = widget.valueOfCond.value ?? ''; + databaseName = widget.valueOfCond.datasetName!; + databaseAttribute = widget.valueOfCond.datasetAttr!; } @override Widget build(final BuildContext context) { - //controller.text = widget.node.valueOfCond!.value ?? ''; return BlocListener>( listener: (final context, final state) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.valueOfCond.value ?? ''; - }); - nodeId = state.first.nid; - } + controller.text = widget.valueOfCond.value ?? ''; }, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -130,147 +109,179 @@ class ValueOfConditionControlState extends State { widget.callBack(widget.valueOfCond, old); }, ), - if (widget.valueOfCond.type == FTextTypeEnum.param) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.valueOfCond.paramName, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - final old = widget.valueOfCond; - widget.valueOfCond.paramName = newValue; - widget.callBack(widget.valueOfCond, old); - }, - isDense: true, - isExpanded: true, - items: widget.page.params - .map((final e) => e.name) - .map>((final value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, - ), - ); - }).toList(), - ), - ), - if (widget.valueOfCond.type == FTextTypeEnum.state) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.valueOfCond.stateName, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - final old = widget.valueOfCond; - widget.valueOfCond.stateName = newValue; - widget.callBack(widget.valueOfCond, old); - }, - isDense: true, - isExpanded: true, - items: widget.page.states - .map((final e) => e.name) - .map>((final value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, - ), - ); - }).toList(), - ), - ), - if (widget.valueOfCond.type == FTextTypeEnum.dataset) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.valueOfCond.datasetName, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - setState(() { - databaseName = newValue!; - }); - final old = widget.valueOfCond; - widget.valueOfCond.datasetName = newValue; - widget.callBack(widget.valueOfCond, old); - }, - isDense: true, - isExpanded: true, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, - ), - ); - }).toList(), - ), - ), - if (widget.valueOfCond.type == FTextTypeEnum.dataset && - widget.valueOfCond.datasetName != null) - Container( - margin: const EdgeInsets.only(top: 8), - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.valueOfCond.datasetAttr, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - setState(() { - databaseAttribute = newValue!; - }); - final old = widget.valueOfCond; - widget.valueOfCond.datasetAttr = newValue; - widget.callBack(widget.valueOfCond, old); - }, - isDense: true, - isExpanded: true, - items: widget.page.datasets - .firstWhere( - (final element) => - element.getName == widget.valueOfCond.datasetName, - ) - .getMap - .first - .keys - .map((final key) => key) - .toSet() - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, - ), - ); - }).toList(), - ), - ), + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + if (widget.valueOfCond.type != FTextTypeEnum.param) { + return const SizedBox(); + } + return Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: widget.valueOfCond.paramName, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + final old = widget.valueOfCond; + widget.valueOfCond.paramName = newValue; + widget.callBack(widget.valueOfCond, old); + }, + isDense: true, + isExpanded: true, + items: state.params + .map((final e) => e.name) + .map>((final value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), + ); + }, + ), + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + if (widget.valueOfCond.type != FTextTypeEnum.state) { + return const SizedBox(); + } + return Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: widget.valueOfCond.stateName, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + final old = widget.valueOfCond; + widget.valueOfCond.stateName = newValue; + widget.callBack(widget.valueOfCond, old); + }, + isDense: true, + isExpanded: true, + items: state.states + .map((final e) => e.name) + .map>((final value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), + ); + }, + ), + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + if (widget.valueOfCond.type != FTextTypeEnum.dataset) { + return const SizedBox(); + } + return Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: widget.valueOfCond.datasetName, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + setState(() { + databaseName = newValue!; + }); + final old = widget.valueOfCond; + widget.valueOfCond.datasetName = newValue; + widget.callBack(widget.valueOfCond, old); + }, + isDense: true, + isExpanded: true, + items: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), + ); + }, + ), + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + if (widget.valueOfCond.type == FTextTypeEnum.dataset && + widget.valueOfCond.datasetName != null) { + return Container( + margin: const EdgeInsets.only(top: 8), + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: widget.valueOfCond.datasetAttr, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + setState(() { + databaseAttribute = newValue!; + }); + final old = widget.valueOfCond; + widget.valueOfCond.datasetAttr = newValue; + widget.callBack(widget.valueOfCond, old); + }, + isDense: true, + isExpanded: true, + items: state.datasets + .firstWhere( + (final element) => + element.getName == widget.valueOfCond.datasetName, + ) + .getMap + .first + .keys + .map((final key) => key) + .toSet() + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), + ); + } + return const SizedBox(); + }, + ), ], ), ); diff --git a/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart b/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart index 8901927a..3d043112 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class CrossAxisAlignmentControls extends StatefulWidget { const CrossAxisAlignmentControls({ - required this.node, required this.crossAxisAlignment, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FCrossAxisAlignment crossAxisAlignment; final Function(FCrossAxisAlignment, FCrossAxisAlignment) callBack; @@ -29,14 +27,11 @@ class CrossAxisAlignmentControls extends StatefulWidget { class CrossAxisAlignmentControlsState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.crossAxisAlignment.getString(context); } @@ -45,13 +40,9 @@ class CrossAxisAlignmentControlsState return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.crossAxisAlignment.getString(context); - }); - nodeId = state.first.nid; - } + setState(() { + dropdown = widget.crossAxisAlignment.getString(context); + }); } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/dataset.dart b/teta_widgets/lib/src/elements/controls/atoms/dataset.dart index 3776a940..858f158f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/dataset.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/dataset.dart @@ -12,18 +12,14 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class DatasetControl extends StatefulWidget { const DatasetControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, this.isAttrRequired, }) : super(key: key); - final CNode node; final FDataset value; - final PageObject page; final String title; final bool? isAttrRequired; final Function(FDataset, FDataset) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/db_map.dart b/teta_widgets/lib/src/elements/controls/atoms/db_map.dart index 18162d95..56cd73c6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/db_map.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/db_map.dart @@ -14,16 +14,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class DBMapControl extends StatefulWidget { const DBMapControl({ - required this.node, required this.list, - required this.page, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final List list; - final PageObject page; final Function(List, List) callBack; @override @@ -31,14 +27,11 @@ class DBMapControl extends StatefulWidget { } class DBMapControlState extends State { - int? nodeId; - bool? isUpdated; late TextEditingController controller; @override void initState() { controller = TextEditingController(); - nodeId = widget.node.nid; super.initState(); } @@ -46,14 +39,7 @@ class DBMapControlState extends State { Widget build(final BuildContext context) { return BlocListener>( listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } + if (state.isNotEmpty) {} }, child: Padding( padding: const EdgeInsets.only(top: 8), @@ -130,9 +116,7 @@ class DBMapControlState extends State { borderRadius: BorderRadius.circular(8), ), child: MapElementControl( - node: widget.node, value: e, - page: widget.page, callBack: (final value, final old) { final old = widget.list; final index = widget.list.indexOf(e); diff --git a/teta_widgets/lib/src/elements/controls/atoms/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/delete.dart index 09b5f433..2302589d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/delete.dart @@ -15,12 +15,10 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class DeleteControl extends StatefulWidget { const DeleteControl({ - required this.node, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final Function(bool) callBack; @override diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill.dart b/teta_widgets/lib/src/elements/controls/atoms/fill.dart index bea9c7bf..4b0a38ae 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill.dart @@ -22,7 +22,6 @@ enum FillTypeControlType { class FillControl extends StatefulWidget { const FillControl({ - required this.node, required this.callBack, required this.fill, required this.isImageEnabled, @@ -33,7 +32,6 @@ class FillControl extends StatefulWidget { final Key? key, }) : super(key: key); - final CNode node; final String? title; final String? color; final FFill fill; diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart index 9fca2420..dea40bcb 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/asset.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class AssetFillControl extends StatefulWidget { const AssetFillControl({ - required this.node, required this.fill, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FFill fill; final Function(FFill, bool, FFill) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart index cd432d99..abb366c3 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart @@ -17,7 +17,6 @@ class ImageFillControl extends StatefulWidget { const ImageFillControl({ required this.title, required this.fill, - required this.node, required this.isStyled, required this.callBack, final Key? key, @@ -25,7 +24,6 @@ class ImageFillControl extends StatefulWidget { final FFill fill; final String title; - final CNode node; final bool isStyled; final Function(FFill, bool, FFill) callBack; @@ -34,15 +32,12 @@ class ImageFillControl extends StatefulWidget { } class ImageFillControlState extends State { - int? nodeId; - bool? isUpdated; String? value; bool isVisible = true; TextEditingController controller = TextEditingController(); @override void initState() { - nodeId = widget.node.nid; controller.text = widget.fill.levels!.first.color; super.initState(); } @@ -52,13 +47,7 @@ class ImageFillControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.fill.levels!.first.color; - }); - nodeId = state.first.nid; - } + controller.text = widget.fill.levels!.first.color; } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart index c8a303c1..b5995e02 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart @@ -20,7 +20,6 @@ class LinearFillControl extends StatefulWidget { const LinearFillControl({ required this.title, required this.fill, - required this.node, required this.isStyled, required this.callBack, final Key? key, @@ -29,7 +28,6 @@ class LinearFillControl extends StatefulWidget { final FFill fill; final String title; final bool isStyled; - final CNode node; final Function(FFill, bool, FFill) callBack; @override @@ -37,7 +35,6 @@ class LinearFillControl extends StatefulWidget { } class ColorControlState extends State { - bool isUpdated = false; String? tempColor; int selectedElementIndex = 0; Alignment? align; @@ -52,7 +49,6 @@ class ColorControlState extends State { Widget build(final BuildContext context) { return BlocBuilder>( builder: (final context, final state) { - //updateState(state); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -273,7 +269,6 @@ class ColorControlState extends State { element: e, fill: widget.fill, index: widget.fill.levels?.indexOf(e) ?? 0, - node: widget.node, callBackIndex: (final index, final controller) { setState(() { selectedElementIndex = index; @@ -311,11 +306,9 @@ class ColorControlState extends State { void _updateColor(final Color color) { final old = FFill().fromJson(widget.fill.toJson()); - setState(() { - widget.fill.levels![selectedElementIndex].color = - color.value.toRadixString(16).substring(2, 8); - isUpdated = true; - }); + + widget.fill.levels![selectedElementIndex].color = + color.value.toRadixString(16).substring(2, 8); widget.callBack(widget.fill, false, old); } @@ -332,7 +325,6 @@ class ColorControlState extends State { context: context, builder: (final context) { return ColorPickerDialog( - context: context, color: tempColor!, fill: widget.fill, callback: (final color) { @@ -481,7 +473,6 @@ class FillElement extends StatefulWidget { required this.element, required this.fill, required this.index, - required this.node, required this.callBackIndex, required this.callBack, final Key? key, @@ -490,7 +481,6 @@ class FillElement extends StatefulWidget { final FFill fill; final FFillElement element; final int index; - final CNode node; final Function(int, TextEditingController) callBackIndex; final Function(FFill, FFill) callBack; @@ -502,13 +492,10 @@ class FillElementState extends State { TextEditingController editingController = TextEditingController(); TextEditingController stopController = TextEditingController(); TextEditingController opacityController = TextEditingController(); - int? nodeId; - bool? isUpdated; @override void initState() { super.initState(); - nodeId = widget.node.nid; editingController.text = widget.element.color; stopController.text = '${widget.element.stop}'; opacityController.text = '${widget.element.opacity}'; @@ -519,14 +506,8 @@ class FillElementState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - editingController.text = widget.element.color; - stopController.text = '${widget.element.stop}'; - }); - nodeId = state.first.nid; - } + editingController.text = widget.element.color; + stopController.text = '${widget.element.stop}'; } }, child: Padding( diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart index 075c544c..bab1ddce 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart @@ -18,7 +18,6 @@ class RadialFillControl extends StatefulWidget { const RadialFillControl({ required this.title, required this.fill, - required this.node, required this.isStyled, required this.callBack, final Key? key, @@ -27,7 +26,6 @@ class RadialFillControl extends StatefulWidget { final FFill fill; final String title; final bool isStyled; - final CNode node; final Function(FFill, bool, FFill) callBack; @override @@ -111,7 +109,6 @@ class ColorControlState extends State { element: e, fill: widget.fill, index: widget.fill.levels!.indexOf(e), - node: widget.node, callBackIndex: (final index, final controller) { setState(() { selectedElementIndex = index; @@ -180,7 +177,6 @@ class ColorControlState extends State { context: context, builder: (final context) { return ColorPickerDialog( - context: context, color: tempColor!, fill: widget.fill, callback: (final color) { @@ -338,7 +334,6 @@ class FillElement extends StatefulWidget { required this.element, required this.fill, required this.index, - required this.node, required this.callBackIndex, required this.callBack, final Key? key, @@ -347,7 +342,6 @@ class FillElement extends StatefulWidget { final FFill fill; final FFillElement element; final int index; - final CNode node; final Function(int, TextEditingController) callBackIndex; final Function(FFill, FFill) callBack; @@ -359,13 +353,10 @@ class FillElementState extends State { TextEditingController editingController = TextEditingController(); TextEditingController stopController = TextEditingController(); TextEditingController opacityController = TextEditingController(); - int? nodeId; - bool? isUpdated; @override void initState() { super.initState(); - nodeId = widget.node.nid; editingController.text = widget.element.color; stopController.text = '${widget.element.stop}'; opacityController.text = '${widget.element.opacity}'; @@ -376,14 +367,8 @@ class FillElementState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - editingController.text = widget.element.color; - stopController.text = '${widget.element.stop}'; - }); - nodeId = state.first.nid; - } + editingController.text = widget.element.color; + stopController.text = '${widget.element.stop}'; } }, child: Padding( diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart index 008dabf9..c5862046 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart @@ -16,7 +16,6 @@ class SolidFillControl extends StatefulWidget { const SolidFillControl({ required this.title, required this.fill, - required this.node, required this.isStyled, required this.callBack, this.color, @@ -28,7 +27,6 @@ class SolidFillControl extends StatefulWidget { final String title; final String? color; final double? opacity; - final CNode node; final bool isStyled; final Function(FFill, bool, FFill) callBack; @@ -37,9 +35,6 @@ class SolidFillControl extends StatefulWidget { } class SolidFillControlState extends State { - int? nodeId; - bool? isUpdated; - String? value; bool isVisible = true; TextEditingController controller = TextEditingController(); TextEditingController opacityController = TextEditingController(); @@ -48,19 +43,16 @@ class SolidFillControlState extends State { @override void initState() { - try { - nodeId = widget.node.nid; - if (widget.color != null) { - controller.text = widget.color ?? ''; - opacityController.text = '${widget.opacity}'; - tempColor = widget.color; - } else { - controller.text = widget.fill!.get(context).levels!.first.color; - opacityController.text = - '${widget.fill!.get(context).levels!.first.opacity}'; - tempColor = widget.fill!.get(context).levels!.first.color; - } - } catch (_) {} + if (widget.color != null) { + controller.text = widget.color ?? ''; + opacityController.text = '${widget.opacity}'; + tempColor = widget.color; + } else { + controller.text = widget.fill!.get(context).levels!.first.color; + opacityController.text = + '${widget.fill!.get(context).levels!.first.opacity}'; + tempColor = widget.fill!.get(context).levels!.first.color; + } super.initState(); } @@ -79,22 +71,15 @@ class SolidFillControlState extends State { BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - if (widget.color != null) { - controller.text = widget.color ?? ''; - controller.text = '${widget.opacity}'; - tempColor = widget.color; - } else { - controller.text = - widget.fill!.get(context).levels!.first.color; - opacityController.text = - '${widget.fill!.get(context).levels!.first.opacity}'; - tempColor = widget.fill!.get(context).levels!.first.color; - } - }); - nodeId = state.first.nid; + if (widget.color != null) { + controller.text = widget.color ?? ''; + controller.text = '${widget.opacity}'; + tempColor = widget.color; + } else { + controller.text = widget.fill!.get(context).levels!.first.color; + opacityController.text = + '${widget.fill!.get(context).levels!.first.opacity}'; + tempColor = widget.fill!.get(context).levels!.first.color; } } }, @@ -247,7 +232,6 @@ class SolidFillControlState extends State { final old = FFill().fromJson(widget.fill!.toJson()); setState(() { tempColor = color.value.toRadixString(16).substring(2, 8); - isUpdated = true; }); widget.fill!.levels!.first.color = color.value.toRadixString(16).substring(2, 8); @@ -263,7 +247,6 @@ class SolidFillControlState extends State { return BlocProvider.value( value: bloc, child: ColorPickerDialog( - context: context, color: tempColor!, fill: widget.fill!, callback: updateColor, diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart index a5d7b92a..19932242 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart @@ -14,7 +14,6 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class StyleFillControl extends StatefulWidget { const StyleFillControl({ required this.onlySolid, - required this.node, required this.model, required this.fill, required this.callBack, @@ -22,7 +21,6 @@ class StyleFillControl extends StatefulWidget { }) : super(key: key); final bool onlySolid; - final CNode node; final ColorStyleModel model; final FFill fill; final Function(FFill, bool, FFill) callBack; @@ -49,11 +47,11 @@ class StyleFillControlState extends State { .where( (final element) => (widget.onlySolid && - (element.fill!.type == FFillType.solid || - element.fill!.type == FFillType.none)) || + (element.fill.type == FFillType.solid || + element.fill.type == FFillType.none)) || !widget.onlySolid, ) - .map((final e) => e.name!) + .map((final e) => e.name) .toList(), onChange: (final value) { ColorStyleModel? model; diff --git a/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart b/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart index 64288296..cc9715c6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart @@ -18,10 +18,8 @@ class FirestoreParameterControl extends StatefulWidget { required this.value, required this.callBack, final Key? key, - this.node, }) : super(key: key); - final CNode? node; final PageObject page; final String title; final FTextTypeInput value; @@ -32,24 +30,15 @@ class FirestoreParameterControl extends StatefulWidget { } class ParameterState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; - FTextTypeEnum typeOfInput = FTextTypeEnum.text; @override void initState() { - try { - nodeId = widget.node?.nid; - text = widget.value.value ?? ''; - controller.text = text!; - typeOfInput = widget.value.type!; - databaseName = widget.value.datasetName!; - databaseAttribute = widget.value.datasetAttr!; - } catch (_) {} + controller.text = widget.value.value ?? ''; + databaseName = widget.value.datasetName!; + databaseAttribute = widget.value.datasetAttr!; super.initState(); } @@ -59,13 +48,7 @@ class ParameterState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.value.value ?? ''; - }); - nodeId = state.first.nid; - } + controller.text = widget.value.value ?? ''; } }, child: Container( @@ -125,64 +108,117 @@ class ParameterState extends State { }, ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params - .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .map((final e) => e.get as String) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; + } + return previous.params != current.params; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.params + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: + state.params.map((final e) => e.get as String).toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states - .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .map((final e) => e.get as String) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; + } + return previous.states != current.states; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: + state.states.map((final e) => e.get as String).toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.dataset) - CDropdown( - value: widget.page.datasets + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; + } + return previous.datasets != current.datasets; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .contains(widget.value.datasetName) + ? widget.value.datasetName + : null, + items: state.datasets .map((final e) => e.getName) .where((final element) => element != 'null') - .contains(widget.value.datasetName) - ? widget.value.datasetName - : null, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - setState(() { - databaseName = newValue!; - }); - final old = widget.value; - widget.value.datasetName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + setState(() { + databaseName = newValue!; + }); + final old = widget.value; + widget.value.datasetName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.dataset && widget.value.datasetName != null) Padding( padding: EI.smT, - child: CDropdown( - value: widget.page.datasets + child: BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; + } + return previous.datasets != current.datasets; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .firstWhere( + (final element) => + element.getName == widget.value.datasetName, + ) + .getMap + .first + .keys + .map((final key) => key) + .toSet() + .contains(widget.value.datasetAttr) + ? widget.value.datasetAttr + : null, + items: state.datasets .firstWhere( (final element) => element.getName == widget.value.datasetName, @@ -192,27 +228,16 @@ class ParameterState extends State { .keys .map((final key) => key) .toSet() - .contains(widget.value.datasetAttr) - ? widget.value.datasetAttr - : null, - items: widget.page.datasets - .firstWhere( - (final element) => - element.getName == widget.value.datasetName, - ) - .getMap - .first - .keys - .map((final key) => key) - .toSet() - .toList(), - onChange: (final newValue) { - setState(() { - databaseAttribute = newValue!; - }); - final old = widget.value; - widget.value.datasetAttr = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + setState(() { + databaseAttribute = newValue!; + }); + final old = widget.value; + widget.value.datasetAttr = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart b/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart index 6881ad13..e6009a15 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/firebase/path.dart @@ -52,7 +52,7 @@ class FirestorePathControlState extends State { children: widget.path.values! .map( (final e) => FirestoreParameterControl( - page: BlocProvider.of(context).state, + page: (context.read().state as PageLoaded).page, title: widget.path.values!.indexOf(e).isEven ? 'Collection' : 'Doc', diff --git a/teta_widgets/lib/src/elements/controls/atoms/flag.dart b/teta_widgets/lib/src/elements/controls/atoms/flag.dart index 51c9431d..cace36a0 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/flag.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/flag.dart @@ -11,7 +11,6 @@ class FlagControl extends StatefulWidget { const FlagControl({ required this.title, required this.value, - required this.node, required this.keyValue, required this.callBack, final Key? key, @@ -19,7 +18,6 @@ class FlagControl extends StatefulWidget { final String title; final bool value; - final NDynamic node; final String? keyValue; final Function(bool, bool) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart b/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart index d444714b..5513602b 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class FlatTextControl extends StatefulWidget { const FlatTextControl({ - required this.node, required this.value, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String value; final Function(String, String) callBack; @@ -27,17 +25,13 @@ class FlatTextControl extends StatefulWidget { } class FlatTextControlState extends State { - int? nodeId; bool? isUpdated; - String? name; TextEditingController? controller; @override void initState() { - nodeId = widget.node.nid; - name = widget.value; controller = TextEditingController(); - controller!.text = name!; + controller!.text = widget.value; super.initState(); } @@ -46,13 +40,7 @@ class FlatTextControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller!.text = widget.value; - }); - nodeId = state.first.nid; - } + controller!.text = widget.value; } }, child: Column( @@ -67,7 +55,6 @@ class FlatTextControlState extends State { hpadding: 4, callBack: (final text) { final old = widget.value; - name = text; widget.callBack(text, old); }, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_family.dart b/teta_widgets/lib/src/elements/controls/atoms/font_family.dart index 1b92cdbc..834e92bf 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_family.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_family.dart @@ -17,13 +17,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class FontFamilyControl extends StatefulWidget { const FontFamilyControl({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart index 142dca84..6cf67cf4 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart @@ -18,13 +18,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class FontSizeControl extends StatefulWidget { const FontSizeControl({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; @@ -33,14 +31,11 @@ class FontSizeControl extends StatefulWidget { } class FontSizeState extends State { - int? nodeId; - bool? isUpdated; TextEditingController controller = TextEditingController(); Timer? searchOnStoppedTyping; @override void initState() { - nodeId = widget.node.nid; controller.text = '${widget.textStyle.fontSize?.get(context)}'; super.initState(); } @@ -76,14 +71,7 @@ class FontSizeState extends State { BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = - '${widget.textStyle.fontSize!.get(context)}'; - }); - nodeId = state.first.nid; - } + controller.text = '${widget.textStyle.fontSize!.get(context)}'; } }, child: Column( @@ -99,7 +87,7 @@ class FontSizeState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(ctx: context), + builder: (final ctx) => DevicesDialog(), ); }, child: Image.asset( diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_style.dart b/teta_widgets/lib/src/elements/controls/atoms/font_style.dart index 5359d425..4a776c30 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_style.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_style.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class FontStyleControls extends StatefulWidget { const FontStyleControls({ - required this.node, required this.callBack, required this.textStyle, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_weight.dart b/teta_widgets/lib/src/elements/controls/atoms/font_weight.dart index afe3d104..cb06f303 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_weight.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_weight.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class FontWeightControl extends StatefulWidget { const FontWeightControl({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart index c902580c..5fa05059 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class GoogleMapsControl extends StatefulWidget { const GoogleMapsControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart index 2852ac0a..317603d1 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class GoogleMapsMapStyleControls extends StatefulWidget { const GoogleMapsMapStyleControls({ - required this.node, required this.mapStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FGoogleMapsMapStyle mapStyle; final Function(FGoogleMapsMapStyle, FGoogleMapsMapStyle) callBack; @@ -29,14 +27,11 @@ class GoogleMapsMapStyleControls extends StatefulWidget { class GoogleMapsMapStyleControlsState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.mapStyle.getString; } @@ -45,13 +40,7 @@ class GoogleMapsMapStyleControlsState return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.mapStyle.getString; - }); - nodeId = state.first.nid; - } + dropdown = widget.mapStyle.getString; } }, child: BlocBuilder>( @@ -75,13 +64,17 @@ class GoogleMapsMapStyleControlsState value: dropdown, items: [ buildMapStyleMenuItem( - 'Standard', 'assets/images/standard.png'), + 'Standard', + 'assets/images/standard.png', + ), buildMapStyleMenuItem('Silver', 'assets/images/silver.png'), buildMapStyleMenuItem('Retro', 'assets/images/retro.png'), buildMapStyleMenuItem('Dark', 'assets/images/dark.png'), buildMapStyleMenuItem('Night', 'assets/images/night.png'), buildMapStyleMenuItem( - 'Aubergine', 'assets/images/aubergine.png'), + 'Aubergine', + 'assets/images/aubergine.png', + ), ], onChange: (final newValue) { if (newValue != null) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart b/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart index daa02ad7..dba6417a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart @@ -10,14 +10,12 @@ import 'package:teta_widgets/src/elements/index.dart'; class HttpMethodControl extends StatefulWidget { const HttpMethodControl({ - required this.node, required this.httpMethod, required this.callBack, final Key? key, this.title, }) : super(key: key); - final CNode node; final String? title; final String httpMethod; final Function(String, String) callBack; @@ -27,14 +25,11 @@ class HttpMethodControl extends StatefulWidget { } class _HttpMethodControlState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.httpMethod; } @@ -43,13 +38,7 @@ class _HttpMethodControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.httpMethod; - }); - nodeId = state.first.nid; - } + dropdown = widget.httpMethod; } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/delete.dart index 8b623cfd..828aec90 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/delete.dart @@ -13,17 +13,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class CustomHttpRequestDeleteControl extends StatelessWidget { const CustomHttpRequestDeleteControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -41,9 +35,7 @@ class CustomHttpRequestDeleteControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestURL ?? FTextTypeInput(), - page: page, title: 'URL', callBack: (final value, final old) { action.customHttpRequestURL = value; @@ -60,10 +52,8 @@ class CustomHttpRequestDeleteControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestExpectedStatusCode ?? FTextTypeInput(), - page: page, title: 'Status Code', callBack: (final value, final old) { action.customHttpRequestExpectedStatusCode = value; @@ -72,8 +62,6 @@ class CustomHttpRequestDeleteControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Params', list: action.customHttpRequestList ?? [], callBack: (final value, final old) { @@ -91,8 +79,6 @@ class CustomHttpRequestDeleteControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Headers', list: action.customHttpRequestHeader ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/post.dart b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/post.dart index e4410820..d3195af9 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/post.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/post.dart @@ -13,17 +13,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class CustomHttpRequestPostControl extends StatelessWidget { const CustomHttpRequestPostControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -41,9 +35,7 @@ class CustomHttpRequestPostControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestURL ?? FTextTypeInput(), - page: page, title: 'URL', callBack: (final value, final old) { action.customHttpRequestURL = value; @@ -60,10 +52,8 @@ class CustomHttpRequestPostControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestExpectedStatusCode ?? FTextTypeInput(), - page: page, title: 'Status Code', callBack: (final value, final old) { action.customHttpRequestExpectedStatusCode = value; @@ -72,8 +62,6 @@ class CustomHttpRequestPostControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Params', list: action.customHttpRequestList ?? [], callBack: (final value, final old) { @@ -91,8 +79,6 @@ class CustomHttpRequestPostControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Body Paramaters', list: action.customHttpRequestBody ?? [], callBack: (final value, final old) { @@ -110,8 +96,6 @@ class CustomHttpRequestPostControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Headers', list: action.customHttpRequestHeader ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/update.dart b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/update.dart index 9dfce194..2a6fe59c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/update.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/https_requests_custom_backend/update.dart @@ -13,17 +13,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class CustomHttpRequestUpdateControl extends StatelessWidget { const CustomHttpRequestUpdateControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -41,9 +35,7 @@ class CustomHttpRequestUpdateControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestURL ?? FTextTypeInput(), - page: page, title: 'URL', callBack: (final value, final old) { action.customHttpRequestURL = value; @@ -60,10 +52,8 @@ class CustomHttpRequestUpdateControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.customHttpRequestExpectedStatusCode ?? FTextTypeInput(), - page: page, title: 'Status Code', callBack: (final value, final old) { action.customHttpRequestExpectedStatusCode = value; @@ -72,8 +62,6 @@ class CustomHttpRequestUpdateControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Params', list: action.customHttpRequestList ?? [], callBack: (final value, final old) { @@ -91,8 +79,6 @@ class CustomHttpRequestUpdateControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Body Paramaters', list: action.customHttpRequestBody ?? [], callBack: (final value, final old) { @@ -110,8 +96,6 @@ class CustomHttpRequestUpdateControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Headers', list: action.customHttpRequestHeader ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/icon.dart b/teta_widgets/lib/src/elements/controls/atoms/icon.dart index eb528f45..5142ee02 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/icon.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/icon.dart @@ -17,13 +17,11 @@ import 'package:universal_platform/universal_platform.dart'; class IconControl extends StatefulWidget { const IconControl({ - required this.node, required this.icon, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String icon; final Function(String, String) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/icon_feather.dart b/teta_widgets/lib/src/elements/controls/atoms/icon_feather.dart index e9510f9b..833d495f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/icon_feather.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/icon_feather.dart @@ -16,13 +16,11 @@ import 'package:universal_platform/universal_platform.dart'; class IconFeatherControl extends StatefulWidget { const IconFeatherControl({ - required this.node, required this.icon, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String icon; final Function(String, String) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/icon_fontawesome.dart b/teta_widgets/lib/src/elements/controls/atoms/icon_fontawesome.dart index 0be76694..8f2771da 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/icon_fontawesome.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/icon_fontawesome.dart @@ -16,13 +16,11 @@ import 'package:universal_platform/universal_platform.dart'; class IconFontAwesomeControl extends StatefulWidget { const IconFontAwesomeControl({ - required this.node, required this.icon, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String icon; final Function(String, String) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/icon_line.dart b/teta_widgets/lib/src/elements/controls/atoms/icon_line.dart index e96d6dd2..32705664 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/icon_line.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/icon_line.dart @@ -16,13 +16,11 @@ import 'package:universal_platform/universal_platform.dart'; class IconLineControl extends StatefulWidget { const IconLineControl({ - required this.node, required this.icon, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String icon; final Function(String, String) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart b/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart index 850b1c00..f551adea 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class MainAxisAlignmentControls extends StatefulWidget { const MainAxisAlignmentControls({ - required this.node, required this.mainAxisAlignment, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FMainAxisAlignment mainAxisAlignment; final Function(FMainAxisAlignment, FMainAxisAlignment) callBack; @@ -28,14 +26,11 @@ class MainAxisAlignmentControls extends StatefulWidget { } class MainAxisAlignmentControlsState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.mainAxisAlignment.getString; } @@ -44,13 +39,9 @@ class MainAxisAlignmentControlsState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.mainAxisAlignment.getString; - }); - nodeId = state.first.nid; - } + setState(() { + dropdown = widget.mainAxisAlignment.getString; + }); } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart b/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart index 04d66094..10900302 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart @@ -11,13 +11,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class MainAxisSizeControl extends StatefulWidget { const MainAxisSizeControl({ - required this.node, required this.size, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FMainAxisSize size; final Function(FMainAxisSize, FMainAxisSize) callBack; @@ -26,14 +24,11 @@ class MainAxisSizeControl extends StatefulWidget { } class MainAxisSizeControlState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.size.getString; } @@ -42,13 +37,9 @@ class MainAxisSizeControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.size.getString; - }); - nodeId = state.first.nid; - } + setState(() { + dropdown = widget.size.getString; + }); } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart index 71bd45f4..b9f4b2a8 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class MapControllerControl extends StatefulWidget { const MapControllerControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/map_element.dart b/teta_widgets/lib/src/elements/controls/atoms/map_element.dart index 85c14c47..09ddb4fc 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/map_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/map_element.dart @@ -13,16 +13,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class MapElementControl extends StatefulWidget { const MapElementControl({ - required this.node, required this.value, - required this.page, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final MapElement value; - final PageObject page; final Function(MapElement, MapElement) callBack; @override @@ -30,14 +26,11 @@ class MapElementControl extends StatefulWidget { } class MapElementControlState extends State { - int? nodeId; - bool? isUpdated; late TextEditingController controller; @override void initState() { controller = TextEditingController(); - nodeId = widget.node.nid; controller.text = widget.value.key; super.initState(); } @@ -47,13 +40,9 @@ class MapElementControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.value.key; - }); - nodeId = state.first.nid; - } + setState(() { + controller.text = widget.value.key; + }); } }, child: Column( @@ -77,9 +66,7 @@ class MapElementControlState extends State { ), TextControl( valueType: VariableType.dynamic, - node: widget.node, value: widget.value.value, - page: widget.page, title: 'Value', callBack: (final value, final old) { final newValue = widget.value.copyWith(value: value); diff --git a/teta_widgets/lib/src/elements/controls/atoms/margins.dart b/teta_widgets/lib/src/elements/controls/atoms/margins.dart index 488ce437..0819b344 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/margins.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/margins.dart @@ -19,14 +19,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class Margins extends StatefulWidget { const Margins({ - required this.node, required this.title, required this.value, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String title; final FMargins value; final Function(Map, Map) callBack; @@ -36,8 +34,6 @@ class Margins extends StatefulWidget { } class MarginsState extends State { - int? nodeId; - bool? isUpdated; List? margins; List controllers = []; bool isLinked = true; @@ -45,7 +41,6 @@ class MarginsState extends State { @override void initState() { - nodeId = widget.node.nid; margins = widget.value.getList(context); for (var i = 0; i < 4; i++) { controllers.add(TextEditingController()); @@ -102,23 +97,20 @@ class MarginsState extends State { BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - margins = widget.value.getList(context); - for (var i = 0; i < 4; i++) { - controllers[i].text = margins![i]; - } - var flag = false; - var lastValue = ''; - for (final element in margins ?? const []) { - if (lastValue == '') lastValue = element; - if (element != lastValue) { - flag = true; - } + if (mounted) { + margins = widget.value.getList(context); + for (var i = 0; i < 4; i++) { + controllers[i].text = margins![i]; + } + var flag = false; + var lastValue = ''; + for (final element in margins ?? const []) { + if (lastValue == '') lastValue = element; + if (element != lastValue) { + flag = true; } - isLinked = !flag; } + isLinked = !flag; } } return Column( @@ -138,8 +130,7 @@ class MarginsState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => - DevicesDialog(ctx: context), + builder: (final ctx) => DevicesDialog(), ); }, child: Image.asset( diff --git a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart index 6cf8042e..1844fd96 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart @@ -14,17 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class MixPanelSetUserId extends StatelessWidget { const MixPanelSetUserId({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; diff --git a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart index 761c4250..3e560b4e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart @@ -16,17 +16,10 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class MixPanelTrack extends StatelessWidget { const MixPanelTrack({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; diff --git a/teta_widgets/lib/src/elements/controls/atoms/name.dart b/teta_widgets/lib/src/elements/controls/atoms/name.dart index 777186f0..f8c56b67 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/name.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/name.dart @@ -12,13 +12,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class NameControl extends StatefulWidget { const NameControl({ - required this.node, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final String? title; final Function(String, String) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart index 126c708e..9d635fa2 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart @@ -16,17 +16,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class ComponentControl extends StatefulWidget { const ComponentControl({ - required this.prj, - required this.page, - required this.node, required this.callBack, required this.callBackParameters, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final Function(String, String) callBack; final Function(Map) callBackParameters; diff --git a/teta_widgets/lib/src/elements/controls/atoms/page_params.dart b/teta_widgets/lib/src/elements/controls/atoms/page_params.dart index be962c19..7ce11bee 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/page_params.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/page_params.dart @@ -17,14 +17,10 @@ import 'package:uuid/uuid.dart'; class PageParamsControl extends StatefulWidget { const PageParamsControl({ - required this.node, - required this.page, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; - final PageObject page; final Function(List) callBack; @override diff --git a/teta_widgets/lib/src/elements/controls/atoms/qonversion/buy.dart b/teta_widgets/lib/src/elements/controls/atoms/qonversion/buy.dart index 7f247a92..2f6aff3b 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/qonversion/buy.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/qonversion/buy.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; @@ -8,17 +9,11 @@ import 'package:teta_widgets/src/elements/nodes/dynamic.dart'; class QonversionActionWidget extends StatelessWidget { const QonversionActionWidget({ - required this.prj, - required this.page, - required this.node, required this.element, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final NDynamic node; - final PageObject page; final FActionElement element; final Function(FActionElement, FActionElement) callback; @@ -26,20 +21,34 @@ class QonversionActionWidget extends StatelessWidget { Widget build(final BuildContext context) { return Column( children: [ - CDropdown( - value: FActionElement.convertValueToDropdown( - element.actionQonversion, - ), - items: FActionElement.getQonversion(prj.config).toSet().toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = element; - element.actionQonversion = FActionElement.convertDropdownToValue( - ActionQonversion.values, - newValue, - ) as ActionQonversion?; - callback(element, old); + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! ConfigStateLoaded || + current is! ConfigStateLoaded) { + return false; } + return previous.config.qonversion != current.config.qonversion; + }, + builder: (final context, final state) { + if (state is! ConfigStateLoaded) return const SizedBox(); + return CDropdown( + value: FActionElement.convertValueToDropdown( + element.actionQonversion, + ), + items: + FActionElement.getQonversion(state.config).toSet().toList(), + onChange: (final newValue) { + if (newValue != null) { + final old = element; + element.actionQonversion = + FActionElement.convertDropdownToValue( + ActionQonversion.values, + newValue, + ) as ActionQonversion?; + callback(element, old); + } + }, + ); }, ), const Gap(Grid.medium), @@ -48,9 +57,7 @@ class QonversionActionWidget extends StatelessWidget { width: double.maxFinite, child: TextControl( valueType: VariableType.string, - node: node, value: element.qonversionProductIdentifier ?? FTextTypeInput(), - page: page, title: 'Qonversion ID', callBack: (final value, final old) { final old = element; @@ -70,29 +77,40 @@ class QonversionActionWidget extends StatelessWidget { color: Palette.txtPrimary.withOpacity(0.6), ), const Gap(Grid.small), - CDropdown( - value: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == element.stateName, - ) != - -1 - ? element.stateName - : null, - items: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - try { - final old = element; - element.stateName = newValue; - callback(element, old); - } catch (_) {} + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; } + return previous.states != current.states; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == element.stateName, + ) != + -1 + ? element.stateName + : null, + items: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + try { + final old = element; + element.stateName = newValue; + callback(element, old); + } catch (_) {} + } + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart b/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart index 2e0929c2..37557f9d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; @@ -8,17 +9,11 @@ import 'package:teta_widgets/src/elements/nodes/dynamic.dart'; class RevenueCatBuyActionWidget extends StatelessWidget { const RevenueCatBuyActionWidget({ - required this.prj, - required this.page, - required this.node, required this.element, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final NDynamic node; - final PageObject page; final FActionElement element; final Function(FActionElement, FActionElement) callback; @@ -48,9 +43,7 @@ class RevenueCatBuyActionWidget extends StatelessWidget { width: double.maxFinite, child: TextControl( valueType: VariableType.string, - node: node, value: element.revenueCatProductIdentifier ?? FTextTypeInput(), - page: page, title: 'Prod Identifier', callBack: (final value, final old) { final old = element; @@ -70,29 +63,40 @@ class RevenueCatBuyActionWidget extends StatelessWidget { color: Palette.txtPrimary.withOpacity(0.6), ), const Gap(Grid.small), - CDropdown( - value: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == element.stateName, - ) != - -1 - ? element.stateName - : null, - items: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - try { - final old = element; - element.stateName = newValue; - callback(element, old); - } catch (_) {} + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; } + return previous.states != current.states; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == element.stateName, + ) != + -1 + ? element.stateName + : null, + items: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + try { + final old = element; + element.stateName = newValue; + callback(element, old); + } catch (_) {} + } + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/size.dart b/teta_widgets/lib/src/elements/controls/atoms/size.dart index 15e039ad..c890af2a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/size.dart @@ -16,7 +16,6 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SizeControl extends StatefulWidget { const SizeControl({ required this.keyAttr, - required this.node, required this.size, required this.isWidth, required this.title, @@ -26,7 +25,6 @@ class SizeControl extends StatefulWidget { }) : super(key: key); final String keyAttr; - final CNode node; final FSize size; final bool isWidth; final String title; @@ -38,14 +36,11 @@ class SizeControl extends StatefulWidget { } class SizeControlsState extends State { - int? nodeId; - bool? isUpdated; TextEditingController controller = TextEditingController(); bool flag = false; @override void initState() { - nodeId = widget.node.nid; controller.text = '${widget.size.get(context: context, isWidth: widget.isWidth)}'; flag = widget.size.get(context: context, isWidth: widget.isWidth) != null; @@ -86,40 +81,36 @@ class SizeControlsState extends State { BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - flag = widget.size - .get(context: context, isWidth: widget.isWidth) != - null; - var size = widget.size.size; - if (device.identifier.type == DeviceType.phone) { - size = widget.size.size; - } else if (device.identifier.type == DeviceType.tablet) { - size = widget.size.sizeTablet; - } else { - size = widget.size.sizeDesktop; - } - final unit = widget.size.getUnit(context); - for (var i = 0; i < 2; i++) { - controller.text = (size == 'max' || - size == 'inf' && - size == '100%' && - unit == SizeUnit.pixel) - ? 'max' - : (size == 'max' || - size == 'inf' && - size == '100%' && - unit == SizeUnit.percent) - ? '100%' - : (size == 'auto') - ? 'auto' - : '$size'; - } + if (mounted) { + flag = widget.size + .get(context: context, isWidth: widget.isWidth) != + null; + var size = widget.size.size; + if (device.identifier.type == DeviceType.phone) { + size = widget.size.size; + } else if (device.identifier.type == DeviceType.tablet) { + size = widget.size.sizeTablet; + } else { + size = widget.size.sizeDesktop; + } + final unit = widget.size.getUnit(context); + for (var i = 0; i < 2; i++) { + controller.text = (size == 'max' || + size == 'inf' && + size == '100%' && + unit == SizeUnit.pixel) + ? 'max' + : (size == 'max' || + size == 'inf' && + size == '100%' && + unit == SizeUnit.percent) + ? '100%' + : (size == 'auto') + ? 'auto' + : '$size'; } } } - return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -136,8 +127,7 @@ class SizeControlsState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => - DevicesDialog(ctx: context), + builder: (final ctx) => DevicesDialog(), ); }, child: Image.asset( diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/delete.dart index fa72ca9c..3778f763 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/delete.dart @@ -14,17 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseDeleteControl extends StatelessWidget { const SupabaseDeleteControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -51,9 +45,7 @@ class SupabaseDeleteControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'From Table', callBack: (final value, final old) { action.dbFrom = value; @@ -76,9 +68,7 @@ class SupabaseDeleteControl extends StatelessWidget { borderRadius: BorderRadius.circular(8), ), child: MapElementControl( - node: node, value: action.dbEq ?? MapElement(key: '', value: FTextTypeInput()), - page: page, callBack: (final value, final old) { action.dbEq = value; callback(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/insert.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/insert.dart index 2012165a..6f59b005 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/insert.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/insert.dart @@ -15,17 +15,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseInsertControl extends StatelessWidget { const SupabaseInsertControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -52,9 +46,7 @@ class SupabaseInsertControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'From Table', callBack: (final value, final old) { action.dbFrom = value; @@ -62,9 +54,7 @@ class SupabaseInsertControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/invoke.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/invoke.dart index b5980b7f..d209f390 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/invoke.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/invoke.dart @@ -10,21 +10,14 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; import 'package:teta_widgets/src/elements/features/actions/element.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseInvokeControl extends StatelessWidget { const SupabaseInvokeControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -36,9 +29,7 @@ class SupabaseInvokeControl extends StatelessWidget { children: [ TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'Function', callBack: (final value, final old) { action.dbFrom = value; diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_remove.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_remove.dart index 16cb86fb..f6b260c7 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_remove.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_remove.dart @@ -16,17 +16,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseStorageRemoveControl extends StatelessWidget { const SupabaseStorageRemoveControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -38,9 +32,7 @@ class SupabaseStorageRemoveControl extends StatelessWidget { children: [ TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'Bucket ID', callBack: (final value, final old) { action.dbFrom = value; @@ -49,9 +41,7 @@ class SupabaseStorageRemoveControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.valueTextTypeInput ?? FTextTypeInput(), - page: page, title: 'File path', callBack: (final value, final old) { action.valueTextTypeInput = value; @@ -60,8 +50,6 @@ class SupabaseStorageRemoveControl extends StatelessWidget { ), const Gap(Grid.small), HttpParamsControl( - node: node, - page: page, title: 'Add Body Paramaters', list: action.customHttpRequestBody ?? [], callBack: (final value, final old) { @@ -79,8 +67,6 @@ class SupabaseStorageRemoveControl extends StatelessWidget { ), ), HttpParamsControl( - node: node, - page: page, title: 'Add Headers', list: action.customHttpRequestHeader ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_upload.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_upload.dart index 883b4639..79149e31 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_upload.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/storage_upload.dart @@ -4,6 +4,7 @@ // Flutter imports: import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; // Package imports: import 'package:teta_core/teta_core.dart'; @@ -15,17 +16,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseStorageUploadControl extends StatelessWidget { const SupabaseStorageUploadControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -37,9 +32,7 @@ class SupabaseStorageUploadControl extends StatelessWidget { children: [ TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'Bucket ID', callBack: (final value, final old) { action.dbFrom = value; @@ -48,9 +41,7 @@ class SupabaseStorageUploadControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.valueTextTypeInput ?? FTextTypeInput(), - page: page, title: 'File path', callBack: (final value, final old) { action.valueTextTypeInput = value; @@ -66,30 +57,40 @@ class SupabaseStorageUploadControl extends StatelessWidget { 'Type: File.', ), const Gap(Grid.small), - CDropdown( - value: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == action.stateName, - ) != - -1 - ? action.stateName - : null, - items: page.states - .where( - (final element) => element.type == VariableType.file, - ) - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = action; - action.stateName = newValue; - callback(); + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; } + return previous.states != current.states; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == action.stateName, + ) != + -1 + ? action.stateName + : null, + items: state.states + .where( + (final element) => element.type == VariableType.file, + ) + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + action.stateName = newValue; + callback(); + } + }, + ); }, ), const Gap(Grid.medium), @@ -101,30 +102,40 @@ class SupabaseStorageUploadControl extends StatelessWidget { 'Type: String.', ), const Gap(Grid.small), - CDropdown( - value: page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == action.stateName2, - ) != - -1 - ? action.stateName2 - : null, - items: page.states - .where( - (final element) => element.type == VariableType.string, - ) - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = action; - action.stateName2 = newValue; - callback(); + BlocBuilder( + buildWhen: (final previous, final current) { + if (previous is! PageLoaded || current is! PageLoaded) { + return true; } + return previous.states != current.states; + }, + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.states + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList() + .indexWhere( + (final e) => e == action.stateName2, + ) != + -1 + ? action.stateName2 + : null, + items: state.states + .where( + (final element) => element.type == VariableType.string, + ) + .map((final e) => e.name) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + if (newValue != null) { + action.stateName2 = newValue; + callback(); + } + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/subapase/update.dart b/teta_widgets/lib/src/elements/controls/atoms/subapase/update.dart index 0db19953..8bc9dce0 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/subapase/update.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/subapase/update.dart @@ -15,17 +15,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SupabaseUpdateControl extends StatelessWidget { const SupabaseUpdateControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -52,9 +46,7 @@ class SupabaseUpdateControl extends StatelessWidget { ), TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'From Table', callBack: (final value, final old) { action.dbFrom = value; @@ -62,9 +54,7 @@ class SupabaseUpdateControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback(); @@ -83,9 +73,7 @@ class SupabaseUpdateControl extends StatelessWidget { borderRadius: BorderRadius.circular(8), ), child: MapElementControl( - node: node, value: action.dbEq ?? MapElement(key: '', value: FTextTypeInput()), - page: page, callBack: (final value, final old) { action.dbEq = value; callback(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/delete.dart index b512b277..7695e164 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/delete.dart @@ -14,17 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TetaCmsDeleteControl extends StatelessWidget { const TetaCmsDeleteControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -50,7 +44,6 @@ class TetaCmsDeleteControl extends StatelessWidget { ), ), CMSCollectionControl( - node: node, collectionId: action.cmsCollectionId, callBack: (final value, final old) { action.cmsCollectionId = value; @@ -74,9 +67,7 @@ class TetaCmsDeleteControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'Document Id', callBack: (final value, final old) { action.dbFrom = value; diff --git a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/insert.dart b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/insert.dart index d10e88d4..16f660d6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/insert.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/insert.dart @@ -14,17 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TetaCmsInsertControl extends StatelessWidget { const TetaCmsInsertControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -50,7 +44,6 @@ class TetaCmsInsertControl extends StatelessWidget { ), ), CMSCollectionControl( - node: node, collectionId: action.cmsCollectionId, callBack: (final value, final old) { action.cmsCollectionId = value; @@ -58,9 +51,7 @@ class TetaCmsInsertControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback(); diff --git a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/update.dart b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/update.dart index 88777124..fa2a34fe 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/teta_cms/update.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/teta_cms/update.dart @@ -15,17 +15,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TetaCmsUpdateControl extends StatelessWidget { const TetaCmsUpdateControl({ - required this.prj, - required this.page, - required this.node, required this.action, required this.callback, final Key? key, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FActionElement action; final Function() callback; @@ -51,7 +45,6 @@ class TetaCmsUpdateControl extends StatelessWidget { ), ), CMSCollectionControl( - node: node, collectionId: action.cmsCollectionId, callBack: (final value, final old) { action.cmsCollectionId = value; @@ -59,9 +52,7 @@ class TetaCmsUpdateControl extends StatelessWidget { }, ), DBMapControl( - node: node, list: action.dbData ?? [], - page: page, callBack: (final value, final old) { action.dbData = value; callback(); @@ -81,9 +72,7 @@ class TetaCmsUpdateControl extends StatelessWidget { ), child: TextControl( valueType: VariableType.string, - node: node, value: action.dbFrom ?? FTextTypeInput(), - page: page, title: 'Document Id', callBack: (final value, final old) { action.dbFrom = value; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart b/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart index ab0e3c28..a01564d6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart @@ -11,13 +11,11 @@ import 'package:teta_widgets/src/elements/index.dart'; class TextDirectionControl extends StatefulWidget { const TextDirectionControl({ - required this.node, required this.textDirection, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextDirection textDirection; final Function(FTextDirection, FTextDirection) callBack; @@ -26,14 +24,11 @@ class TextDirectionControl extends StatefulWidget { } class TextDirectionControlState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; @override void initState() { super.initState(); - nodeId = widget.node.nid; dropdown = widget.textDirection.getStringForDropDown; } @@ -42,13 +37,9 @@ class TextDirectionControlState extends State { return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - dropdown = widget.textDirection.getStringForDropDown; - }); - nodeId = state.first.nid; - } + setState(() { + dropdown = widget.textDirection.getStringForDropDown; + }); } }, child: BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/video/video_start_at.dart b/teta_widgets/lib/src/elements/controls/atoms/video/video_start_at.dart index aa56e5be..b460ef77 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/video/video_start_at.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/video/video_start_at.dart @@ -10,13 +10,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class VideoStartAtControl extends StatefulWidget { const VideoStartAtControl({ - required this.node, required this.startAt, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final int startAt; final Function(int, int) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart index 0a26b647..662f6afd 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart @@ -15,13 +15,11 @@ import 'package:youtube_player_iframe/youtube_player_iframe.dart'; class VideoUrlControl extends StatefulWidget { const VideoUrlControl({ - required this.node, required this.value, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/http_params.dart b/teta_widgets/lib/src/elements/controls/http_params.dart index 7eb54d06..b2eedd7c 100644 --- a/teta_widgets/lib/src/elements/controls/http_params.dart +++ b/teta_widgets/lib/src/elements/controls/http_params.dart @@ -14,17 +14,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class HttpParamsControl extends StatefulWidget { const HttpParamsControl({ - required this.node, required this.list, - required this.page, required this.callBack, final Key? key, this.title, }) : super(key: key); - final CNode node; final List list; - final PageObject page; final Function(List, List) callBack; final String? title; @@ -33,122 +29,105 @@ class HttpParamsControl extends StatefulWidget { } class HttpParamsControlState extends State { - int? nodeId; - bool? isUpdated; late TextEditingController controller; @override void initState() { controller = TextEditingController(); - nodeId = widget.node.nid; super.initState(); } @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } - }, - child: Padding( - padding: const EdgeInsets.only(top: 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: EdgeInsets.only(bottom: widget.list.isEmpty ? 0 : 8), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TParagraph( - widget.title ?? 'Add Params', - ), - Row( - children: [ - BounceSmall( - onTap: () { - final old = widget.list; - widget.list.add( - MapElement( - key: '', - value: FTextTypeInput(), - ), - ); - widget.callBack(widget.list, old); - }, - child: HoverWidget( - hoverChild: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - ), - ), - child: const Icon( - Icons.add, - size: 24, + return Padding( + padding: const EdgeInsets.only(top: 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: EdgeInsets.only(bottom: widget.list.isEmpty ? 0 : 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TParagraph( + widget.title ?? 'Add Params', + ), + Row( + children: [ + BounceSmall( + onTap: () { + final old = widget.list; + widget.list.add( + MapElement( + key: '', + value: FTextTypeInput(), + ), + ); + widget.callBack(widget.list, old); + }, + child: HoverWidget( + hoverChild: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( color: Colors.white, ), ), - onHover: (final e) {}, - child: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.transparent, - ), - ), - child: const Icon( - Icons.add, - size: 24, - color: Colors.white, + child: const Icon( + Icons.add, + size: 24, + color: Colors.white, + ), + ), + onHover: (final e) {}, + child: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( + color: Colors.transparent, ), ), + child: const Icon( + Icons.add, + size: 24, + color: Colors.white, + ), ), ), - ], - ), - ], - ), + ), + ], + ), + ], ), - Padding( - padding: const EdgeInsets.only(bottom: 8), - child: Column( - mainAxisSize: MainAxisSize.min, - children: widget.list - .map( - (final e) => Container( - margin: const EdgeInsets.only(bottom: 8), - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.black26, - borderRadius: BorderRadius.circular(8), - ), - child: HttpParamsElementControl( - node: widget.node, - value: e, - page: widget.page, - callBack: (final value, final old) { - final old = widget.list; - final index = widget.list.indexOf(e); - widget.list[index] = value; - widget.callBack(widget.list, old); - }, - ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Column( + mainAxisSize: MainAxisSize.min, + children: widget.list + .map( + (final e) => Container( + margin: const EdgeInsets.only(bottom: 8), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.black26, + borderRadius: BorderRadius.circular(8), + ), + child: HttpParamsElementControl( + value: e, + callBack: (final value, final old) { + final old = widget.list; + final index = widget.list.indexOf(e); + widget.list[index] = value; + widget.callBack(widget.list, old); + }, ), - ) - .toList(), - ), + ), + ) + .toList(), ), - ], - ), + ), + ], ), ); } diff --git a/teta_widgets/lib/src/elements/controls/http_params_element.dart b/teta_widgets/lib/src/elements/controls/http_params_element.dart index fbb2ec36..62ceb8af 100644 --- a/teta_widgets/lib/src/elements/controls/http_params_element.dart +++ b/teta_widgets/lib/src/elements/controls/http_params_element.dart @@ -13,16 +13,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class HttpParamsElementControl extends StatefulWidget { const HttpParamsElementControl({ - required this.node, required this.value, - required this.page, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final MapElement value; - final PageObject page; final Function(MapElement, MapElement) callBack; @override @@ -31,64 +27,46 @@ class HttpParamsElementControl extends StatefulWidget { } class HttpParamsElementControlState extends State { - int? nodeId; - bool? isUpdated; late TextEditingController controller; @override void initState() { controller = TextEditingController(); - nodeId = widget.node.nid; controller.text = widget.value.key; super.initState(); } @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.value.key; - }); - nodeId = state.first.nid; - } - } - }, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 8), - child: TParagraph( - 'Key', - ), + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Padding( + padding: EdgeInsets.only(bottom: 8), + child: TParagraph( + 'Key', ), - CTextField( - //text: text, - controller: controller, - callBack: (final value) { - final old = widget.value; - final newValue = widget.value.copyWith(key: value); - widget.callBack(newValue, old); - }, - ), - TextControl( - valueType: VariableType.dynamic, - node: widget.node, - value: widget.value.value, - page: widget.page, - title: 'Value', - callBack: (final value, final old) { - final newValue = widget.value.copyWith(value: value); - widget.callBack(newValue, widget.value); - }, - ), - ], - ), + ), + CTextField( + //text: text, + controller: controller, + callBack: (final value) { + final old = widget.value; + final newValue = widget.value.copyWith(key: value); + widget.callBack(newValue, old); + }, + ), + TextControl( + valueType: VariableType.dynamic, + value: widget.value.value, + title: 'Value', + callBack: (final value, final old) { + final newValue = widget.value.copyWith(value: value); + widget.callBack(newValue, widget.value); + }, + ), + ], ); } } diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index 7c99dfaf..5adf9edc 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -26,18 +26,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextPrefabControl extends StatelessWidget { const TextPrefabControl({ - required this.prj, - required this.page, - required this.node, required this.textStyle, required this.keyValue, final Key? key, this.title, }) : super(key: key); - final ProjectObject prj; - final PageObject page; - final CNode node; final FTextStyle textStyle; final String? title; final String keyValue; diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 7510c016..2688bd10 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -10,6 +10,7 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_repositories/src/node_repository.dart'; import 'package:teta_repositories/src/project_repository.dart'; import 'package:teta_repositories/src/project_styles_repository.dart'; +import 'package:teta_repositories/teta_repositories.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/action.dart'; import 'package:teta_widgets/src/elements/controls/atoms/aligns.dart'; @@ -187,28 +188,10 @@ class ControlBuilder { final dynamic old, ) async { final prj = BlocProvider.of(context).state!; - final page = BlocProvider.of(context).state; - try { - try { - final userId = (BlocProvider.of(context).state - as Authenticated) - .user - .id; - sl.get().track(prj.id, userId); - } catch (e) { - Logger.printError('Error tracking generic project update, error: $e'); - } - unawaited( - sl.get().changeNode( - node: node as NDynamic, - ), - ); - } catch (e) { - if (kDebugMode) { - // ignore: avoid_print - print(e); - } - } + sl.get().track(prj.id); + sl.get().changeNode( + node: node as NDynamic, + ); } /// Returns a control widget based of [control] value. @@ -309,7 +292,6 @@ class ControlBuilder { key: ValueKey( '${node.nid} ${(node.body.attributes[control.key] as FTextTypeInput).value}', ), - node: node, collectionId: (node.body.attributes[control.key] as FTextTypeInput).value ?? '', callBack: (final value, final old) { @@ -330,8 +312,6 @@ class ControlBuilder { description: control.description, control: CurrentSongControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Current audio player data set', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -349,8 +329,6 @@ class ControlBuilder { description: control.description, control: AudioControllerControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Audio Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -368,8 +346,6 @@ class ControlBuilder { description: control.description, control: MapControllerControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Map Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -388,8 +364,6 @@ class ControlBuilder { description: control.description, control: GoogleMapsControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Google Maps Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -408,8 +382,6 @@ class ControlBuilder { description: control.description, control: GoogleMapsCubitControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Google Maps Cubit', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -428,8 +400,6 @@ class ControlBuilder { description: control.description, control: CameraControllerControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Camera Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -447,8 +417,6 @@ class ControlBuilder { description: control.description, control: WebViewControllerControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'WebView Controller', value: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( @@ -466,9 +434,6 @@ class ControlBuilder { description: control.description, control: ActionControl( key: ValueKey('${node.nid}'), - prj: BlocProvider.of(context).state!, - page: BlocProvider.of(context).state, - node: node, action: control.value as FAction, callBack: (final value, final old) { node.body.attributes[DBKeys.action] = value; @@ -488,7 +453,6 @@ class ControlBuilder { description: control.description, control: AlignsControl( key: ValueKey('${node.nid}'), - node: node, align: control.value as FAlign, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -508,7 +472,6 @@ class ControlBuilder { description: control.description, control: PhysicsControl( key: ValueKey('${node.nid}'), - node: node, physic: control.value as FPhysic, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -528,7 +491,6 @@ class ControlBuilder { description: control.description, control: BorderRadiusControl( key: ValueKey('${node.nid}'), - node: node, borderRadius: control.value as FBorderRadius, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -545,7 +507,6 @@ class ControlBuilder { description: control.description, control: BordersControl( key: ValueKey('${node.nid}'), - node: node, borders: control.value as FBorder, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -560,9 +521,6 @@ class ControlBuilder { if (control.type == ControlType.component) { return ComponentControl( key: ValueKey('${node.nid}'), - prj: BlocProvider.of(context).state!, - page: BlocProvider.of(context).state, - node: node, callBack: (final value, final old) => ControlBuilder.toDB( node, context, @@ -585,7 +543,6 @@ class ControlBuilder { description: control.description, control: CrossAxisAlignmentControls( key: ValueKey('${node.nid}'), - node: node, crossAxisAlignment: control.value as FCrossAxisAlignment, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -603,8 +560,6 @@ class ControlBuilder { control: SrcImageControl( key: ValueKey('${node.nid}'), title: 'Image', - node: node, - page: BlocProvider.of(context).state, image: control.value as FTextTypeInput, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -622,7 +577,6 @@ class ControlBuilder { description: control.description, control: IconControl( key: ValueKey('${node.nid}'), - node: node, icon: control.value as String, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -642,7 +596,6 @@ class ControlBuilder { description: control.description, control: IconFontAwesomeControl( key: ValueKey('${node.nid}'), - node: node, icon: control.value as String, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -662,7 +615,6 @@ class ControlBuilder { description: control.description, control: IconFeatherControl( key: ValueKey('${node.nid}'), - node: node, icon: control.value as String, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -682,7 +634,6 @@ class ControlBuilder { description: control.description, control: IconLineControl( key: ValueKey('${node.nid}'), - node: node, icon: control.value as String, callBack: (final value, final old) { node.body.attributes[control.key] = value; @@ -702,7 +653,6 @@ class ControlBuilder { description: control.description, control: MainAxisAlignmentControls( key: ValueKey('${node.nid}'), - node: node, mainAxisAlignment: control.value as FMainAxisAlignment, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -719,7 +669,6 @@ class ControlBuilder { description: control.description, control: GoogleMapsMapStyleControls( key: ValueKey('${node.nid}'), - node: node, mapStyle: control.value as FGoogleMapsMapStyle, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -736,7 +685,6 @@ class ControlBuilder { description: control.description, control: MainAxisSizeControl( key: ValueKey('${node.nid}'), - node: node, size: control.value as FMainAxisSize, callBack: (final value, final old) => ControlBuilder.toDB( node, @@ -753,7 +701,6 @@ class ControlBuilder { description: control.description, control: Margins( key: ValueKey('${node.nid}'), - node: node, title: 'Margins', value: control.value as FMargins, callBack: (final value, final old) { @@ -774,7 +721,6 @@ class ControlBuilder { description: control.description, control: Margins( key: ValueKey('${node.nid}'), - node: node, title: 'Padding', value: control.value as FMargins, callBack: (final value, final old) { @@ -797,8 +743,6 @@ class ControlBuilder { control: TextControl( key: ValueKey('${node.nid}'), valueType: control.valueType, - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'Value', value: control.value as FTextTypeInput, callBack: (final value, final old) { @@ -819,8 +763,6 @@ class ControlBuilder { description: control.description, control: DatasetControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title ?? 'From', value: control.value as FDataset, isAttrRequired: control.flag, @@ -838,9 +780,6 @@ class ControlBuilder { return TextPrefabControl( title: control.title, key: ValueKey('${node.nid}'), - node: node, - prj: BlocProvider.of(context).state!, - page: BlocProvider.of(context).state, textStyle: control.value as FTextStyle, keyValue: control.key, ); @@ -848,8 +787,6 @@ class ControlBuilder { if (control.type == ControlType.httpParamsControl) { return HttpParamsControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, title: control.title, list: control.value as List, callBack: (final value, final old) => { @@ -867,7 +804,6 @@ class ControlBuilder { if (control.type == ControlType.httpMethodControl) { return HttpMethodControl( key: ValueKey('${node.nid}'), - node: node, title: control.title, httpMethod: control.value as String, callBack: (final value, final old) => { @@ -885,7 +821,6 @@ class ControlBuilder { if (control.type == ControlType.apiCallsRequestControl) { return ApiCallsRequestControl( key: ValueKey('${node.nid}'), - node: node, requestName: control.value as String, callBack: (final value, final old, final apiCallsSelectedRequest) => { node.body.attributes[control.key] = value, @@ -906,11 +841,10 @@ class ControlBuilder { description: control.description, control: PageParamsControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, callBack: (final list) async { - await sl.get().updatePage( - BlocProvider.of(context).state, + await sl.get().updatePage( + (BlocProvider.of(context).state as PageLoaded) + .page, ); }, ), @@ -921,11 +855,10 @@ class ControlBuilder { description: control.description, control: StatesControl( key: ValueKey('${node.nid}'), - node: node, - page: BlocProvider.of(context).state, callBack: (final list) async { - await sl.get().updatePage( - BlocProvider.of(context).state, + await sl.get().updatePage( + (BlocProvider.of(context).state as PageLoaded) + .page, ); }, ), @@ -963,7 +896,6 @@ class ControlBuilder { control: FlagControl( key: ValueKey('${BlocProvider.of(context).state.first.nid}'), title: control.title, - node: BlocProvider.of(context).state.first as NDynamic, keyValue: control.key, value: control.value as bool, callBack: (final value, final old) { @@ -995,7 +927,6 @@ class ControlBuilder { return FillControl( title: control.title.isNotEmpty ? control.title : 'Fill', key: ValueKey('${BlocProvider.of(context).state.first.nid}'), - node: BlocProvider.of(context).state.first, isImageEnabled: isImageEnabled, isNoneEnabled: isNoneEnabled, type: @@ -1056,7 +987,6 @@ class ControlBuilder { }) { return SizeControl( key: ValueKey('${BlocProvider.of(context).state.first.nid}'), - node: BlocProvider.of(context).state.first, isWidth: control.isWidth, title: control.title, size: control.value, @@ -1081,7 +1011,6 @@ class ControlBuilder { }) { return SizesPrefabControl( key: ValueKey('${BlocProvider.of(context).state.first.nid}'), - node: BlocProvider.of(context).state.first, values: control.values, ); } diff --git a/teta_widgets/lib/src/elements/features/actions/element.dart b/teta_widgets/lib/src/elements/features/actions/element.dart index e2c89009..8feca765 100644 --- a/teta_widgets/lib/src/elements/features/actions/element.dart +++ b/teta_widgets/lib/src/elements/features/actions/element.dart @@ -587,7 +587,8 @@ class FActionElement extends Equatable { ]; /// Get avaiable action types for drop down list - List getTypes(final ProjectConfig? config, final PageObject page) { + List getTypes( + final ProjectConfigModel? config, final PageObject page) { if (config != null) { try { return [ @@ -601,33 +602,40 @@ class FActionElement extends Equatable { 'Languages', 'Google Maps', if (kDebugMode) 'Custom Functions', - if (config.isSupabaseReady) 'Supabase auth', - if (config.isSupabaseReady) 'Supabase database', - if (config.isSupabaseReady) 'Supabase functions', - if (config.isSupabaseReady) 'Supabase storage', - if (config.isBraintreeReady) 'Braintree', - if (config.isRevenueCatEnabled) 'RevenueCat', - if (config.isQonversionReady) 'Qonversion', - if (config.isMixpanelReady) 'Mixpanel', - if (config.isStripeEnabled) 'Stripe', - if (config.isAirtableReady) 'Airtable Database', - if ((page.flatList ?? []).indexWhere( + if (config.supabase is SupabaseConfigModelInitialized) + 'Supabase auth', + if (config.supabase is SupabaseConfigModelInitialized) + 'Supabase database', + if (config.supabase is SupabaseConfigModelInitialized) + 'Supabase functions', + if (config.supabase is SupabaseConfigModelInitialized) + 'Supabase storage', + if (config.braintree is BraintreeConfigModelInitialized) 'Braintree', + if (config.revenuecat is RevenueCatConfigModelInitialized) + 'RevenueCat', + if (config.qonversion is QonversionConfigModelInitialized) + 'Qonversion', + if (config.mixpanel is MixpanelConfigModelInitialized) 'Mixpanel', + if (config.stripe is StripeConfigModelInitialized) 'Stripe', + if (config.airtable is AirtableConfigModelInitialized) + 'Airtable Database', + if ((page.flatList).indexWhere( (final element) => element.intrinsicState.type == NType.camera, ) != -1) 'Camera', - if ((page.flatList ?? []).indexWhere( + if ((page.flatList).indexWhere( (final element) => element.intrinsicState.type == NType.audioPlayer, ) != -1) 'Audio player', - if ((page.flatList ?? []).indexWhere( + if ((page.flatList).indexWhere( (final element) => element.intrinsicState.type == NType.webview, ) != -1) 'Webview', - if ((page.flatList ?? []).indexWhere( + if ((page.flatList).indexWhere( (final element) => element.intrinsicState.type == NType.map || element.intrinsicState.type == NType.mapBuilder, @@ -665,38 +673,34 @@ class FActionElement extends Equatable { return enumsToListString(ActionState.values); } - static List getRevenueCat(final ProjectConfig? config) { - if (config != null) { - if (config.isRevenueCatEnabled) { - return enumsToListString(ActionRevenueCat.values); - } + static List getRevenueCat(final ProjectConfigModel config) { + if (config.revenuecat is RevenueCatConfigModelInitialized) { + return enumsToListString(ActionRevenueCat.values); } + return []; } - static List getQonversion(final ProjectConfig? config) { + static List getQonversion(final ProjectConfigModel? config) { if (config != null) { - if (config.isQonversionReady) { + if (config.qonversion is QonversionConfigModelInitialized) { return enumsToListString(ActionQonversion.values); } } return []; } - static List getMixpanel(final ProjectConfig? config) { - if (config != null) { - if (config.isMixpanelReady) { - return enumsToListString(ActionMixpanel.values); - } + static List getMixpanel(final ProjectConfigModel config) { + if (config.mixpanel is MixpanelConfigModelInitialized) { + return enumsToListString(ActionMixpanel.values); } + return []; } - static List getBraintree(final ProjectConfig? config) { - if (config != null) { - if (config.isBraintreeReady) { - return enumsToListString(ActionBraintree.values); - } + static List getBraintree(final ProjectConfigModel config) { + if (config.braintree is BraintreeConfigModelInitialized) { + return enumsToListString(ActionBraintree.values); } return []; } @@ -705,11 +709,11 @@ class FActionElement extends Equatable { return enumsToListString(ActionTranslator.values); } - static List getStripe(final ProjectConfig? config) { + static List getStripe(final ProjectConfigModel config) { return enumsToListString(ActionStripe.values); } - static List getGoogleMaps(final ProjectConfig? config) { + static List getGoogleMaps(final ProjectConfigModel config) { return enumsToListString(ActionGoogleMaps.values); } @@ -717,48 +721,42 @@ class FActionElement extends Equatable { return enumsToListString(ActionTheme.values); } - static List getSupabaseAuth(final ProjectConfig? config) { - if (config != null) { - if (config.isSupabaseReady) { - return enumsToListString(ActionSupabaseAuth.values); - } + static List getSupabaseAuth(final ProjectConfigModel config) { + if (config.supabase is SupabaseConfigModelInitialized) { + return enumsToListString(ActionSupabaseAuth.values); } return []; } - static List getSupabaseDB(final ProjectConfig? config) { - if (config != null) { - if (config.isSupabaseReady) { - return enumsToListString(ActionSupabaseDB.values); - } + static List getSupabaseDB(final ProjectConfigModel config) { + if (config.supabase is SupabaseConfigModelInitialized) { + return enumsToListString(ActionSupabaseDB.values); } + return []; } - static List getAirtableDB(final ProjectConfig? config) { - if (config != null) { - if (config.isAirtableReady) { - return enumsToListString(ActionAirtableDB.values); - } + static List getAirtableDB(final ProjectConfigModel config) { + if (config.airtable is AirtableConfigModelInitialized) { + return enumsToListString(ActionAirtableDB.values); } + return []; } - static List getSupabaseStorage(final ProjectConfig? config) { - if (config != null) { - if (config.isSupabaseReady) { - return enumsToListString(ActionSupabaseStorage.values); - } + static List getSupabaseStorage(final ProjectConfigModel config) { + if (config.supabase is SupabaseConfigModelInitialized) { + return enumsToListString(ActionSupabaseStorage.values); } + return []; } - static List getSupabaseFunctions(final ProjectConfig? config) { - if (config != null) { - if (config.isSupabaseReady) { - return enumsToListString(ActionSupabaseFunctions.values); - } + static List getSupabaseFunctions(final ProjectConfigModel config) { + if (config.supabase is SupabaseConfigModelInitialized) { + return enumsToListString(ActionSupabaseFunctions.values); } + return []; } @@ -892,7 +890,7 @@ class FActionElement extends Equatable { 'g': convertValueToDropdown(actionGesture), 'sA': convertValueToDropdown(actionSupabaseAuth), 'sD': convertValueToDropdown(actionSupabaseDB), - 'sA': convertValueToDropdown(actionAirtableDB), + 'airtableA': convertValueToDropdown(actionAirtableDB), 'supaFuncs': convertValueToDropdown(actionSupabaseFunctions), 'supaStor': convertValueToDropdown(actionSupabaseStorage), 'aC': convertValueToDropdown(actionCamera), diff --git a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart index 8ccbb79a..14821964 100644 --- a/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart +++ b/teta_widgets/lib/src/elements/widgets/airtable/fetch.dart @@ -53,9 +53,11 @@ class _WAirtableFetchState extends State { widget.state.loop, context, ); - final config = BlocProvider.of(context).state!.config; + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; var dbElements = []; - if (config != null && config.isAirtableReady) { + if (config.airtable is AirtableConfigModelInitialized) { final airtable = context.read(); dbElements = await airtable.getAllRecords(recordName); } else { diff --git a/teta_widgets/lib/src/elements/widgets/camera.dart b/teta_widgets/lib/src/elements/widgets/camera.dart index 4634e22c..2fcfa2f0 100644 --- a/teta_widgets/lib/src/elements/widgets/camera.dart +++ b/teta_widgets/lib/src/elements/widgets/camera.dart @@ -31,7 +31,7 @@ class WCamera extends StatefulWidget { class _WCameraState extends State { @override Widget build(final BuildContext context) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; VariableObject? variable; if (widget.controller.type == FTextTypeEnum.param) { variable = page.params diff --git a/teta_widgets/lib/src/elements/widgets/component.dart b/teta_widgets/lib/src/elements/widgets/component.dart index 5ea1a52f..69be25ea 100644 --- a/teta_widgets/lib/src/elements/widgets/component.dart +++ b/teta_widgets/lib/src/elements/widgets/component.dart @@ -53,16 +53,16 @@ class _WComponentState extends State { } Future calc() async { - prj = BlocProvider.of(context).state!; + final pages = context.read().state; PageObject? _component; - _component = prj.pages!.firstWhereOrNull( + _component = pages.firstWhereOrNull( (final element) => element.name == widget.componentName, ); if (_component != null) { _component = _component.copyWith( states: [ - ..._component.states + ..._component.defaultStates .map((final e) => e.toJson()) .map(VariableObject.fromJson) .toList() @@ -110,8 +110,9 @@ class _WComponentState extends State { final BuildContext context, ) async { final list = await sl.get().fetchNodesByPage(page.id); + if (list.error != null) return []; final nodes = []; - for (final e in list) { + for (final e in list.data!) { nodes.add( CNode.fromJson( e as Map, @@ -127,15 +128,12 @@ class _WComponentState extends State { ? BlocProvider( create: (final context) => PageCubit(sl.get()) ..onFocus( - prj: prj, page: component!, - context: context, forPlay: widget.state.forPlay, - isComponent: true, ), - child: BlocBuilder( - builder: (final context, final page) { - return (page.scaffold == null) + child: BlocBuilder( + builder: (final context, final state) { + return (state is! PageLoaded) ? const SizedBox() : NodeSelection( state: widget.state, @@ -144,13 +142,13 @@ class _WComponentState extends State { state: widget.state, child: IgnorePointer( ignoring: !widget.state.forPlay, - child: page.scaffold!.toWidget( + child: state.page.scaffold.toWidget( state: widget.state.copyWith( params: (widget.paramsToSend != null) ? getVariableObjectsFromParams(page) - : page.params, - states: page.states, - dataset: page.datasets, + : state.params, + states: state.states, + dataset: state.datasets, ), ), ), diff --git a/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart b/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart index fe2917cf..7b88f9dc 100644 --- a/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart +++ b/teta_widgets/lib/src/elements/widgets/google_maps/google_maps_web_mobile_widget.dart @@ -80,7 +80,6 @@ class _WGoogleMapsState extends State { @override void initState() { super.initState(); - print('GoogleMapsInitData'); initData(); } @@ -193,12 +192,10 @@ class _WGoogleMapsState extends State { Future initData() async { try { - googleMapsKey = BlocProvider.of(context) - .state! - .config - ?.googleMapsKey ?? - ''; - final page = BlocProvider.of(context).state; + googleMapsKey = (context.read().state as ConfigStateLoaded) + .config + .googleMapsKey; + final page = BlocProvider.of(context).state as PageLoaded; final VariableObject? variable; variable = page.states.firstWhereOrNull( diff --git a/teta_widgets/lib/src/elements/widgets/icon.dart b/teta_widgets/lib/src/elements/widgets/icon.dart index aa5a208c..b09e187a 100644 --- a/teta_widgets/lib/src/elements/widgets/icon.dart +++ b/teta_widgets/lib/src/elements/widgets/icon.dart @@ -46,8 +46,8 @@ class WIcon extends StatelessWidget { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color).withOpacity(tempOpacity); } diff --git a/teta_widgets/lib/src/elements/widgets/icon_feather.dart b/teta_widgets/lib/src/elements/widgets/icon_feather.dart index 3184f5d2..e93138dd 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_feather.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_feather.dart @@ -46,8 +46,8 @@ class WFeatherIcon extends StatelessWidget { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color).withOpacity(tempOpacity); } diff --git a/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart b/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart index e8d73284..29bd4dbe 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_font_awesome.dart @@ -45,8 +45,8 @@ class WFontAwesome extends StatelessWidget { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color).withOpacity(tempOpacity); } diff --git a/teta_widgets/lib/src/elements/widgets/icon_line.dart b/teta_widgets/lib/src/elements/widgets/icon_line.dart index 6a09a926..7754868d 100644 --- a/teta_widgets/lib/src/elements/widgets/icon_line.dart +++ b/teta_widgets/lib/src/elements/widgets/icon_line.dart @@ -45,8 +45,8 @@ class WLineIcon extends StatelessWidget { final tempOpacity = fill.levels?.first.opacity ?? 1; if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color).withOpacity(tempOpacity); } diff --git a/teta_widgets/lib/src/elements/widgets/map.dart b/teta_widgets/lib/src/elements/widgets/map.dart index 8698182a..ae03eec6 100644 --- a/teta_widgets/lib/src/elements/widgets/map.dart +++ b/teta_widgets/lib/src/elements/widgets/map.dart @@ -53,7 +53,7 @@ class _WMapState extends State { } Future init() async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; if (widget.controller.type == FTextTypeEnum.param) { variable = page.params .firstWhereOrNull((final e) => e.name == widget.controller.paramName); @@ -137,9 +137,8 @@ class _WMapState extends State { } return NodeSelectionBuilder( state: widget.state, - child: !BlocProvider.of(context) - .state! - .config! + child: (BlocProvider.of(context).state as ConfigStateLoaded) + .config .mapEnabled ? const DecoratedBox( decoration: BoxDecoration(color: Colors.black), @@ -226,10 +225,13 @@ class _WMapState extends State { controller: variable!.mapController!, builder: (final context, final x, final y, final z) { + final config = (context.read().state + as ConfigStateLoaded) + .config; final url = - 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${config.mapboxKey}'; final darkUrl = - 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${config.mapboxKey}'; return CNetworkImage( nid: widget.state.node.nid, src: widget.flag ? darkUrl : url, diff --git a/teta_widgets/lib/src/elements/widgets/map_builder.dart b/teta_widgets/lib/src/elements/widgets/map_builder.dart index 2dd3746b..7c1f20aa 100644 --- a/teta_widgets/lib/src/elements/widgets/map_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/map_builder.dart @@ -67,7 +67,7 @@ class _WMapBuilderState extends State { } Future init() async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; if (widget.controller.type == FTextTypeEnum.param) { variable = page.params .firstWhereOrNull((final e) => e.name == widget.controller.paramName); @@ -171,9 +171,8 @@ class _WMapBuilderState extends State { return NodeSelectionBuilder( state: widget.state, - child: !BlocProvider.of(context) - .state! - .config! + child: !(BlocProvider.of(context).state as ConfigStateLoaded) + .config .mapEnabled ? const DecoratedBox( decoration: BoxDecoration(color: Colors.black), @@ -262,10 +261,13 @@ class _WMapBuilderState extends State { controller: variable!.mapController!, builder: (final context, final x, final y, final z) { + final config = (context.read().state + as ConfigStateLoaded) + .config; final url = - 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/$z/$x/$y?access_token=${config.mapboxKey}'; final darkUrl = - 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${BlocProvider.of(context).state!.config?.mapboxKey}'; + 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/$z/$x/$y?access_token=${config.mapboxKey}'; return CNetworkImage( nid: widget.state.node.nid, src: widget.flag ? darkUrl : url, diff --git a/teta_widgets/lib/src/elements/widgets/scaffold.dart b/teta_widgets/lib/src/elements/widgets/scaffold.dart index 7c57943f..94440ab2 100644 --- a/teta_widgets/lib/src/elements/widgets/scaffold.dart +++ b/teta_widgets/lib/src/elements/widgets/scaffold.dart @@ -71,7 +71,8 @@ class _WScaffoldState extends State { @override Widget build(final BuildContext context) { - final isPage = BlocProvider.of(context).state.isPage; + final isPage = + (BlocProvider.of(context).state as PageLoaded).page.isPage; if (!isPage && !widget.state.forPlay) { return SizedBox( child: Center( @@ -155,7 +156,8 @@ class _WScaffoldState extends State { (final element) => element.globalType == NType.drawer, ); - final isPage = BlocProvider.of(context).state.isPage; + final isPage = + (BlocProvider.of(context).state as PageLoaded).page.isPage; if (!isPage) return _childWids(context); return Stack( children: [ diff --git a/teta_widgets/lib/src/elements/widgets/scaffold/mobile.dart b/teta_widgets/lib/src/elements/widgets/scaffold/mobile.dart index c2720f99..e6d44297 100644 --- a/teta_widgets/lib/src/elements/widgets/scaffold/mobile.dart +++ b/teta_widgets/lib/src/elements/widgets/scaffold/mobile.dart @@ -53,7 +53,7 @@ class ScaffoldMobile extends StatelessWidget { @override Widget build(final BuildContext context) { - final isPage = BlocProvider.of(context).state.isPage; + final isPage = (context.watch().state as PageLoaded).page.isPage; if (!isPage || children.indexWhere( (final element) => element.globalType == NType.appBar, @@ -153,21 +153,25 @@ class ScaffoldMobile extends StatelessWidget { ); } } - final isPage = BlocProvider.of(context).state.isPage; + final isPage = (context.watch().state as PageLoaded).page.isPage; if (!isPage) return childWids(context); return Stack( children: [ childWids(context), if (showAppBar) Positioned( - child: (appBar != null) ? appBar.toWidget(state: state) : const SizedBox(), + child: (appBar != null) + ? appBar.toWidget(state: state) + : const SizedBox(), ), if (showBottomBar) Positioned( bottom: 0, left: 0, right: 0, - child: (bottomBar != null) ? bottomBar.toWidget(state: state) : const SizedBox(), + child: (bottomBar != null) + ? bottomBar.toWidget(state: state) + : const SizedBox(), ), if (showDrawer && !state.forPlay) Positioned( diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart index d96f08a4..b546b9af 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart @@ -38,11 +38,10 @@ class _WCMSLoggedUserState extends State { Future load() async { final user = await TetaCMS.instance.auth.user.get; - if ((BlocProvider.of(context) - .state! - .config - ?.isRevenueCatEnabled ?? - false) && + if ((context.read().state as ConfigStateLoaded) + .config + .revenuecat + .isEnabled && UniversalPlatform.isAndroid) { await Purchases.logIn(user.uid!); } diff --git a/teta_widgets/lib/src/elements/widgets/w_audio_player.dart b/teta_widgets/lib/src/elements/widgets/w_audio_player.dart index 9e6feb69..4e7626d8 100644 --- a/teta_widgets/lib/src/elements/widgets/w_audio_player.dart +++ b/teta_widgets/lib/src/elements/widgets/w_audio_player.dart @@ -42,7 +42,7 @@ class _WAudioPlayerState extends State { Future initAudioPlayer() async { try { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; _map = DatasetObject( name: widget.state.node.name ?? diff --git a/teta_widgets/lib/src/elements/widgets/w_audio_player_progress_indicator.dart b/teta_widgets/lib/src/elements/widgets/w_audio_player_progress_indicator.dart index 3a4d83dd..fe7b1b0d 100644 --- a/teta_widgets/lib/src/elements/widgets/w_audio_player_progress_indicator.dart +++ b/teta_widgets/lib/src/elements/widgets/w_audio_player_progress_indicator.dart @@ -27,10 +27,12 @@ class WAudioPlayerProgressIndicator extends StatefulWidget { final FTextTypeInput controller; @override - State createState() => _WAudioPlayerProgressIndicatorState(); + State createState() => + _WAudioPlayerProgressIndicatorState(); } -class _WAudioPlayerProgressIndicatorState extends State { +class _WAudioPlayerProgressIndicatorState + extends State { bool isInitialized = false; AudioPlayer? audioController; @@ -41,12 +43,14 @@ class _WAudioPlayerProgressIndicatorState extends State init() async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; VariableObject? variable; if (widget.controller.type == FTextTypeEnum.param) { - variable = page.params.firstWhereOrNull((final e) => e.name == widget.controller.paramName); + variable = page.params + .firstWhereOrNull((final e) => e.name == widget.controller.paramName); } else { - variable = page.states.firstWhereOrNull((final e) => e.name == widget.controller.stateName); + variable = page.states + .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } if (variable?.audioController != null) { setState(() { @@ -79,7 +83,8 @@ class _WAudioPlayerProgressIndicatorState extends State>( - stream: Rx.combineLatest3>( + stream: Rx.combineLatest3>( audioController!.positionStream, audioController!.bufferedPositionStream, audioController!.durationStream, diff --git a/teta_widgets/lib/src/elements/widgets/w_audio_player_volume_indicator.dart b/teta_widgets/lib/src/elements/widgets/w_audio_player_volume_indicator.dart index 82fb6e3f..06ee33bc 100644 --- a/teta_widgets/lib/src/elements/widgets/w_audio_player_volume_indicator.dart +++ b/teta_widgets/lib/src/elements/widgets/w_audio_player_volume_indicator.dart @@ -27,10 +27,12 @@ class WAudioPlayerVolumeIndicator extends StatefulWidget { final FTextTypeInput controller; @override - State createState() => _WAudioPlayerVolumeIndicatorState(); + State createState() => + _WAudioPlayerVolumeIndicatorState(); } -class _WAudioPlayerVolumeIndicatorState extends State { +class _WAudioPlayerVolumeIndicatorState + extends State { bool isInitialized = false; AudioPlayer? audioController; @@ -41,12 +43,14 @@ class _WAudioPlayerVolumeIndicatorState extends State init() async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; VariableObject? variable; if (widget.controller.type == FTextTypeEnum.param) { - variable = page.params.firstWhereOrNull((final e) => e.name == widget.controller.paramName); + variable = page.params + .firstWhereOrNull((final e) => e.name == widget.controller.paramName); } else { - variable = page.states.firstWhereOrNull((final e) => e.name == widget.controller.stateName); + variable = page.states + .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } if (variable?.audioController != null) { if (mounted) { @@ -79,7 +83,8 @@ class _WAudioPlayerVolumeIndicatorState extends State>( - stream: Rx.combineLatest3>( + stream: Rx.combineLatest3>( audioController!.positionStream, audioController!.bufferedPositionStream, audioController!.volumeStream, diff --git a/teta_widgets/lib/src/elements/widgets/webview.dart b/teta_widgets/lib/src/elements/widgets/webview.dart index b1e104ef..33aca102 100644 --- a/teta_widgets/lib/src/elements/widgets/webview.dart +++ b/teta_widgets/lib/src/elements/widgets/webview.dart @@ -37,12 +37,14 @@ class _WWebViewXPageState extends State { @override void initState() { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; if (widget.controller.type == FTextTypeEnum.param) { - variable = page.params.firstWhereOrNull((final e) => e.name == widget.controller.paramName); + variable = page.params + .firstWhereOrNull((final e) => e.name == widget.controller.paramName); } else { - variable = page.states.firstWhereOrNull((final e) => e.name == widget.controller.stateName); + variable = page.states + .firstWhereOrNull((final e) => e.name == widget.controller.stateName); } super.initState(); From 7ccddc1f7e2819faa0d0544273e050f79eaf4feb Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Mon, 23 Jan 2023 11:44:30 +0100 Subject: [PATCH 17/23] feat(controls) --- .../actions/navigation/open_bottom_sheet.dart | 28 ++-- .../actions/navigation/open_page.dart | 35 ++--- .../actions/navigation/open_snack.dart | 26 ++-- .../src/elements/actions/supabase/delete.dart | 4 +- .../actions/supabase/function_invoke.dart | 4 +- .../src/elements/actions/supabase/insert.dart | 4 +- .../src/elements/actions/supabase/on_all.dart | 4 +- .../elements/actions/supabase/on_delete.dart | 4 +- .../elements/actions/supabase/on_insert.dart | 4 +- .../elements/actions/supabase/on_update.dart | 4 +- .../supabase/signin_w_credentials.dart | 8 +- .../actions/supabase/signin_w_provider.dart | 9 +- .../supabase/signup_w_credentials.dart | 7 +- .../actions/supabase/storage_delete.dart | 4 +- .../actions/supabase/storage_upload.dart | 4 +- .../src/elements/actions/supabase/update.dart | 4 +- .../elements/actions/teta_cms/auth/login.dart | 9 +- .../actions/teta_cms/database/on_all.dart | 4 +- .../lib/src/elements/builder/add_dataset.dart | 2 +- .../src/elements/builder/drag_and_drop.dart | 7 +- .../lib/src/elements/builder/gesture.dart | 3 +- .../src/elements/builder/node_selection.dart | 4 +- .../elements/builder/placeholder_child.dart | 4 +- .../src/elements/builder/save_dataset.dart | 2 +- .../controls/atoms/action_element.dart | 1 - .../controls/atoms/apicalls_request.dart | 132 ++++++++---------- .../controls/atoms/cms_collections.dart | 3 - .../src/elements/controls/atoms/delete.dart | 101 +------------- .../lib/src/elements/controls/atoms/fill.dart | 6 - .../lib/src/elements/controls/atoms/flag.dart | 7 +- .../controls/atoms/mixpanel/set_user_id.dart | 2 - .../controls/atoms/mixpanel/track.dart | 4 - .../controls/atoms/navigation/component.dart | 8 -- .../src/elements/controls/atoms/physics.dart | 2 - .../controls/atoms/revenuecat/buy.dart | 70 +++------- .../lib/src/elements/controls/atoms/size.dart | 74 ++++++---- .../elements/controls/atoms/src_image.dart | 37 ++--- .../src/elements/controls/atoms/states.dart | 4 - .../lib/src/elements/controls/atoms/text.dart | 4 - .../elements/controls/atoms/text_align.dart | 2 - .../controls/atoms/text_decoration.dart | 2 - .../elements/controls/atoms/text_styles.dart | 2 - .../controls/atoms/video/video_url.dart | 41 +++--- .../controls/atoms/webview_controller.dart | 4 - .../controls/current_song_controll.dart | 4 - .../controls/google_maps_cubit_control.dart | 4 - .../prefabs/sizes_prefab_control.dart | 4 - .../controls/prefabs/text_prefab_control.dart | 1 - 48 files changed, 273 insertions(+), 434 deletions(-) diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart index d8715781..628a5eb3 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_bottom_sheet.dart @@ -29,9 +29,11 @@ class FActionNavigationOpenBottomSheet { try { if (nameOfPage != null) { final prj = BlocProvider.of(context).state!; - final currentPage = BlocProvider.of(context).state; + final pages = BlocProvider.of(context).state; + final currentPageState = + BlocProvider.of(context).state as PageLoaded; PageObject? page; - page = prj.pages! + page = pages .firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( @@ -58,18 +60,18 @@ class FActionNavigationOpenBottomSheet { page = page.copyWith(flatList: nodes, scaffold: scaffold); await showModalBottomSheet( context: context, - builder: (final context) => page!.scaffold!.toWidget( + builder: (final context) => page!.scaffold.toWidget( state: state.copyWith( forPlay: true, params: passParamsToNewPage( - page.params, - currentPage.params, + page.defaultParams, + currentPageState.params, paramsToSend, state.dataset, loop: state.loop, ), - states: page.states, - dataset: page.datasets, + states: page.defaultStates, + dataset: currentPageState.datasets, ), ), ); @@ -90,12 +92,14 @@ class FActionNavigationOpenBottomSheet { ) { try { final prj = BlocProvider.of(context).state!; + final pages = BlocProvider.of(context).state; if (nameOfPage == null || - (prj.pages ?? []) - .indexWhere((final element) => element.name == nameOfPage) == - -1) return ''; + pages.indexWhere((final element) => element.name == nameOfPage) == + -1) { + return ''; + } final page = - prj.pages!.firstWhere((final element) => element.name == nameOfPage); + pages.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -115,7 +119,7 @@ class FActionNavigationOpenBottomSheet { final pageNameRC = ReCase(temp); final stringParamsToSend = StringBuffer()..write(''); - for (final param in page.params) { + for (final param in page.defaultParams) { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); // ignore: avoid_dynamic_calls diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart index a6c1a1da..02c1dd2e 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_page.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_page.dart @@ -54,10 +54,13 @@ class FActionNavigationOpenPage { ) async { try { final prj = BlocProvider.of(context).state!; - final currentPage = BlocProvider.of(context).state; + final pages = BlocProvider.of(context).state; + + final currentPage = + BlocProvider.of(context).state as PageLoaded; PageObject? page; - page = prj.pages! - .firstWhereOrNull((final element) => element.name == nameOfPage); + page = + pages.firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( 'nodes', @@ -82,22 +85,21 @@ class FActionNavigationOpenPage { final scaffold = sl.get().renderTree(nodes); page = page.copyWith(flatList: nodes, scaffold: scaffold); - BlocProvider.of(context) - .onFocus(prj: prj, page: page, context: context); + BlocProvider.of(context).onFocus(page: page, forPlay: true); await Navigator.push( context, MaterialPageRoute( builder: (final context) => BlocProvider( - create: (final context) => PageCubit(sl.get()) - ..onFocus(prj: prj, page: page!, context: context), - child: page!.scaffold!.toWidget( + create: (final context) => + PageCubit(sl.get())..onFocus(page: page!, forPlay: true), + child: page!.scaffold.toWidget( state: state.copyWith( forPlay: true, - states: page.states, - dataset: page.datasets, + states: page.defaultStates, + dataset: [], params: passParamsToNewPage( - page.params, + page.defaultParams, currentPage.params, paramsToSend, state.dataset, @@ -123,12 +125,13 @@ class FActionNavigationOpenPage { final Map? paramsToSend, ) { final prj = BlocProvider.of(context).state!; + final pages = BlocProvider.of(context).state; + if (nameOfPage == null || - (prj.pages ?? []) - .indexWhere((final element) => element.name == nameOfPage) == - -1) return ''; + pages.indexWhere((final element) => element.name == nameOfPage) == -1) + return ''; final page = - prj.pages!.firstWhere((final element) => element.name == nameOfPage); + pages.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -148,7 +151,7 @@ class FActionNavigationOpenPage { final pageNameRC = ReCase(temp); final stringParamsToSend = StringBuffer()..write(''); - for (final param in page.params) { + for (final param in page.defaultParams) { // ignore: literal_only_boolean_expressions if ("${paramsToSend?[param.id]?['dataset']}" == 'States' || "${paramsToSend?[param.id]?['dataset']}" == 'Params') { diff --git a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart index ed50e459..542ae87a 100644 --- a/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart +++ b/teta_widgets/lib/src/elements/actions/navigation/open_snack.dart @@ -27,9 +27,12 @@ class FActionNavigationOpenSnackBar { try { if (nameOfPage != null) { final prj = BlocProvider.of(context).state!; - final currentPage = BlocProvider.of(context).state; + final pages = BlocProvider.of(context).state; + + final currentPage = + BlocProvider.of(context).state as PageLoaded; PageObject? page; - page = prj.pages! + page = pages .firstWhereOrNull((final element) => element.name == nameOfPage); if (page != null) { final list = await TetaDB.instance.client.selectList( @@ -55,13 +58,13 @@ class FActionNavigationOpenSnackBar { final scaffold = sl.get().renderTree(nodes); page = page.copyWith(flatList: nodes, scaffold: scaffold); final snackBar = SnackBar( - content: page.scaffold!.toWidget( + content: page.scaffold.toWidget( state: state.copyWith( forPlay: true, - states: page.states, - dataset: page.datasets, + states: page.defaultStates, + dataset: [], params: passParamsToNewPage( - page.params, + page.defaultParams, currentPage.params, paramsToSend, state.dataset, @@ -85,12 +88,13 @@ class FActionNavigationOpenSnackBar { ) { try { final prj = BlocProvider.of(context).state!; + final pages = BlocProvider.of(context).state; + if (nameOfPage == null || - (prj.pages ?? []) - .indexWhere((final element) => element.name == nameOfPage) == - -1) return ''; + pages.indexWhere((final element) => element.name == nameOfPage) == -1) + return ''; final page = - prj.pages!.firstWhere((final element) => element.name == nameOfPage); + pages.firstWhere((final element) => element.name == nameOfPage); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -110,7 +114,7 @@ class FActionNavigationOpenSnackBar { final pageNameRC = ReCase(temp); final stringParamsToSend = StringBuffer()..write(''); - for (final param in page.params) { + for (final param in page.defaultParams) { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); final valueToSend = (paramsToSend ?? {})[param.id] diff --git a/teta_widgets/lib/src/elements/actions/supabase/delete.dart b/teta_widgets/lib/src/elements/actions/supabase/delete.dart index 9ed3fee3..3a78684c 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/delete.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/delete.dart @@ -22,7 +22,7 @@ class FASupabaseDelete { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -79,7 +79,7 @@ class FASupabaseDelete { final FTextTypeInput? supabaseFrom, final MapElement? supabaseEq, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/function_invoke.dart b/teta_widgets/lib/src/elements/actions/supabase/function_invoke.dart index 6eee387f..e034b907 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/function_invoke.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/function_invoke.dart @@ -23,7 +23,7 @@ class FASupabaseFunctionsInvoke { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -99,7 +99,7 @@ class FASupabaseFunctionsInvoke { final List? body, final List? headers, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/insert.dart b/teta_widgets/lib/src/elements/actions/supabase/insert.dart index f8c01415..5389514b 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/insert.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/insert.dart @@ -23,7 +23,7 @@ class FASupabaseInsert { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -84,7 +84,7 @@ class FASupabaseInsert { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/on_all.dart b/teta_widgets/lib/src/elements/actions/supabase/on_all.dart index 3a08ffaa..69709dd1 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/on_all.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/on_all.dart @@ -23,7 +23,7 @@ class FASupabaseOnAll { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final client = BlocProvider.of(context).state; final state = takeStateFrom(page, stateName ?? ''); if (client != null) { @@ -55,7 +55,7 @@ class FASupabaseOnAll { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/on_delete.dart b/teta_widgets/lib/src/elements/actions/supabase/on_delete.dart index a2bc4446..3224747e 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/on_delete.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/on_delete.dart @@ -23,7 +23,7 @@ class FASupabaseOnDelete { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final client = BlocProvider.of(context).state; final state = takeStateFrom(page, stateName ?? ''); if (client != null) { @@ -55,7 +55,7 @@ class FASupabaseOnDelete { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/on_insert.dart b/teta_widgets/lib/src/elements/actions/supabase/on_insert.dart index 6ebb8fa6..cabcf6a2 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/on_insert.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/on_insert.dart @@ -23,7 +23,7 @@ class FASupabaseOnInsert { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final client = BlocProvider.of(context).state; final state = takeStateFrom(page, stateName ?? ''); if (client != null) { @@ -55,7 +55,7 @@ class FASupabaseOnInsert { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/on_update.dart b/teta_widgets/lib/src/elements/actions/supabase/on_update.dart index 8fcc5ff4..b66a5deb 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/on_update.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/on_update.dart @@ -23,7 +23,7 @@ class FASupabaseOnUpdate { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final client = BlocProvider.of(context).state; final state = takeStateFrom(page, stateName ?? ''); if (client != null) { @@ -55,7 +55,7 @@ class FASupabaseOnUpdate { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/signin_w_credentials.dart b/teta_widgets/lib/src/elements/actions/supabase/signin_w_credentials.dart index a7218246..993c05a7 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/signin_w_credentials.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/signin_w_credentials.dart @@ -24,7 +24,7 @@ class FASupabaseSignInWithCredentials { final String? nameOfPage, final Map? paramsToSend, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take email from states final email = takeStateFrom(page, 'email'); @@ -39,8 +39,8 @@ class FASupabaseSignInWithCredentials { changeState(status, context, 'Loading'); final client = BlocProvider.of(context).state; if (client != null) { - final response = - await client.auth.signIn(email: '${email.get}', password: '${password.get}'); + final response = await client.auth + .signIn(email: '${email.get}', password: '${password.get}'); if (response.error != null) { changeState(status, context, '${response.error?.message}'); } else { @@ -65,7 +65,7 @@ class FASupabaseSignInWithCredentials { final String? nameOfPage, final Map? paramsToSend, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final email = takeStateFrom(page, 'email'); final password = takeStateFrom(page, 'password'); diff --git a/teta_widgets/lib/src/elements/actions/supabase/signin_w_provider.dart b/teta_widgets/lib/src/elements/actions/supabase/signin_w_provider.dart index 5c3cb08f..09914cee 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/signin_w_provider.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/signin_w_provider.dart @@ -29,7 +29,7 @@ class FASupabaseSignInWithProvider { final Map? paramsToSend, final Provider provider, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -37,14 +37,15 @@ class FASupabaseSignInWithProvider { changeState(status, context, 'Loading'); final client = BlocProvider.of(context).state; if (client != null) { - final response = - await UserSocialLoginService.instance.executeLogin(client.supabaseUrl, provider); + final response = await UserSocialLoginService.instance + .executeLogin(client.supabaseUrl, provider); if (!UniversalPlatform.isWeb) { uriLinkStream.listen( (final Uri? uri) { if (uri != null) { - final uriParameters = SupabaseAuth.instance.parseUriParameters(Uri.base); + final uriParameters = + SupabaseAuth.instance.parseUriParameters(Uri.base); if (uriParameters.containsKey('access_token') && uriParameters.containsKey('refresh_token') && uriParameters.containsKey('expires_in')) { diff --git a/teta_widgets/lib/src/elements/actions/supabase/signup_w_credentials.dart b/teta_widgets/lib/src/elements/actions/supabase/signup_w_credentials.dart index beeb96fe..d3933080 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/signup_w_credentials.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/signup_w_credentials.dart @@ -24,7 +24,7 @@ class FASupabaseSignUp { final String? nameOfPage, final Map? paramsToSend, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take email from states final email = takeStateFrom(page, 'email'); @@ -39,7 +39,8 @@ class FASupabaseSignUp { changeState(status, context, 'Loading'); final client = BlocProvider.of(context).state; if (client != null) { - final response = await client.auth.signUp('${email.get}', '${password.get}'); + final response = + await client.auth.signUp('${email.get}', '${password.get}'); if (response.error != null) { changeState(status, context, '${response.error?.message}'); } else { @@ -62,7 +63,7 @@ class FASupabaseSignUp { final String? nameOfPage, final Map? paramsToSend, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final email = takeStateFrom(page, 'email'); final password = takeStateFrom(page, 'password'); diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage_delete.dart b/teta_widgets/lib/src/elements/actions/supabase/storage_delete.dart index 3f62d8ce..4b75cd01 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/storage_delete.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/storage_delete.dart @@ -23,7 +23,7 @@ class FASupabaseStorageRemove { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -67,7 +67,7 @@ class FASupabaseStorageRemove { final FTextTypeInput? pathFile, final int? loop, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; final from = supabaseFrom?.toCode( diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart b/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart index d70d4d90..42aa4025 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart @@ -26,7 +26,7 @@ class FASupabaseStorageUpload { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -107,7 +107,7 @@ class FASupabaseStorageUpload { final String stateName2, final int? loop, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; final from = supabaseFrom?.toCode( diff --git a/teta_widgets/lib/src/elements/actions/supabase/update.dart b/teta_widgets/lib/src/elements/actions/supabase/update.dart index 9c22e24a..4412ecea 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/update.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/update.dart @@ -23,7 +23,7 @@ class FASupabaseUpdate { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; // Take status from states final status = takeStateFrom(page, 'status'); @@ -105,7 +105,7 @@ class FASupabaseUpdate { final List? supabaseData, final MapElement? supabaseEq, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart index 731a5746..0f9419c1 100644 --- a/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart +++ b/teta_widgets/lib/src/elements/actions/teta_cms/auth/login.dart @@ -65,8 +65,9 @@ class FATetaCMSLogin { final String? nameOfPage, final Map? paramsToSend, ) { - final prj = BlocProvider.of(context).state!; - final isRevenueCatEnabled = config?.isRevenueCatEnabled ?? false; + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; final providerStr = provider == TetaProvider.google ? 'TetaProvider.google' : provider == TetaProvider.twitter @@ -79,8 +80,8 @@ class FATetaCMSLogin { provider: $providerStr, onSuccess: (final isFirstTime) async { final user = await TetaCMS.instance.auth.user.get; - ${isRevenueCatEnabled ? r"LogInResult result = await Purchases.logIn('${user.uid}');" : ''} - ${prj.config?.isQonversionReady ?? false ? r"Qonversion.setProperty(QUserProperty.customUserId, '${user.uid}');" : ''} + ${config.revenuecat.isEnabled ? r"LogInResult result = await Purchases.logIn('${user.uid}');" : ''} + ${config.qonversion.isEnabled ? r"Qonversion.setProperty(QUserProperty.customUserId, '${user.uid}');" : ''} ${FActionNavigationOpenPage.toCode(context, nameOfPage, paramsToSend)} } ); diff --git a/teta_widgets/lib/src/elements/actions/teta_cms/database/on_all.dart b/teta_widgets/lib/src/elements/actions/teta_cms/database/on_all.dart index caa9201a..b8de7cf2 100644 --- a/teta_widgets/lib/src/elements/actions/teta_cms/database/on_all.dart +++ b/teta_widgets/lib/src/elements/actions/teta_cms/database/on_all.dart @@ -23,7 +23,7 @@ class FATetaCMSOnAll { final List dataset, final int? loop, ) async { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final state = takeStateFrom(page, stateName ?? ''); if (collection != null) { final collectionId = collection.get( @@ -53,7 +53,7 @@ class FATetaCMSOnAll { final FTextTypeInput? supabaseFrom, final List? supabaseData, ) { - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; final status = takeStateFrom(page, 'status'); final client = BlocProvider.of(context).state; if (client != null) { diff --git a/teta_widgets/lib/src/elements/builder/add_dataset.dart b/teta_widgets/lib/src/elements/builder/add_dataset.dart index 16393d4c..e1efc574 100644 --- a/teta_widgets/lib/src/elements/builder/add_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/add_dataset.dart @@ -14,7 +14,7 @@ List addDataset( ) { final list = [...dataset, map]; final prj = BlocProvider.of(context).state!; - final pageFocused = BlocProvider.of(context).state; + final pageFocused = BlocProvider.of(context).state as PageLoaded; try { var flag = true; diff --git a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart index 6899bc07..a2a8fa06 100644 --- a/teta_widgets/lib/src/elements/builder/drag_and_drop.dart +++ b/teta_widgets/lib/src/elements/builder/drag_and_drop.dart @@ -29,9 +29,9 @@ class _DragAndDropBuilderState extends State { @override void initState() { + final page = (context.read().state as PageLoaded).page; parent = sl.get().findParentByChildrenIds( - flatList: - BlocProvider.of(context).state.flatList ?? [], + flatList: page.flatList, element: widget.state.node, ); canReceiveDrag = parent?.globalType == NType.row || @@ -54,11 +54,12 @@ class _DragAndDropBuilderState extends State { parent?.childrenIds.ids.indexOf(widget.state.node.nid); if (currentIndex == null) return; if (parent == null) return; + final page = (context.read().state as PageLoaded).page; await sl.get().addNodeWithCustomIndex( node: data.node!, parent: parent!, index: onLeft ?? false ? currentIndex : currentIndex + 1, - pageId: BlocProvider.of(context).state.id, + pageId: page.id, ); }, onMove: (final details) { diff --git a/teta_widgets/lib/src/elements/builder/gesture.dart b/teta_widgets/lib/src/elements/builder/gesture.dart index ad401cad..09a9d2d1 100644 --- a/teta_widgets/lib/src/elements/builder/gesture.dart +++ b/teta_widgets/lib/src/elements/builder/gesture.dart @@ -32,6 +32,7 @@ class GestureBuilder { ); } if (action != null) { + final page = (context.read().state as PageLoaded).page; action.actions! .where((final element) => element.actionGesture == gesture) .forEach( @@ -40,7 +41,7 @@ class GestureBuilder { context, state, finalValue, - BlocProvider.of(context).state.scaffold!, + page.scaffold, ); Logger.printMessage('Action performed'); }, diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index 322cedc4..f12afdea 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -32,11 +32,11 @@ class NodeSelectionState extends State { @override void initState() { + final page = (context.read().state as PageLoaded).page; do { parents.add( sl.get().findParentByChildrenIds( - flatList: - BlocProvider.of(context).state.flatList ?? [], + flatList: page.flatList, element: widget.state.node, ), ); diff --git a/teta_widgets/lib/src/elements/builder/placeholder_child.dart b/teta_widgets/lib/src/elements/builder/placeholder_child.dart index e8cf5bd5..cebed551 100644 --- a/teta_widgets/lib/src/elements/builder/placeholder_child.dart +++ b/teta_widgets/lib/src/elements/builder/placeholder_child.dart @@ -39,12 +39,12 @@ class _PlaceholderChildBuilderState extends State { setState(() { isDragging = true; }); - + final page = (context.read().state as PageLoaded).page; await sl.get().addNodeWithCustomIndex( node: data.node!, parent: widget.node, index: 0, - pageId: BlocProvider.of(context).state.id, + pageId: page.id, ); }, onMove: (final details) { diff --git a/teta_widgets/lib/src/elements/builder/save_dataset.dart b/teta_widgets/lib/src/elements/builder/save_dataset.dart index dde6c494..d6e7f96c 100644 --- a/teta_widgets/lib/src/elements/builder/save_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/save_dataset.dart @@ -14,7 +14,7 @@ Future> saveDatasets( final DatasetObject map, ) async { final list = [...dataset, map]; - final pageFocused = BlocProvider.of(context).state; + final pageFocused = BlocProvider.of(context).state as PageLoaded; final prj = BlocProvider.of(context).state!; try { Box> box; diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index ff840fba..af657819 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -154,7 +154,6 @@ class ActionElementControlState extends State { @override Widget build(final BuildContext context) { - print('actionElement: ${widget.element.actionType}'); //TODO: return Container( margin: const EdgeInsets.only(bottom: 8), diff --git a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart index 1b34a11c..ce687e7a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart @@ -10,7 +10,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_cms/teta_cms.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -29,8 +28,6 @@ class ApiCallsRequestControl extends StatefulWidget { } class ApiCallsRequestControlState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; List items = []; CollectionObject? collection; @@ -38,11 +35,11 @@ class ApiCallsRequestControlState extends State { List _requestList = []; List requestNames = []; String? collectionID; + @override void initState() { getRequest(); super.initState(); - nodeId = widget.node.nid; } Future getRequest() async { @@ -79,79 +76,68 @@ class ApiCallsRequestControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } - }, - child: BlocBuilder>( - builder: (final context, final state) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only( - bottom: 8, - ), - child: Row( - children: const [ - TParagraph( - 'Request', - ), - ], - ), + return BlocBuilder>( + builder: (final context, final state) { + if (state.length != 1) return const SizedBox(); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only( + bottom: 8, ), - if (_requestList != []) - CDropdown( - value: requestNames.firstWhereOrNull( - (final element) => - element == - (widget.requestName ?? - (widget.node.body.attributes[DBKeys.requestName] - as FTextTypeInput?) - ?.value), + child: Row( + children: const [ + TParagraph( + 'Request', ), - items: requestNames, - onChange: (final newValue) { - if (newValue != null) { - setState(() { - dropdown = newValue; - }); - var requestData = {}; - for (final e in _requestList) { - if ((e as Map)['_name'].toString() == - dropdown) { - requestData = e; - } - } - final old = widget.requestName; - final nw = requestNames.firstWhereOrNull( - (final element) => element == dropdown, - ); - if (widget.node.body.attributes[DBKeys.requestName] != - null && - widget.node.body.attributes[DBKeys.requestName] - is FTextTypeInput) { - (widget.node.body.attributes[DBKeys.requestName] - as FTextTypeInput) - .value = nw; - } - if (nw != null) { - widget.callBack(nw, old, requestData); + ], + ), + ), + if (_requestList != []) + CDropdown( + value: requestNames.firstWhereOrNull( + (final element) => + element == + (widget.requestName ?? + (state.first.body.attributes[DBKeys.requestName] + as FTextTypeInput?) + ?.value), + ), + items: requestNames, + onChange: (final newValue) { + if (newValue != null) { + setState(() { + dropdown = newValue; + }); + var requestData = {}; + for (final e in _requestList) { + if ((e as Map)['_name'].toString() == + dropdown) { + requestData = e; } } - }, - ), - ], - ); - }, - ), + final old = widget.requestName; + final nw = requestNames.firstWhereOrNull( + (final element) => element == dropdown, + ); + if (state.first.body.attributes[DBKeys.requestName] != + null && + state.first.body.attributes[DBKeys.requestName] + is FTextTypeInput) { + (state.first.body.attributes[DBKeys.requestName] + as FTextTypeInput) + .value = nw; + } + if (nw != null) { + widget.callBack(nw, old, requestData); + } + } + }, + ), + ], + ); + }, ); } } diff --git a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart index 24b47f39..8802ce9e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart @@ -27,15 +27,12 @@ class CMSCollectionControl extends StatefulWidget { } class CMSCollectionControlState extends State { - int? nodeId; - bool? isUpdated; String? dropdown; late Future> _future; @override void initState() { super.initState(); - nodeId = widget.node.nid; _future = TetaCMS.instance.client.getCollections(); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/delete.dart b/teta_widgets/lib/src/elements/controls/atoms/delete.dart index 2302589d..60c8c541 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/delete.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/delete.dart @@ -4,16 +4,10 @@ // Flutter imports: import 'package:flutter/material.dart'; // Package imports: -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:teta_core/src/rendering/find.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_repositories/src/node_repository.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/children_enum.dart'; -import 'package:teta_widgets/src/elements/nodes/dynamic.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; -class DeleteControl extends StatefulWidget { +class DeleteControl extends StatelessWidget { const DeleteControl({ required this.callBack, final Key? key, @@ -21,58 +15,8 @@ class DeleteControl extends StatefulWidget { final Function(bool) callBack; - @override - DeleteControlState createState() => DeleteControlState(); -} - -class DeleteControlState extends State { - double? height; - double? flag; - @override Widget build(final BuildContext context) { - height = MediaQuery.of(context).size.height; - final parentOfNode = sl.get().findParentByChildrenIds( - flatList: BlocProvider.of(context).state.flatList ?? [], - element: widget.node, - ); - final prj = BlocProvider.of(context).state!; - final pageState = BlocProvider.of(context).state; - if (widget.node.intrinsicState.canHave == - parentOfNode!.intrinsicState.canHave) { - return Padding( - padding: const EdgeInsets.only( - left: 4, - right: 4, - bottom: 8, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const TActionLabel( - 'Delete', - ), - Padding( - padding: const EdgeInsets.only(top: 8), - child: CDangerousButton( - label: 'Delete node', - callback: () async => - sl.get().removeNodeBetweenNodes( - context: context, - nodes: BlocProvider.of(context) - .state - .flatList ?? - [], - node: widget.node as NDynamic, - prj: prj, - page: pageState, - ), - ), - ), - ], - ), - ); - } return Padding( padding: const EdgeInsets.only( left: 4, @@ -88,11 +32,7 @@ class DeleteControlState extends State { Padding( padding: const EdgeInsets.only(top: 8), child: CDangerousButton( - label: widget.node.intrinsicState.canHave == ChildrenEnum.none - ? 'Delete' - : widget.node.intrinsicState.canHave == ChildrenEnum.child - ? 'Delete with child' - : 'Delete with children', + label: 'Delete', callback: delete, ), ), @@ -101,40 +41,5 @@ class DeleteControlState extends State { ); } - void delete() => widget.callBack(true); - - void showPicker() { - showDialog( - context: context, - builder: (final context) { - final cubit = GoogleFontsCubit(); - return BlocProvider( - create: (final context) => cubit, - child: AlertDialog( - backgroundColor: const Color(0xFF222222), - title: const THeadline2( - 'Are you sure you wanna delete me?', - ), - actions: [ - TextButton( - onPressed: delete, - child: const TActionLabel( - 'Delete', - color: Colors.red, - ), - ), - TextButton( - onPressed: () { - Navigator.of(context, rootNavigator: true).pop(null); - }, - child: const TActionLabel( - 'Cancel', - ), - ), - ], - ), - ); - }, - ); - } + void delete() => callBack(true); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill.dart b/teta_widgets/lib/src/elements/controls/atoms/fill.dart index 4b0a38ae..0d5a9edb 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill.dart @@ -13,7 +13,6 @@ import 'package:teta_widgets/src/elements/controls/atoms/fill/radial.dart'; import 'package:teta_widgets/src/elements/controls/atoms/fill/solid.dart'; import 'package:teta_widgets/src/elements/controls/atoms/fill/style.dart'; import 'package:teta_widgets/src/elements/features/features.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; enum FillTypeControlType { onlySolid, @@ -185,7 +184,6 @@ class FillControlState extends State { ? StyleFillControl( onlySolid: widget.type == FillTypeControlType.onlySolid, model: model!, - node: widget.node, callBack: widget.callBack, fill: widget.fill, ) @@ -195,7 +193,6 @@ class FillControlState extends State { title: widget.title ?? 'Fill', fill: widget.fill, color: widget.color, - node: widget.node, isStyled: false, callBack: widget.callBack, ) @@ -203,7 +200,6 @@ class FillControlState extends State { ? LinearFillControl( title: widget.title ?? 'Fill', fill: widget.fill, - node: widget.node, isStyled: false, callBack: widget.callBack, ) @@ -211,7 +207,6 @@ class FillControlState extends State { ? RadialFillControl( title: widget.title ?? 'Fill', fill: widget.fill, - node: widget.node, isStyled: false, callBack: widget.callBack, ) @@ -219,7 +214,6 @@ class FillControlState extends State { ? ImageFillControl( title: widget.title ?? 'Fill', fill: widget.fill, - node: widget.node, isStyled: false, callBack: widget.callBack, ) diff --git a/teta_widgets/lib/src/elements/controls/atoms/flag.dart b/teta_widgets/lib/src/elements/controls/atoms/flag.dart index cace36a0..3e3ea48b 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/flag.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/flag.dart @@ -4,8 +4,8 @@ // Flutter imports: import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_widgets/src/elements/nodes/dynamic.dart'; class FlagControl extends StatefulWidget { const FlagControl({ @@ -39,7 +39,10 @@ class FlagControlState extends State { switchOn = value; }); if (widget.keyValue != null) { - widget.node.body.attributes[widget.keyValue!] = value; + final nodes = BlocProvider.of(context).state; + if (nodes.isNotEmpty) { + nodes.first.body.attributes[widget.keyValue!] = value; + } } widget.callBack(value, widget.value); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart index 1844fd96..4554b5d5 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/set_user_id.dart @@ -30,9 +30,7 @@ class MixPanelSetUserId extends StatelessWidget { children: [ TextControl( valueType: VariableType.string, - node: node, value: action.valueTextTypeInput ?? FTextTypeInput(), - page: page, title: 'User ID', callBack: (final value, final old) { action.valueTextTypeInput = value; diff --git a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart index 3e560b4e..479b7f59 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/mixpanel/track.dart @@ -31,9 +31,7 @@ class MixPanelTrack extends StatelessWidget { children: [ TextControl( valueType: VariableType.string, - node: node, value: action.valueTextTypeInput ?? FTextTypeInput(), - page: page, title: 'Event name', callBack: (final value, final old) { action.valueTextTypeInput = value; @@ -42,8 +40,6 @@ class MixPanelTrack extends StatelessWidget { ), const Gap(Grid.small), HttpParamsControl( - node: node, - page: page, title: 'Event Properties', list: action.customHttpRequestBody ?? [], callBack: (final value, final old) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart index 9d635fa2..2c2eba90 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart @@ -29,8 +29,6 @@ class ComponentControl extends StatefulWidget { } class ComponentControlState extends State { - int? nodeId; - String? name; String? dropdown; PageObject? pageObject; Map map = {}; @@ -38,8 +36,6 @@ class ComponentControlState extends State { @override void initState() { super.initState(); - nodeId = widget.node.nid; - name = widget.node.body.attributes[DBKeys.componentName] as String? ?? ''; final components = widget.prj.pages!.where((final element) => !element.isPage).toList(); try { @@ -64,8 +60,6 @@ class ComponentControlState extends State { @override Widget build(final BuildContext context) { - final components = (widget.prj.pages ?? []) - .where((final element) => !element.isPage); return DecoratedBox( decoration: BoxDecoration( color: Colors.black, @@ -194,8 +188,6 @@ class ElementState extends State { @override void initState() { super.initState(); - Logger.printMessage('Datasets: ${widget.page.datasets}'); - Logger.printMessage('Params: ${widget.page.params}'); final params = Map.fromEntries( widget.page.params .where((final element) => widget.variable.type == element.type) diff --git a/teta_widgets/lib/src/elements/controls/atoms/physics.dart b/teta_widgets/lib/src/elements/controls/atoms/physics.dart index e2b4b9f4..2f61a06d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/physics.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/physics.dart @@ -11,13 +11,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class PhysicsControl extends StatefulWidget { const PhysicsControl({ - required this.node, required this.physic, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FPhysic physic; final Function(FPhysic, FPhysic) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart b/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart index 37557f9d..5f136a27 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/revenuecat/buy.dart @@ -21,20 +21,27 @@ class RevenueCatBuyActionWidget extends StatelessWidget { Widget build(final BuildContext context) { return Column( children: [ - CDropdown( - value: FActionElement.convertValueToDropdown( - element.actionRevenueCat, - ), - items: FActionElement.getRevenueCat(prj.config).toSet().toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = element; - element.actionRevenueCat = FActionElement.convertDropdownToValue( - ActionRevenueCat.values, - newValue, - ) as ActionRevenueCat?; - callback(element, old); - } + BlocBuilder( + builder: (final context, final state) { + if (state is! ConfigStateLoaded) return const SizedBox(); + return CDropdown( + value: FActionElement.convertValueToDropdown( + element.actionRevenueCat, + ), + items: + FActionElement.getRevenueCat(state.config).toSet().toList(), + onChange: (final newValue) { + if (newValue != null) { + final old = element; + element.actionRevenueCat = + FActionElement.convertDropdownToValue( + ActionRevenueCat.values, + newValue, + ) as ActionRevenueCat?; + callback(element, old); + } + }, + ); }, ), const Gap(Grid.medium), @@ -101,41 +108,6 @@ class RevenueCatBuyActionWidget extends StatelessWidget { ), ], ), - /* - const Gap(Grid.medium), - const THeadline3( - 'Choose a variable to save the status of the operation', - ), - TDetailLabel( - "The selected variable is set to 'Loading' during the operation, to 'Successful' if the payment is successful and to 'Failed' if it is not successful. The variable must be of String type.", - color: Palette.txtPrimary.withOpacity(0.6), - ), - const Gap(Grid.small), - CDropdown( - value: widget.page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList() - .indexWhere( - (final e) => e == widget.element.stateName, - ) != - -1 - ? widget.element.stateName - : null, - items: widget.page.states - .map((final e) => e.name) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - if (newValue != null) { - try { - final old = widget.element; - widget.element.stateName = newValue; - widget.callBack(widget.element, old); - } catch (e) {} - } - }, - ),*/ ], ); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/size.dart b/teta_widgets/lib/src/elements/controls/atoms/size.dart index c890af2a..b8fac563 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/size.dart @@ -127,7 +127,7 @@ class SizeControlsState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(), + builder: (final ctx) => const DevicesDialog(), ); }, child: Image.asset( @@ -154,7 +154,12 @@ class SizeControlsState extends State { final old = FSize.fromJson(widget.size.toJson()); value.replaceAll('%', ''); szs.updateSize(value, context); - widget.node.body.attributes[widget.keyAttr] = szs; + final nodes = + BlocProvider.of(context).state; + if (nodes.length == 1) { + nodes.first.body.attributes[widget.keyAttr] = + szs; + } widget.callBack(szs.toJson(), old.toJson()); }, value: flag, @@ -189,9 +194,13 @@ class SizeControlsState extends State { widget.size .updateUnit(SizeUnit.pixel, context); final szs = widget.size; - widget.node.body.attributes[widget.keyAttr] = - szs; - widget.callBack(szs.toJson(), old.toJson()); + final nodes = + BlocProvider.of(context).state; + if (nodes.length == 1) { + nodes.first.body + .attributes[widget.keyAttr] = szs; + widget.callBack(szs.toJson(), old.toJson()); + } }, child: unitIcon( unit: SizeUnit.pixel, @@ -205,9 +214,13 @@ class SizeControlsState extends State { widget.size .updateUnit(SizeUnit.percent, context); final szs = widget.size; - widget.node.body.attributes[widget.keyAttr] = - szs; - widget.callBack(szs.toJson(), old.toJson()); + final nodes = + BlocProvider.of(context).state; + if (nodes.length == 1) { + nodes.first.body + .attributes[widget.keyAttr] = szs; + widget.callBack(szs.toJson(), old.toJson()); + } }, child: unitIcon( unit: SizeUnit.percent, @@ -261,12 +274,17 @@ class SizeControlsState extends State { FSize.fromJson(widget.size.toJson()); value.replaceAll('%', ''); szs.updateSize(value, context); - widget.node.body - .attributes[widget.keyAttr] = szs; - widget.callBack( - szs.toJson(), - old.toJson(), - ); + final nodes = + BlocProvider.of(context) + .state; + if (nodes.length == 1) { + nodes.first.body + .attributes[widget.keyAttr] = szs; + widget.callBack( + szs.toJson(), + old.toJson(), + ); + } }, ), ), @@ -291,17 +309,23 @@ class SizeControlsState extends State { : '100%', context, ); - widget.node.body - .attributes[widget.keyAttr] = - widget.size; - widget.callBack( - widget.size.toJson(), - old.toJson(), - ); - controller.text = - widget.size.unit == SizeUnit.pixel - ? 'max' - : '100%'; + final nodes = + BlocProvider.of( + context, + ).state; + if (nodes.length == 1) { + nodes.first.body.attributes[ + widget.keyAttr] = widget.size; + widget.callBack( + widget.size.toJson(), + old.toJson(), + ); + controller.text = + widget.size.unit == + SizeUnit.pixel + ? 'max' + : '100%'; + } }, child: maxIcon( unit: widget.size.unit, diff --git a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart index 3ef0288c..66ae5c77 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart @@ -15,16 +15,12 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SrcImageControl extends StatefulWidget { const SrcImageControl({ - required this.node, - required this.page, required this.title, required this.image, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; - final PageObject page; final String title; final FTextTypeInput image; final Function(FTextTypeInput, FTextTypeInput) callBack; @@ -34,8 +30,6 @@ class SrcImageControl extends StatefulWidget { } class SrcImageControlState extends State { - int? nodeId; - bool? isUpdated; String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; @@ -46,7 +40,6 @@ class SrcImageControlState extends State { @override void initState() { try { - nodeId = widget.node.nid; text = widget.image.value ?? ''; controller.text = widget.image.value!; typeOfInput = widget.image.type!; @@ -54,11 +47,12 @@ class SrcImageControlState extends State { databaseAttribute = widget.image.datasetAttr!; } catch (_) {} try { - list = (widget.page.datasets.indexWhere( + final pageState = context.watch().state as PageLoaded; + list = (pageState.datasets.indexWhere( (final element) => element.getName == widget.image.datasetName, ) != -1) - ? widget.page.datasets + ? pageState.datasets .firstWhere( (final element) => element.getName == widget.image.datasetName, orElse: () { @@ -79,16 +73,11 @@ class SrcImageControlState extends State { @override Widget build(final BuildContext context) { + final pageState = context.watch().state as PageLoaded; return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - controller.text = widget.image.value ?? ''; - }); - nodeId = state.first.nid; - } + controller.text = widget.image.value ?? ''; } }, child: Column( @@ -154,15 +143,14 @@ class SrcImageControlState extends State { ), if (widget.image.type == FTextTypeEnum.param) CDropdown( - value: widget.page.params + value: pageState.params .map((final e) => e.name) .toSet() .toList() .contains(widget.image.paramName) ? widget.image.paramName : null, - items: - widget.page.params.map((final e) => e.name).toSet().toList(), + items: pageState.params.map((final e) => e.name).toSet().toList(), onChange: (final newValue) { final old = widget.image; widget.image.paramName = newValue; @@ -171,15 +159,14 @@ class SrcImageControlState extends State { ), if (widget.image.type == FTextTypeEnum.state) CDropdown( - value: widget.page.states + value: pageState.states .map((final e) => e.name) .toSet() .toList() .contains(widget.image.stateName) ? widget.image.stateName : null, - items: - widget.page.states.map((final e) => e.name).toSet().toList(), + items: pageState.states.map((final e) => e.name).toSet().toList(), onChange: (final newValue) { final old = widget.image; widget.image.stateName = newValue; @@ -188,14 +175,14 @@ class SrcImageControlState extends State { ), if (widget.image.type == FTextTypeEnum.dataset) CDropdown( - value: widget.page.datasets + value: pageState.datasets .map((final e) => e.getName) .where((final element) => element != 'null') .toSet() .contains(widget.image.datasetName) ? widget.image.datasetName : null, - items: widget.page.datasets + items: pageState.datasets .map((final e) => e.getName) .where((final element) => element != 'null') .toSet() @@ -214,7 +201,7 @@ class SrcImageControlState extends State { Padding( padding: EI.smT, child: CDropdown( - value: widget.page.datasets.indexWhere( + value: pageState.datasets.indexWhere( (final element) => element.getName == widget.image.datasetName, ) != diff --git a/teta_widgets/lib/src/elements/controls/atoms/states.dart b/teta_widgets/lib/src/elements/controls/atoms/states.dart index 329f98c8..30468116 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/states.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/states.dart @@ -16,14 +16,10 @@ import 'package:uuid/uuid.dart'; class StatesControl extends StatefulWidget { const StatesControl({ - required this.node, - required this.page, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; - final PageObject page; final Function(List) callBack; @override diff --git a/teta_widgets/lib/src/elements/controls/atoms/text.dart b/teta_widgets/lib/src/elements/controls/atoms/text.dart index 13b33e94..82db886a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text.dart @@ -22,9 +22,7 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextControl extends StatefulWidget { const TextControl({ required this.valueType, - required this.node, required this.value, - required this.page, required this.title, required this.callBack, this.withConvertTo = false, @@ -34,9 +32,7 @@ class TextControl extends StatefulWidget { }) : super(key: key); final VariableType? valueType; - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final bool isSubControl; final bool withConvertTo; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_align.dart b/teta_widgets/lib/src/elements/controls/atoms/text_align.dart index a6dfaa73..dc086814 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_align.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_align.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextAlignControls extends StatefulWidget { const TextAlignControls({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart b/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart index f89e200b..0d63d707 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart @@ -14,13 +14,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextDecorationControl extends StatelessWidget { const TextDecorationControl({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(Map, Map) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart index 7ca891af..9b6f9d91 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart @@ -15,13 +15,11 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextStylesControl extends StatefulWidget { const TextStylesControl({ - required this.node, required this.textStyle, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextStyle textStyle; final Function(String?, bool, String?) callBack; diff --git a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart index 662f6afd..b66d7e59 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart @@ -38,37 +38,40 @@ class PaddingsState extends State { @override void initState() { + final pageState = BlocProvider.of(context).state as PageLoaded; text = 'https://www.youtube.com/watch?v=${widget.value.get( - BlocProvider.of(context).state.params, - BlocProvider.of(context).state.states, - BlocProvider.of(context).state.datasets, + pageState.params, + pageState.states, + pageState.datasets, false, null, context, )}'; - tempNode = widget.node; controller.text = text!; urlState = widget.value.get( - BlocProvider.of(context).state.params, - BlocProvider.of(context).state.states, - BlocProvider.of(context).state.datasets, + pageState.params, + pageState.states, + pageState.datasets, false, null, context, ); - controllerVideo = YoutubePlayerController( - initialVideoId: urlState!, - params: YoutubePlayerParams( - startAt: Duration( - seconds: widget.node.body.attributes[DBKeys.startAt] as int, + final nodes = BlocProvider.of(context).state; + if (nodes.isNotEmpty) { + controllerVideo = YoutubePlayerController( + initialVideoId: urlState!, + params: YoutubePlayerParams( + startAt: Duration( + seconds: nodes.first.body.attributes[DBKeys.startAt] as int, + ), + showControls: + nodes.first.body.attributes[DBKeys.showControls] as bool, + showFullscreenButton: + nodes.first.body.attributes[DBKeys.isFullWidth] as bool, + mute: true, ), - showControls: widget.node.body.attributes[DBKeys.showControls] as bool, - showFullscreenButton: - widget.node.body.attributes[DBKeys.isFullWidth] as bool, - mute: true, - ), - ); - + ); + } super.initState(); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart index 2faf43c5..67677293 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class WebViewControllerControl extends StatefulWidget { const WebViewControllerControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/current_song_controll.dart b/teta_widgets/lib/src/elements/controls/current_song_controll.dart index d77478c0..8b31478b 100644 --- a/teta_widgets/lib/src/elements/controls/current_song_controll.dart +++ b/teta_widgets/lib/src/elements/controls/current_song_controll.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class CurrentSongControl extends StatefulWidget { const CurrentSongControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart index 56b669e5..c1ff7903 100644 --- a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart +++ b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart @@ -12,17 +12,13 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class GoogleMapsCubitControl extends StatefulWidget { const GoogleMapsCubitControl({ - required this.node, required this.value, - required this.page, required this.title, required this.callBack, final Key? key, }) : super(key: key); - final CNode node; final FTextTypeInput value; - final PageObject page; final String title; final Function(FTextTypeInput, FTextTypeInput) callBack; diff --git a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart index 9948c626..758a227d 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart @@ -13,12 +13,10 @@ import 'package:teta_widgets/src/elements/nodes/node.dart'; class SizesPrefabControl extends StatelessWidget { const SizesPrefabControl({ - required this.node, required this.values, final Key? key, }) : super(key: key); - final CNode node; final List values; @override @@ -33,7 +31,6 @@ class SizesPrefabControl extends StatelessWidget { ), ), SizeControl( - node: node, size: values.first, isWidth: true, title: 'Width', @@ -50,7 +47,6 @@ class SizesPrefabControl extends StatelessWidget { }, ), SizeControl( - node: node, size: values.last, isWidth: false, title: 'Height', diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index 5adf9edc..ae3a8130 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -201,7 +201,6 @@ class TextPrefabControl extends StatelessWidget { FillControl( title: 'Text Color', fill: textStyle.fill ?? FFill(), - node: node, isImageEnabled: false, isNoneEnabled: false, type: FillTypeControlType.onlySolid, From bee703202d880a67e03bf03e919e86c447e93ba6 Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Mon, 23 Jan 2023 18:55:12 +0100 Subject: [PATCH 18/23] feat --- .../lib/src/elements/builder/add_dataset.dart | 27 +- .../src/elements/builder/save_dataset.dart | 13 +- .../lib/src/elements/code/formatter_test.dart | 3 +- .../elements/code/page/code_component.dart | 3 +- .../lib/src/elements/code/page/scaffold.dart | 26 +- .../code/templates/cms_logged_user.dart | 7 +- .../elements/code/templates/component.dart | 14 +- .../lib/src/elements/code/templates/map.dart | 4 +- .../src/elements/controls/atoms/action.dart | 443 ++++++++--------- .../controls/atoms/action_element.dart | 446 ++++++------------ .../elements/controls/atoms/action_value.dart | 331 ++++++------- .../controls/atoms/audio_controller.dart | 90 ++-- .../controls/atoms/camera_controller.dart | 88 ++-- .../controls/atoms/cms_collections.dart | 158 +++---- .../src/elements/controls/atoms/dataset.dart | 249 +++++----- .../controls/atoms/google_maps_control.dart | 88 ++-- .../controls/atoms/map_controller.dart | 75 +-- .../lib/src/elements/controls/atoms/name.dart | 52 +- .../controls/atoms/navigation/component.dart | 78 +-- .../elements/controls/atoms/page_params.dart | 113 +++-- .../atoms/{states.dart => page_states.dart} | 126 ++--- .../lib/src/elements/controls/atoms/text.dart | 263 ++++++----- .../controls/atoms/webview_controller.dart | 88 ++-- .../controls/current_song_controll.dart | 88 ++-- .../controls/google_maps_cubit_control.dart | 88 ++-- .../prefabs/sizes_prefab_control.dart | 20 +- .../controls/prefabs/text_prefab_control.dart | 356 +++++++------- .../lib/src/elements/controls/type.dart | 2 +- .../elements/features/actions/element.dart | 4 +- .../lib/src/elements/features/fill.dart | 6 +- .../lib/src/elements/widgets/badge.dart | 4 +- .../src/elements/widgets/bottombaritem.dart | 4 +- .../lib/src/elements/widgets/card.dart | 4 +- .../widgets/circular_progress_indicator.dart | 4 +- .../lib/src/elements/widgets/component.dart | 6 +- .../widgets/concentric_page_view.dart | 4 +- .../lib/src/elements/widgets/divider.dart | 4 +- .../lib/src/elements/widgets/placeholder.dart | 8 +- 38 files changed, 1682 insertions(+), 1705 deletions(-) rename teta_widgets/lib/src/elements/controls/atoms/{states.dart => page_states.dart} (82%) diff --git a/teta_widgets/lib/src/elements/builder/add_dataset.dart b/teta_widgets/lib/src/elements/builder/add_dataset.dart index e1efc574..6b3d124d 100644 --- a/teta_widgets/lib/src/elements/builder/add_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/add_dataset.dart @@ -25,19 +25,8 @@ List addDataset( break; } } - if (flag) pageFocused.datasets = [...pageFocused.datasets, map]; - - for (final page in prj.pages!) { - if (page.id == pageFocused.id) { - var flag = true; - for (final e in pageFocused.datasets) { - if (e.getName == map.getName) { - flag = false; - break; - } - } - if (flag) page.datasets = [...page.datasets, map]; - } + if (flag) { + context.read().updateDatasets([...pageFocused.datasets, map]); } Box> box; @@ -64,10 +53,16 @@ List addDataset( break; } } - if (flag) pageFocused.datasets = [...pageFocused.datasets, element]; + if (flag) { + context + .read() + .updateDatasets([...pageFocused.datasets, map]); + } } - for (final page in prj.pages!) { + /* + final pages = context.read().state; + for (final page in pages) { for (final element in list2) { var flag = true; for (final e in page.datasets) { @@ -80,7 +75,7 @@ List addDataset( } if (flag) page.datasets = [...page.datasets, element]; } - } + }*/ } return list; diff --git a/teta_widgets/lib/src/elements/builder/save_dataset.dart b/teta_widgets/lib/src/elements/builder/save_dataset.dart index d6e7f96c..def4fdd6 100644 --- a/teta_widgets/lib/src/elements/builder/save_dataset.dart +++ b/teta_widgets/lib/src/elements/builder/save_dataset.dart @@ -47,10 +47,15 @@ Future> saveDatasets( break; } } - if (flag) pageFocused.datasets = [...pageFocused.datasets, element]; + if (flag) { + context + .read() + .updateDatasets([...pageFocused.datasets, map]); + } } - for (final page in prj.pages!) { + /*final pages = BlocProvider.of(context).state; + for (final page in pages) { for (final element in list2) { var flag = true; for (final e in page.datasets) { @@ -65,9 +70,9 @@ Future> saveDatasets( } } - final list3 = [...dataset, ...list2]; + final list3 = [...dataset, ...list2];*/ - return list3; + return [...pageFocused.datasets, map]; } catch (e) { if (kDebugMode) { // ignore: avoid_print diff --git a/teta_widgets/lib/src/elements/code/formatter_test.dart b/teta_widgets/lib/src/elements/code/formatter_test.dart index ee01af91..52433967 100644 --- a/teta_widgets/lib/src/elements/code/formatter_test.dart +++ b/teta_widgets/lib/src/elements/code/formatter_test.dart @@ -1,6 +1,5 @@ import 'package:dart_style/dart_style.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_repositories/src/project_repository.dart'; class FormatterTest { static bool format(final String code) { @@ -23,7 +22,7 @@ class Test extends StatelessWidget { Logger.printError('Error formating: $e'); } if (result = false) { - sl.get().sendToCodeError(code); + //sl.get().sendToCodeError(code); } return result; } diff --git a/teta_widgets/lib/src/elements/code/page/code_component.dart b/teta_widgets/lib/src/elements/code/page/code_component.dart index 6d81314a..8493a6a8 100644 --- a/teta_widgets/lib/src/elements/code/page/code_component.dart +++ b/teta_widgets/lib/src/elements/code/page/code_component.dart @@ -17,8 +17,9 @@ Future codeComponentTemplate( final int pageId, ) async { final prj = BlocProvider.of(context).state!; + final pages = BlocProvider.of(context).state; - final page = prj.pages!.firstWhere((final element) => element.id == pageId); + final page = pages.firstWhere((final element) => element.id == pageId); final list1 = page.code!.split('void'); final imports = list1[0]; //returns my imports final list2 = page.code!.split('class'); diff --git a/teta_widgets/lib/src/elements/code/page/scaffold.dart b/teta_widgets/lib/src/elements/code/page/scaffold.dart index 351b1464..1c65ab84 100644 --- a/teta_widgets/lib/src/elements/code/page/scaffold.dart +++ b/teta_widgets/lib/src/elements/code/page/scaffold.dart @@ -28,7 +28,11 @@ Future pageCodeTemplate( final int? loop, ) async { final prj = BlocProvider.of(context).state!; - final page = prj.pages!.firstWhere((final element) => element.id == pageId); + final pages = BlocProvider.of(context).state; + final config = + (BlocProvider.of(context).state as ConfigStateLoaded).config; + + final page = pages.firstWhere((final element) => element.id == pageId); final temp = removeDiacritics( page.name .replaceFirst('0', 'A0') @@ -107,7 +111,7 @@ Future pageCodeTemplate( //----start parameters---- final paramsString = StringBuffer()..write(''); final parametersString = StringBuffer()..write(''); - for (final element in page.params) { + for (final element in page.defaultParams) { final rc = ReCase(element.name); final value = element.typeDeclaration(rc.camelCase) == 'String' ? "'''${element.get}'''" @@ -124,7 +128,7 @@ Future pageCodeTemplate( //----start states---- final statesString = StringBuffer()..write(''); - for (final element in page.states) { + for (final element in page.defaultStates) { final rc = ReCase(element.name); final value = element.typeDeclaration(rc.camelCase) == 'String' ? "'${element.get}'" @@ -138,13 +142,14 @@ Future pageCodeTemplate( //----end states---- //packages - if (page.isPage && page.flatList != null) { - for (final item in page.flatList!) { + if (page.isPage) { + for (final item in page.flatList) { PackagesService.instance.insertPackages(item.intrinsicState.packages); } } - final isSupabaseIntegrated = prj.config?.supabaseEnabled ?? false; + final isSupabaseIntegrated = + config.supabase is SupabaseConfigModelInitialized; final isARState = isSupabaseIntegrated ? page.isAuthenticatedRequired @@ -167,11 +172,10 @@ Future pageCodeTemplate( import 'package:myapp/constants.dart' as constantz; import 'package:hive_flutter/hive_flutter.dart'; ${page.isAuthenticatedRequired ? "import 'package:myapp/auth/auth_required_state.dart';" : "import 'package:myapp/auth/auth_state.dart';"} - ${prj.config?.isAdaptyReady ?? false ? "import 'package:adapty_flutter/adapty_flutter.dart';" : ''} - ${prj.config?.isRevenueCatEnabled ?? false ? "import 'package:purchases_flutter/purchases_flutter.dart';" : ''} - ${prj.config?.isQonversionReady ?? false ? "import 'package:qonversion_flutter/qonversion_flutter.dart';" : ''} - ${prj.config?.isBraintreeReady ?? false ? "import 'package:flutter_braintree/flutter_braintree.dart';" : ''} - ${prj.config?.isStripeEnabled ?? false ? "import 'package:flutter_stripe/flutter_stripe.dart'; \n import 'dart:convert' as convert;" : ''} + ${config.revenuecat is RevenueCatConfigModelInitialized ? "import 'package:purchases_flutter/purchases_flutter.dart';" : ''} + ${config.qonversion is QonversionConfigModelInitialized ? "import 'package:qonversion_flutter/qonversion_flutter.dart';" : ''} + ${config.braintree is BraintreeConfigModelInitialized ? "import 'package:flutter_braintree/flutter_braintree.dart';" : ''} + ${config.stripe is StripeConfigModelInitialized ? "import 'package:flutter_stripe/flutter_stripe.dart'; \n import 'dart:convert' as convert;" : ''} ${PackagesService.instance.getToCodePackages()} diff --git a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart index 9bf80229..2f0a6a6d 100644 --- a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart +++ b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart @@ -25,11 +25,10 @@ class CmsLoggedUserCodeTemplate { loader = await children[1].toCode(context); } - final revenueCatFlag = BlocProvider.of(context) - .state! + final revenueCatFlag = + (BlocProvider.of(context).state as ConfigStateLoaded) .config - ?.isRevenueCatEnabled ?? - false; + .revenuecat is RevenueCatConfigModelInitialized; final code = ''' TetaFutureBuilder( future: Future.sync(() async { diff --git a/teta_widgets/lib/src/elements/code/templates/component.dart b/teta_widgets/lib/src/elements/code/templates/component.dart index 6ab2b5c2..62077a09 100644 --- a/teta_widgets/lib/src/elements/code/templates/component.dart +++ b/teta_widgets/lib/src/elements/code/templates/component.dart @@ -10,7 +10,6 @@ import 'package:recase/recase.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/code/formatter_test.dart'; // Project imports: -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; import 'package:teta_widgets/src/elements/index.dart'; import 'package:teta_widgets/src/elements/nodes/node_body.dart'; @@ -21,17 +20,17 @@ Future componentCodeTemplate( final List children, final int pageId, ) async { - final prj = BlocProvider.of(context).state!; + final pages = BlocProvider.of(context).state; //this fix an error of badstate if (body.attributes[DBKeys.componentName] == null || - (prj.pages ?? []).indexWhere( + pages.indexWhere( (final element) => element.name == body.attributes[DBKeys.componentName], ) == -1) return ''; - final compWidget = prj.pages!.firstWhere( + final compWidget = pages.firstWhere( (final element) => element.name == body.attributes[DBKeys.componentName], ); @@ -56,7 +55,7 @@ Future componentCodeTemplate( final pageNameRC = ReCase(temp); //params final stringParamsToSend = StringBuffer()..write(''); - for (final param in compWidget.params) { + for (final param in compWidget.defaultParams) { final name = ReCase(param.name); stringParamsToSend.write('${name.camelCase}: '); final rc = ReCase(param.value.toString()); @@ -87,9 +86,8 @@ Future componentCodeTemplate( ); final pageNameRC = ReCase(temp); //params - final parametersString = StringBuffer()..write(''); final stringParamsToSend = StringBuffer()..write(''); - for (final param in compWidget.params) { + for (final param in compWidget.defaultParams) { if ("${paramsToSend?[param.id]?['dataset']}" == 'States' || "${paramsToSend?[param.id]?['dataset']}" == 'Params') { final valueToSend = (paramsToSend ?? {})[param.id] @@ -128,7 +126,7 @@ Future componentCodeTemplate( String prepareParamsForUi(final PageObject page, final NodeBody body) { final stringParamsToSend = StringBuffer()..write(''); - for (final param in page.params) { + for (final param in page.defaultParams) { final valueToSend = (body.attributes[DBKeys.paramsToSend] ?? {})[param.id]?['label'] as String? ?? 'null'; diff --git a/teta_widgets/lib/src/elements/code/templates/map.dart b/teta_widgets/lib/src/elements/code/templates/map.dart index bbea8a80..abd9dbeb 100644 --- a/teta_widgets/lib/src/elements/code/templates/map.dart +++ b/teta_widgets/lib/src/elements/code/templates/map.dart @@ -20,7 +20,9 @@ class MapCodeTemplate { ) async { final flag = body.attributes[DBKeys.flag] as bool; final mapBoxKey = - BlocProvider.of(context).state!.config?.mapboxKey; + (BlocProvider.of(context).state as ConfigStateLoaded) + .config + .mapboxKey; final code = ''' map.MapLayoutBuilder( diff --git a/teta_widgets/lib/src/elements/controls/atoms/action.dart b/teta_widgets/lib/src/elements/controls/atoms/action.dart index eb78933a..b60ec5b5 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action.dart @@ -52,7 +52,8 @@ class ActionControlState extends State { @override void initState() { super.initState(); - if (widget.prj.pages != null) pageObject = widget.prj.pages!.first; + final pages = context.read().state; + pageObject = pages.first; if (pageObject != null) dropdown = pageObject!.name; } @@ -63,216 +64,233 @@ class ActionControlState extends State { color: Colors.black, borderRadius: BorderRadius.circular(8), ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - for (final trigger in widget.node.intrinsicState.gestures.isNotEmpty - ? widget.node.intrinsicState.gestures - : [ - ActionGesture.onTap, - ActionGesture.onLongPress, - ActionGesture.onDoubleTap - ]) - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - TParagraph( - EnumToString.convertToString(trigger, camelCase: true), - ), - Divider( - color: Palette.txtPrimary.withOpacity(0.3), - ), - ElementButton( - title: 'New action', - isSelected: false, - icon: FeatherIcons.plus, - onTap: () { - final pageBloc = BlocProvider.of(context); - showDialog( - context: context, - builder: (final context) => BlocProvider.value( - value: pageBloc, - child: _NewActionAlert( - callback: (final value, final actionString) { - final dynamic action = - FActionElement.convertDropdownToValue( - value.type, - actionString, - ); - final old = widget.action; - widget.action.actions = [ - ...widget.action.actions ?? [], - FActionElement( - id: const Uuid().v1(), - actionType: value.actionType, - actionGesture: trigger, - actionState: - (action is ActionState) ? action : null, - actionNavigation: (action is ActionNavigation) - ? action - : null, - actionTheme: - (action is ActionTheme) ? action : null, - actionWebView: - (action is ActionWebView) ? action : null, - actionQonversion: (action is ActionQonversion) - ? action - : null, - actionAudioPlayer: - (action is ActionAudioPlayerActions) + child: BlocBuilder>( + builder: (final context, final state) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (final trigger + in state.first.intrinsicState.gestures.isNotEmpty + ? state.first.intrinsicState.gestures + : [ + ActionGesture.onTap, + ActionGesture.onLongPress, + ActionGesture.onDoubleTap + ]) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TParagraph( + EnumToString.convertToString(trigger, camelCase: true), + ), + Divider( + color: Palette.txtPrimary.withOpacity(0.3), + ), + ElementButton( + title: 'New action', + isSelected: false, + icon: FeatherIcons.plus, + onTap: () { + final pageBloc = BlocProvider.of(context); + showDialog( + context: context, + builder: (final context) => BlocProvider.value( + value: pageBloc, + child: _NewActionAlert( + callback: (final value, final actionString) { + final dynamic action = + FActionElement.convertDropdownToValue( + value.type, + actionString, + ); + final old = widget.action; + widget.action.actions = [ + ...widget.action.actions ?? [], + FActionElement( + id: const Uuid().v1(), + actionType: value.actionType, + actionGesture: trigger, + actionState: + (action is ActionState) ? action : null, + actionNavigation: + (action is ActionNavigation) + ? action + : null, + actionTheme: + (action is ActionTheme) ? action : null, + actionWebView: (action is ActionWebView) ? action : null, - actionRevenueCat: (action is ActionRevenueCat) - ? action - : null, - actionStripe: - (action is ActionStripe) ? action : null, - actionCamera: - (action is ActionCamera) ? action : null, - actionSupabaseAuth: - (action is ActionSupabaseAuth) + actionQonversion: + (action is ActionQonversion) + ? action + : null, + actionAudioPlayer: + (action is ActionAudioPlayerActions) + ? action + : null, + actionRevenueCat: + (action is ActionRevenueCat) + ? action + : null, + actionStripe: (action is ActionStripe) ? action : null, - actionSupabaseDB: (action is ActionSupabaseDB) - ? action - : null, - actionAirtableDB: (action is ActionAirtableDB) - ? action - : null, - actionTetaAuth: (action is ActionTetaCmsAuth) - ? action - : null, - actionTetaDB: - (action is ActionTetaCmsDB) ? action : null, - actionCustomHttpRequest: - (action is ActionCustomHttpRequest) + actionCamera: (action is ActionCamera) ? action : null, - actionApiCalls: - (action is ActionApiCalls) ? action : null, - actionTranslator: (action is ActionTranslator) - ? action - : null, - ) - ]; - widget.callBack(widget.action, old); - Navigator.of(context, rootNavigator: true) - .pop(null); - }, + actionSupabaseAuth: + (action is ActionSupabaseAuth) + ? action + : null, + actionSupabaseDB: + (action is ActionSupabaseDB) + ? action + : null, + actionAirtableDB: + (action is ActionAirtableDB) + ? action + : null, + actionTetaAuth: + (action is ActionTetaCmsAuth) + ? action + : null, + actionTetaDB: (action is ActionTetaCmsDB) + ? action + : null, + actionCustomHttpRequest: + (action is ActionCustomHttpRequest) + ? action + : null, + actionApiCalls: (action is ActionApiCalls) + ? action + : null, + actionTranslator: + (action is ActionTranslator) + ? action + : null, + ) + ]; + widget.callBack(widget.action, old); + Navigator.of(context, rootNavigator: true) + .pop(null); + }, + ), + ), + ); + }, + ), + for (final element + in (widget.action.actions ?? []) + .where( + (final element) => + element.actionGesture == trigger, + ) + .toList()) + ActionElementControl( + name: EnumToString.convertToString( + element.actionType, + camelCase: true, ), + element: element, + callBack: (final value, final old) { + final old = widget.action; + final index = widget.action.actions!.indexOf(element); + widget.action.actions![index] = value; + widget.callBack(widget.action, old); + }, + callBackToDelete: () { + final old = widget.action; + widget.action.actions!.remove(element); + widget.callBack(widget.action, old); + }, ), - ); - }, + const Gap(Grid.medium), + ], ), - for (final element in (widget.action.actions ?? - []) - .where((final element) => element.actionGesture == trigger) - .toList()) - ActionElementControl( - name: EnumToString.convertToString( - element.actionType, - camelCase: true, - ), - element: element, - prj: widget.prj, - page: widget.page, - node: widget.node, - callBack: (final value, final old) { - final old = widget.action; - final index = widget.action.actions!.indexOf(element); - widget.action.actions![index] = value; - widget.callBack(widget.action, old); - }, - callBackToDelete: () { - final old = widget.action; - widget.action.actions!.remove(element); - widget.callBack(widget.action, old); - }, + /*Padding( + padding: EdgeInsets.only( + bottom: widget.action.actions?.isEmpty ?? true ? 0 : 8, ), - const Gap(Grid.medium), - ], - ), - /*Padding( - padding: EdgeInsets.only( - bottom: widget.action.actions?.isEmpty ?? true ? 0 : 8, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const THeadline3( - 'Actions', - ), - Row( - children: [ - BounceSmall( - onTap: () { - final old = widget.action; - widget.action.actions = [ - ...widget.action.actions ?? [], - FActionElement(id: const Uuid().v1()) - ]; - widget.callBack(widget.action, old); - }, - child: HoverWidget( - hoverChild: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - ), - ), - child: const Icon( - Icons.add, - size: 24, - color: Colors.white, - ), - ), - onHover: (final e) {}, - child: Container( - padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - border: Border.all( - color: Colors.transparent, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const THeadline3( + 'Actions', + ), + Row( + children: [ + BounceSmall( + onTap: () { + final old = widget.action; + widget.action.actions = [ + ...widget.action.actions ?? [], + FActionElement(id: const Uuid().v1()) + ]; + widget.callBack(widget.action, old); + }, + child: HoverWidget( + hoverChild: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( + color: Colors.white, + ), + ), + child: const Icon( + Icons.add, + size: 24, + color: Colors.white, + ), + ), + onHover: (final e) {}, + child: Container( + padding: const EdgeInsets.all(4), + decoration: BoxDecoration( + border: Border.all( + color: Colors.transparent, + ), + ), + child: const Icon( + Icons.add, + size: 24, + color: Colors.white, + ), + ), ), ), - child: const Icon( - Icons.add, - size: 24, - color: Colors.white, - ), - ), + ], ), - ), - ], - ), - ], - ), - ), - Column( - children: widget.action.actions! - .map( - (final e) => ActionElementControl( - name: 'Action ${widget.action.actions!.indexOf(e)}', - element: e, - prj: widget.prj, - page: widget.page, - node: widget.node, - callBack: (final value, final old) { - final old = widget.action; - final index = widget.action.actions!.indexOf(e); - widget.action.actions![index] = value; - widget.callBack(widget.action, old); - }, - callBackToDelete: () { - final old = widget.action; - widget.action.actions!.remove(e); - widget.callBack(widget.action, old); - }, + ], ), - ) - .toList(), - ),*/ - ], + ), + Column( + children: widget.action.actions! + .map( + (final e) => ActionElementControl( + name: 'Action ${widget.action.actions!.indexOf(e)}', + element: e, + prj: widget.prj, + page: widget.page, + node: widget.node, + callBack: (final value, final old) { + final old = widget.action; + final index = widget.action.actions!.indexOf(e); + widget.action.actions![index] = value; + widget.callBack(widget.action, old); + }, + callBackToDelete: () { + final old = widget.action; + widget.action.actions!.remove(e); + widget.callBack(widget.action, old); + }, + ), + ) + .toList(), + ),*/ + ], + ); + }, ), ); } @@ -297,7 +315,10 @@ class __NewActionAlertState extends State<_NewActionAlert> { void initState() { super.initState(); final prj = BlocProvider.of(context).state!; - final page = BlocProvider.of(context).state; + final page = BlocProvider.of(context).state as PageLoaded; + final config = + (BlocProvider.of(context).state as ConfigStateLoaded) + .config; elements.addAll([ _SelectionClass( title: 'State', @@ -350,61 +371,61 @@ class __NewActionAlertState extends State<_NewActionAlert> { _SelectionClass( title: 'Mixpanel', actionType: ActionType.mixpanel, - options: FActionElement.getMixpanel(prj.config), + options: FActionElement.getMixpanel(config), type: ActionMixpanel.values, ), _SelectionClass( title: 'Supabase Auth', actionType: ActionType.supabaseAuth, - options: FActionElement.getSupabaseAuth(prj.config), + options: FActionElement.getSupabaseAuth(config), type: ActionSupabaseAuth.values, ), _SelectionClass( title: 'Supabase DB', actionType: ActionType.supabaseDatabase, - options: FActionElement.getSupabaseDB(prj.config), + options: FActionElement.getSupabaseDB(config), type: ActionSupabaseDB.values, ), _SelectionClass( title: 'Supabase Functions', actionType: ActionType.supabaseFunctions, - options: FActionElement.getSupabaseFunctions(prj.config), + options: FActionElement.getSupabaseFunctions(config), type: ActionSupabaseFunctions.values, ), _SelectionClass( title: 'Supabase Storage', actionType: ActionType.supabaseStorage, - options: FActionElement.getSupabaseStorage(prj.config), + options: FActionElement.getSupabaseStorage(config), type: ActionSupabaseStorage.values, ), _SelectionClass( title: 'Airtable Database', actionType: ActionType.airtable, - options: FActionElement.getAirtableDB(prj.config), + options: FActionElement.getAirtableDB(config), type: ActionAirtableDB.values, ), _SelectionClass( title: 'RevenueCat', actionType: ActionType.revenueCat, - options: FActionElement.getRevenueCat(prj.config), + options: FActionElement.getRevenueCat(config), type: ActionRevenueCat.values, ), _SelectionClass( title: 'Qonversion', actionType: ActionType.qonversion, - options: FActionElement.getQonversion(prj.config), + options: FActionElement.getQonversion(config), type: ActionQonversion.values, ), _SelectionClass( title: 'Braintree', actionType: ActionType.braintree, - options: FActionElement.getBraintree(prj.config), + options: FActionElement.getBraintree(config), type: ActionBraintree.values, ), _SelectionClass( title: 'WebView', actionType: ActionType.webview, - options: ((page.flatList ?? []).indexWhere( + options: (page.page.flatList.indexWhere( (final element) => element.intrinsicState.type == NType.webview, ) != @@ -416,7 +437,7 @@ class __NewActionAlertState extends State<_NewActionAlert> { _SelectionClass( title: 'Audio Player', actionType: ActionType.audioPlayer, - options: ((page.flatList ?? []).indexWhere( + options: (page.page.flatList.indexWhere( (final element) => element.intrinsicState.type == NType.audioPlayer, ) != @@ -428,12 +449,12 @@ class __NewActionAlertState extends State<_NewActionAlert> { _SelectionClass( title: 'Google Maps', actionType: ActionType.googleMaps, - options: ((page.flatList ?? []).indexWhere( + options: (page.page.flatList.indexWhere( (final element) => element.intrinsicState.type == NType.googleMaps, ) != -1) - ? FActionElement.getGoogleMaps(null) + ? FActionElement.getGoogleMaps(config) : [], type: ActionGoogleMaps.values, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index af657819..72d1c7f8 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -3,8 +3,8 @@ // ignore_for_file: public_member_api_docs, lines_longer_than_80_chars, avoid_dynamic_calls -// Package imports: import 'package:collection/collection.dart'; +// Package imports: import 'package:expandable/expandable.dart'; // Flutter imports: import 'package:flutter/foundation.dart'; @@ -95,7 +95,6 @@ class ActionElementControlState extends State { TextEditingController controller = TextEditingController(); TextEditingController delayController = TextEditingController(); TextEditingController loopController = TextEditingController(); - int? nodeId; String? stateTest; bool isEmit = false; @@ -109,7 +108,8 @@ class ActionElementControlState extends State { @override void initState() { try { - pageObject = widget.prj.pages!.firstWhereOrNull( + final pages = context.read().state; + pageObject = pages.firstWhereOrNull( (final element) => element.name == widget.element.nameOfPage, ); if (pageObject != null) { @@ -120,7 +120,6 @@ class ActionElementControlState extends State { } } catch (_) {} - nodeId = widget.node.nid; controller.text = widget.element.value ?? ''; delayController.text = widget.element.delay?.value ?? '0'; loopController.text = widget.element.everyMilliseconds?.value ?? '0'; @@ -137,8 +136,9 @@ class ActionElementControlState extends State { Logger.printError(e.toString()); } //initialization for openDatePicker for states + final page = context.read().state as PageLoaded; try { - final states = widget.page.states; + final states = page.states; if (states.isNotEmpty) { final currentState = states.firstWhere( (final element) => element.name == widget.element.stateName, @@ -154,7 +154,9 @@ class ActionElementControlState extends State { @override Widget build(final BuildContext context) { - //TODO: + final pageState = context.watch().state as PageLoaded; + final config = + (context.watch().state as ConfigStateLoaded).config; return Container( margin: const EdgeInsets.only(bottom: 8), decoration: BoxDecoration( @@ -206,7 +208,7 @@ class ActionElementControlState extends State { ), CDropdown( value: FActionElement() - .getTypes(widget.prj.config, widget.page) + .getTypes(config, pageState.page) .toSet() .toList() .contains( @@ -219,7 +221,7 @@ class ActionElementControlState extends State { ) : null, items: FActionElement() - .getTypes(widget.prj.config, widget.page) + .getTypes(config, pageState.page) .toSet() .toList(), onChange: (final newValue) { @@ -234,30 +236,6 @@ class ActionElementControlState extends State { } }, ), - // Gesture Dropdown - /*const Padding( - padding: EdgeInsets.only(top: 2, bottom: 4), - child: THeadline3( - 'Gesture', - ), - ), - CDropdown( - value: FActionElement.convertValueToDropdown( - widget.element.actionGesture, - ), - items: FActionElement.getGestures(widget.node as NDynamic), - onChange: (final newValue) { - if (newValue != null) { - final old = widget.element; - widget.element.actionGesture = - FActionElement.convertDropdownToValue( - widget.node.intrinsicState.gestures, - newValue, - ) as ActionGesture?; - widget.callBack(widget.element, old); - } - }, - ),*/ // Delay const Divider( color: Colors.white24, @@ -275,15 +253,8 @@ class ActionElementControlState extends State { child: BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - setState(() { - delayController.text = - widget.element.delay?.value ?? '0'; - }); - } - nodeId = state.first.nid; - } + delayController.text = + widget.element.delay?.value ?? '0'; } }, child: CMiniTextField( @@ -306,7 +277,6 @@ class ActionElementControlState extends State { ), FlagControl( title: 'Is loop', - node: widget.node as NDynamic, keyValue: null, value: widget.element.withLoop ?? false, callBack: (final flag, final old) { @@ -334,16 +304,9 @@ class ActionElementControlState extends State { child: BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - setState(() { - loopController.text = widget - .element.everyMilliseconds?.value ?? - '0'; - }); - } - nodeId = state.first.nid; - } + loopController.text = + widget.element.everyMilliseconds?.value ?? + '0'; } }, child: CMiniTextField( @@ -368,7 +331,6 @@ class ActionElementControlState extends State { ), FlagControl( title: 'By condition', - node: widget.node as NDynamic, keyValue: null, value: widget.element.withCondition ?? false, callBack: (final flag, final old) { @@ -380,9 +342,7 @@ class ActionElementControlState extends State { if (widget.element.withCondition == true) TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.condition ?? FTextTypeInput(), - page: widget.page, title: 'Condition', callBack: (final value, final old) { final old = widget.element; @@ -396,9 +356,7 @@ class ActionElementControlState extends State { '''If "Condition" and "Value" have the same values, the condition is true. Else, it's false.''', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.valueOfCondition ?? FTextTypeInput(), - page: widget.page, title: 'Value', callBack: (final value, final old) { final old = widget.element; @@ -434,7 +392,7 @@ class ActionElementControlState extends State { }, ), CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList() @@ -444,7 +402,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.cameraController, @@ -501,7 +459,7 @@ class ActionElementControlState extends State { }, ), CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == @@ -516,7 +474,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.audioController, @@ -568,7 +526,7 @@ class ActionElementControlState extends State { const TParagraph('Which controller?'), const Gap(Grid.small), CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == @@ -583,7 +541,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.webViewController, @@ -671,7 +629,6 @@ class ActionElementControlState extends State { ActionState.websiteValidator || widget.element.actionState == ActionState.phoneValidator)) AValidatorControl( - page: widget.page, action: widget.element, callback: (final value, final old) { widget.callBack(value, old); @@ -685,7 +642,7 @@ class ActionElementControlState extends State { widget.element.actionTranslator == ActionTranslator.translate)) CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList() @@ -695,7 +652,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList(), @@ -717,7 +674,7 @@ class ActionElementControlState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList() @@ -727,7 +684,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.int || @@ -765,7 +722,7 @@ class ActionElementControlState extends State { ), ), CDropdown( - value: widget.page.params + value: pageState.page.defaultParams .map((final e) => e.name) .where((final element) => element != 'null') .toList() @@ -775,7 +732,7 @@ class ActionElementControlState extends State { -1 ? widget.element.value : null, - items: widget.page.params + items: pageState.page.defaultParams .map((final e) => e.name) .where((final element) => element != 'null') .toList(), @@ -847,7 +804,7 @@ class ActionElementControlState extends State { ), Builder( builder: (final context) { - final states = widget.page.states; + final states = pageState.page.defaultStates; final statesNameList = []; for (final item in states) { statesNameList.add(item.name); @@ -880,9 +837,8 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionBraintree, ), - items: FActionElement.getBraintree(widget.prj.config) - .toSet() - .toList(), + items: + FActionElement.getBraintree(config).toSet().toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -902,10 +858,8 @@ class ActionElementControlState extends State { description: 'e.g. 4.20', control: TextControl( valueType: VariableType.double, - node: widget.node, value: widget.element.valueTextTypeInput ?? FTextTypeInput(), - page: widget.page, title: 'Amount', callBack: (final value, final old) { final old = widget.element; @@ -926,7 +880,7 @@ class ActionElementControlState extends State { ), const Gap(Grid.small), CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList() @@ -936,7 +890,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .map((final e) => e.name) .where((final element) => element != 'null') .toList(), @@ -954,17 +908,11 @@ class ActionElementControlState extends State { ), if (widget.element.actionType == ActionType.revenueCat) RevenueCatBuyActionWidget( - prj: widget.prj, - page: widget.page, - node: widget.node as NDynamic, element: widget.element, callback: widget.callBack, ), if (widget.element.actionType == ActionType.qonversion) QonversionActionWidget( - prj: widget.prj, - page: widget.page, - node: widget.node as NDynamic, element: widget.element, callback: widget.callBack, ), @@ -981,9 +929,8 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionGoogleMaps, ), - items: FActionElement.getGoogleMaps(widget.prj.config) - .toSet() - .toList(), + items: + FActionElement.getGoogleMaps(config).toSet().toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1004,7 +951,7 @@ class ActionElementControlState extends State { descriptionControlWidget( description: 'Google Maps Cubit', control: CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == @@ -1020,7 +967,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.googleMapsCubit, @@ -1045,7 +992,7 @@ class ActionElementControlState extends State { descriptionControlWidget( description: 'Google Maps Controller', control: CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == @@ -1061,7 +1008,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName2 : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == @@ -1090,7 +1037,7 @@ class ActionElementControlState extends State { description: 'Each time a new location is streamed it will be stored here.', control: CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == VariableType.double, @@ -1107,7 +1054,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName3 : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.double, @@ -1133,7 +1080,7 @@ class ActionElementControlState extends State { description: 'Each time a new location is streamed it will be stored here.', control: CDropdown( - value: widget.page.states + value: pageState.page.defaultStates .where( (final element) => element.type == VariableType.double, @@ -1150,7 +1097,7 @@ class ActionElementControlState extends State { -1 ? widget.element.stateName4 : null, - items: widget.page.states + items: pageState.page.defaultStates .where( (final element) => element.type == VariableType.double, @@ -1178,10 +1125,8 @@ class ActionElementControlState extends State { description: 'Camera Latitude', control: TextControl( valueType: VariableType.double, - node: widget.node, value: widget.element.googleMapsLat ?? FTextTypeInput(), - page: widget.page, title: 'Camera Latitude', callBack: (final value, final old) { final old = widget.element; @@ -1201,10 +1146,8 @@ class ActionElementControlState extends State { description: 'Camera Longitude', control: TextControl( valueType: VariableType.double, - node: widget.node, value: widget.element.googleMapsLng ?? FTextTypeInput(), - page: widget.page, title: 'Camera Longitude', callBack: (final value, final old) { final old = widget.element; @@ -1224,10 +1167,8 @@ class ActionElementControlState extends State { description: 'Camera Zoom', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.googleMapsZoom ?? FTextTypeInput(), - page: widget.page, title: 'Camera Zoom', callBack: (final value, final old) { final old = widget.element; @@ -1249,9 +1190,7 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionStripe, ), - items: FActionElement.getStripe(widget.prj.config) - .toSet() - .toList(), + items: FActionElement.getStripe(config).toSet().toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1274,10 +1213,8 @@ class ActionElementControlState extends State { description: 'Billing email', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoEmail ?? FTextTypeInput(), - page: widget.page, title: 'Billing email', callBack: (final value, final old) { final old = widget.element; @@ -1297,10 +1234,8 @@ class ActionElementControlState extends State { description: 'Billing phone', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoPhone ?? FTextTypeInput(), - page: widget.page, title: 'Billing phone', callBack: (final value, final old) { final old = widget.element; @@ -1320,10 +1255,8 @@ class ActionElementControlState extends State { description: 'Billing city', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoCity ?? FTextTypeInput(), - page: widget.page, title: 'Billing city', callBack: (final value, final old) { final old = widget.element; @@ -1343,10 +1276,8 @@ class ActionElementControlState extends State { description: 'Billing state', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoState ?? FTextTypeInput(), - page: widget.page, title: 'Billing state', callBack: (final value, final old) { final old = widget.element; @@ -1366,10 +1297,8 @@ class ActionElementControlState extends State { description: 'Billing line', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoLine ?? FTextTypeInput(), - page: widget.page, title: 'Billing line', callBack: (final value, final old) { final old = widget.element; @@ -1389,11 +1318,9 @@ class ActionElementControlState extends State { description: 'Billing Postal Code', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoPostalCode ?? FTextTypeInput(), - page: widget.page, title: 'Billing postal code', callBack: (final value, final old) { final old = widget.element; @@ -1414,10 +1341,8 @@ class ActionElementControlState extends State { description: 'Billing country', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeBillingInfoCountry ?? FTextTypeInput(), - page: widget.page, title: 'Billing country', callBack: (final value, final old) { final old = widget.element; @@ -1437,10 +1362,8 @@ class ActionElementControlState extends State { description: 'Shipping id', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripeShippingId ?? FTextTypeInput(), - page: widget.page, title: 'Shipping id', callBack: (final value, final old) { final old = widget.element; @@ -1463,10 +1386,8 @@ class ActionElementControlState extends State { description: 'Payment Intent Id', control: TextControl( valueType: VariableType.string, - node: widget.node, value: widget.element.stripePaymentIntentId ?? FTextTypeInput(), - page: widget.page, title: 'Payment Intent Id', callBack: (final value, final old) { final old = widget.element; @@ -1504,7 +1425,7 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionAirtableDB, ), - items: FActionElement.getAirtableDB(widget.prj.config), + items: FActionElement.getAirtableDB(config), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1522,7 +1443,7 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionSupabaseAuth, ), - items: FActionElement.getSupabaseAuth(widget.prj.config), + items: FActionElement.getSupabaseAuth(config), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1540,9 +1461,7 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionSupabaseDB, ), - items: FActionElement.getSupabaseDB(widget.prj.config) - .toSet() - .toList(), + items: FActionElement.getSupabaseDB(config).toSet().toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1562,10 +1481,9 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionSupabaseFunctions, ), - items: - FActionElement.getSupabaseFunctions(widget.prj.config) - .toSet() - .toList(), + items: FActionElement.getSupabaseFunctions(config) + .toSet() + .toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1579,9 +1497,6 @@ class ActionElementControlState extends State { }, ), SupabaseInvokeControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -1597,10 +1512,9 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionSupabaseStorage, ), - items: - FActionElement.getSupabaseStorage(widget.prj.config) - .toSet() - .toList(), + items: FActionElement.getSupabaseStorage(config) + .toSet() + .toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1616,9 +1530,6 @@ class ActionElementControlState extends State { if (widget.element.actionSupabaseStorage == ActionSupabaseStorage.upload) SupabaseStorageUploadControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -1627,9 +1538,6 @@ class ActionElementControlState extends State { ) else SupabaseStorageRemoveControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -1645,9 +1553,8 @@ class ActionElementControlState extends State { value: FActionElement.convertValueToDropdown( widget.element.actionMixpanel, ), - items: FActionElement.getMixpanel(widget.prj.config) - .toSet() - .toList(), + items: + FActionElement.getMixpanel(config).toSet().toList(), onChange: (final newValue) { if (newValue != null) { final old = widget.element; @@ -1662,9 +1569,6 @@ class ActionElementControlState extends State { ), if (widget.element.actionMixpanel == ActionMixpanel.track) MixPanelTrack( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -1673,9 +1577,6 @@ class ActionElementControlState extends State { ) else MixPanelSetUserId( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -1720,45 +1621,51 @@ class ActionElementControlState extends State { } }, ), - if ((widget.element.actionType == ActionType.state && - widget.element.actionState == ActionState.changeWith && - !widget.node.intrinsicState.gestures - .contains(ActionGesture.onChange) && - (widget.node.intrinsicState.type != NType.calendar && - widget.node.intrinsicState.type != - NType.cupertinoSegmentedControl && - widget.node.intrinsicState.type != - NType.cupertinoSwitch)) || - (widget.element.actionType == ActionType.navigation && - widget.element.actionNavigation == - ActionNavigation.launchURL) || - (widget.element.actionType == ActionType.navigation && - widget.element.actionNavigation == - ActionNavigation.share) || - (widget.element.actionType == ActionType.webview && - widget.element.actionWebView == ActionWebView.navigateTo)) - Padding( - padding: const EdgeInsets.only(top: 8), - child: SizedBox( - width: double.maxFinite, - child: descriptionControlWidget( - description: '''''', - control: TextControl( - valueType: VariableType.string, - node: widget.node, - value: widget.element.valueTextTypeInput ?? - FTextTypeInput(), - page: widget.page, - title: 'Value', - callBack: (final value, final old) { - final old = widget.element; - widget.element.valueTextTypeInput = value; - widget.callBack(widget.element, old); - }, + BlocBuilder>( + builder: (final context, final state) { + if ((widget.element.actionType == ActionType.state && + widget.element.actionState == + ActionState.changeWith && + !state.first.intrinsicState.gestures + .contains(ActionGesture.onChange) && + (state.first.intrinsicState.type != NType.calendar && + state.first.intrinsicState.type != + NType.cupertinoSegmentedControl && + state.first.intrinsicState.type != + NType.cupertinoSwitch)) || + (widget.element.actionType == ActionType.navigation && + widget.element.actionNavigation == + ActionNavigation.launchURL) || + (widget.element.actionType == ActionType.navigation && + widget.element.actionNavigation == + ActionNavigation.share) || + (widget.element.actionType == ActionType.webview && + widget.element.actionWebView == + ActionWebView.navigateTo)) { + return Padding( + padding: const EdgeInsets.only(top: 8), + child: SizedBox( + width: double.maxFinite, + child: descriptionControlWidget( + description: '''''', + control: TextControl( + valueType: VariableType.string, + value: widget.element.valueTextTypeInput ?? + FTextTypeInput(), + title: 'Value', + callBack: (final value, final old) { + final old = widget.element; + widget.element.valueTextTypeInput = value; + widget.callBack(widget.element, old); + }, + ), + ), ), - ), - ), - ), + ); + } + return const SizedBox(); + }, + ), if ((widget.element.actionType == ActionType.navigation && (widget.element.actionNavigation == @@ -1786,8 +1693,25 @@ class ActionElementControlState extends State { ], ), ), - CDropdown( - value: widget.prj.pages! + BlocBuilder>( + builder: (final context, final state) { + return CDropdown( + value: state + .where((final element) { + if (widget.element.actionNavigation == + ActionNavigation.openBottomSheet || + widget.element.actionNavigation == + ActionNavigation.openSnackBar) { + return !element.isPage; + } else { + return element.isPage; + } + }) + .toList() + .contains(pageObject) + ? dropdownLinkPage + : null, + items: state .where((final element) { if (widget.element.actionNavigation == ActionNavigation.openBottomSheet || @@ -1798,43 +1722,30 @@ class ActionElementControlState extends State { return element.isPage; } }) - .toList() - .contains(pageObject) - ? dropdownLinkPage - : null, - items: widget.prj.pages! - .where((final element) { - if (widget.element.actionNavigation == - ActionNavigation.openBottomSheet || - widget.element.actionNavigation == - ActionNavigation.openSnackBar) { - return !element.isPage; - } else { - return element.isPage; + .map((final e) => e.name) + .toSet() + .toList(), + onChange: (final newValue) { + if (newValue != null) { + final old = widget.element; + pageObject = state.firstWhere( + (final element) => element.name == newValue, + ); + widget.element.nameOfPage = newValue; + if (mounted) { + setState(() { + dropdownLinkPage = newValue; + }); + } + widget.callBack(widget.element, old); } - }) - .map((final e) => e.name) - .toSet() - .toList(), - onChange: (final newValue) { - if (newValue != null) { - final old = widget.element; - pageObject = widget.prj.pages!.firstWhere( - (final element) => element.name == newValue, - ); - widget.element.nameOfPage = newValue; - if (mounted) { - setState(() { - dropdownLinkPage = newValue; - }); - } - widget.callBack(widget.element, old); - } + }, + ); }, ), if (pageObject != null && - pageObject?.params != []) - pageObject?.params.isNotEmpty ?? false + pageObject?.defaultParams != []) + pageObject?.defaultParams.isNotEmpty ?? false ? Padding( padding: const EdgeInsets.only(top: 16), child: Stack( @@ -1856,11 +1767,11 @@ class ActionElementControlState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: pageObject!.params + children: pageObject!.defaultParams .map( (final e) => _Element( + pageState: pageState, variable: e, - page: widget.page, map: map, element: widget.element, callBack: widget.callBack, @@ -1911,22 +1822,22 @@ class ActionElementControlState extends State { ActionSupabaseAuth.signUp || widget.element.actionSupabaseAuth == ActionSupabaseAuth.signInWithCredential) && - (widget.page.states.indexWhere( + (pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'email', ) == -1 || - widget.page.states.indexWhere( + pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'password', ) == -1 || - widget.page.states.indexWhere( + pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'status', ) == -1 || - widget.page.states.indexWhere( + pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'status', ) == @@ -1961,13 +1872,13 @@ class ActionElementControlState extends State { TextButton( onPressed: () { var flag = false; - if (widget.page.states.indexWhere( + if (pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'email', ) == -1) { - widget.page.states.add( + pageState.page.defaultStates.add( VariableObject( id: const Uuid().v1(), type: VariableType.string, @@ -1977,13 +1888,13 @@ class ActionElementControlState extends State { ); flag = true; } - if (widget.page.states.indexWhere( + if (pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'password', ) == -1) { - widget.page.states.add( + pageState.page.defaultStates.add( VariableObject( id: const Uuid().v1(), type: VariableType.string, @@ -1993,13 +1904,13 @@ class ActionElementControlState extends State { ); flag = true; } - if (widget.page.states.indexWhere( + if (pageState.page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == 'status', ) == -1) { - widget.page.states.add( + pageState.page.defaultStates.add( VariableObject( id: const Uuid().v1(), type: VariableType.string, @@ -2012,12 +1923,10 @@ class ActionElementControlState extends State { if (flag) { sl.get().changeNode( - node: - widget.page.scaffold! as NDynamic, + node: pageState.page.scaffold + as NDynamic, ); } - BlocProvider.of(context) - .add(OnFocus(node: widget.node)); }, child: Container( padding: const EdgeInsets.all(8), @@ -2040,9 +1949,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.supabaseDatabase && widget.element.actionSupabaseDB == ActionSupabaseDB.insert) SupabaseInsertControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2052,9 +1958,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.tetaDatabase && widget.element.actionTetaDB == ActionTetaCmsDB.insert) TetaCmsInsertControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2064,9 +1967,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.airtable && widget.element.actionAirtableDB == ActionAirtableDB.insert) AirtableInsertControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2076,9 +1976,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.airtable && widget.element.actionAirtableDB == ActionAirtableDB.delete) AirtableDeleteControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2088,9 +1985,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.airtable && widget.element.actionAirtableDB == ActionAirtableDB.update) AirtableUpdateControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2100,9 +1994,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.supabaseDatabase && widget.element.actionSupabaseDB == ActionSupabaseDB.update) SupabaseUpdateControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2112,9 +2003,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.tetaDatabase && widget.element.actionTetaDB == ActionTetaCmsDB.update) TetaCmsUpdateControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2124,9 +2012,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.supabaseDatabase && widget.element.actionSupabaseDB == ActionSupabaseDB.delete) SupabaseDeleteControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2136,9 +2021,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.tetaDatabase && widget.element.actionTetaDB == ActionTetaCmsDB.delete) TetaCmsDeleteControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2149,9 +2031,6 @@ class ActionElementControlState extends State { widget.element.actionCustomHttpRequest == ActionCustomHttpRequest.post) CustomHttpRequestPostControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2162,9 +2041,6 @@ class ActionElementControlState extends State { widget.element.actionCustomHttpRequest == ActionCustomHttpRequest.update) CustomHttpRequestUpdateControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2175,9 +2051,6 @@ class ActionElementControlState extends State { widget.element.actionCustomHttpRequest == ActionCustomHttpRequest.delete) CustomHttpRequestDeleteControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2187,9 +2060,6 @@ class ActionElementControlState extends State { if (widget.element.actionType == ActionType.apiCalls && widget.element.actionApiCalls == ActionApiCalls.apiCalls) ApiCallsControl( - prj: widget.prj, - page: widget.page, - node: widget.node, action: widget.element, callback: () { final old = widget.element; @@ -2207,7 +2077,7 @@ class ActionElementControlState extends State { class _Element extends StatefulWidget { const _Element({ required this.variable, - required this.page, + required this.pageState, required this.map, required this.element, required this.callBack, @@ -2215,7 +2085,7 @@ class _Element extends StatefulWidget { }) : super(key: key); final VariableObject variable; - final PageObject page; + final PageLoaded pageState; final Map map; final FActionElement element; final Function(FActionElement, FActionElement) callBack; @@ -2233,15 +2103,13 @@ class __ElementState extends State<_Element> { @override void initState() { super.initState(); - Logger.printMessage('${widget.page.datasets}'); - Logger.printMessage('Params: ${widget.page.params}'); final params = Map.fromEntries( - widget.page.params + widget.pageState.page.defaultParams .where((final element) => widget.variable.type == element.type) .map((final e) => MapEntry(e.name, e.get)), ); final states = Map.fromEntries( - widget.page.states + widget.pageState.page.defaultStates .where((final element) => widget.variable.type == element.type) .map((final e) => MapEntry(e.name, e.get)), ); @@ -2258,7 +2126,8 @@ class __ElementState extends State<_Element> { states, ], ), - if (widget.variable.type == VariableType.string) ...widget.page.datasets + if (widget.variable.type == VariableType.string) + ...widget.pageState.datasets ]; try { dropdown = widget.map[widget.variable.id]?['label'] as String; @@ -2274,7 +2143,6 @@ class __ElementState extends State<_Element> { @override Widget build(final BuildContext context) { - Logger.printMessage('Params: ${widget.page.params}'); if (dropdownDataset != null) { try { listSecondDropwdown.addAll( diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_value.dart b/teta_widgets/lib/src/elements/controls/atoms/action_value.dart index 57232ce7..43b930bb 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_value.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_value.dart @@ -3,11 +3,11 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class ActionvalueControl extends StatefulWidget { const ActionvalueControl({ @@ -111,167 +111,182 @@ class PaddingsState extends State { widget.callBack(widget.actionValue, old); }, ), - if (widget.actionValue.type == FTextTypeEnum.param) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.page.states - .map((final e) => e.name) - .contains(widget.actionValue.paramName) - ? widget.actionValue.stateName - : null, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) {}, - isDense: true, - isExpanded: true, - items: widget.page.params - .map((final e) => e.name) - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + children: [ + if (widget.actionValue.type == FTextTypeEnum.param) + Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.actionValue.paramName) + ? widget.actionValue.stateName + : null, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) {}, + isDense: true, + isExpanded: true, + items: state.page.defaultParams + .map((final e) => e.name) + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), ), - ); - }).toList(), - ), - ), - if (widget.actionValue.type == FTextTypeEnum.state) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.page.states - .map((final e) => e.name) - .contains(widget.actionValue.stateName) - ? widget.actionValue.stateName - : null, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) {}, - isDense: true, - isExpanded: true, - items: widget.page.states - .map((final e) => e.name) - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, + if (widget.actionValue.type == FTextTypeEnum.state) + Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.actionValue.stateName) + ? widget.actionValue.stateName + : null, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) {}, + isDense: true, + isExpanded: true, + items: state.page.defaultStates + .map((final e) => e.name) + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), ), - ); - }).toList(), - ), - ), - //todo: questo è il codice che mi serve nel button - if (widget.actionValue.type == FTextTypeEnum.dataset) - Container( - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .contains(widget.actionValue.datasetName) - ? widget.actionValue.datasetName - : null, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - if (newValue != null) { - if (mounted) { - setState(() { - databaseName = newValue; - }); - } - final old = widget.actionValue; - widget.actionValue.datasetName = newValue; - widget.callBack(widget.actionValue, old); - } - }, - isDense: true, - isExpanded: true, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, + //todo: questo è il codice che mi serve nel button + if (widget.actionValue.type == FTextTypeEnum.dataset) + Container( + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .contains(widget.actionValue.datasetName) + ? widget.actionValue.datasetName + : null, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + if (newValue != null) { + if (mounted) { + setState(() { + databaseName = newValue; + }); + } + final old = widget.actionValue; + widget.actionValue.datasetName = newValue; + widget.callBack(widget.actionValue, old); + } + }, + isDense: true, + isExpanded: true, + items: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), ), - ); - }).toList(), - ), - ), - if (widget.actionValue.type == FTextTypeEnum.dataset && - widget.actionValue.datasetName != null) - Container( - margin: const EdgeInsets.only(top: 8), - width: double.maxFinite, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), - child: DropdownButton( - value: widget.page.datasets - .firstWhere( - (final element) => - element.getName == widget.actionValue.datasetName, - ) - .getMap - .first - .keys - .contains(widget.actionValue.datasetAttr) - ? widget.actionValue.datasetAttr - : null, - icon: const Icon(Icons.arrow_drop_down), - underline: const SizedBox(), - onChanged: (final String? newValue) { - if (newValue != null) { - setState(() { - databaseAttribute = newValue; - }); - final old = widget.actionValue; - widget.actionValue.datasetAttr = newValue; - widget.callBack(widget.actionValue, old); - } - }, - isDense: true, - isExpanded: true, - items: widget.page.datasets - .firstWhere( - (final element) => - element.getName == widget.actionValue.datasetName, - ) - .getMap - .first - .keys - .map>((final String value) { - return DropdownMenuItem( - value: value, - child: TParagraph( - value, + if (widget.actionValue.type == FTextTypeEnum.dataset && + widget.actionValue.datasetName != null) + Container( + margin: const EdgeInsets.only(top: 8), + width: double.maxFinite, + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 8), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + ), + child: DropdownButton( + value: state.datasets + .firstWhere( + (final element) => + element.getName == + widget.actionValue.datasetName, + ) + .getMap + .first + .keys + .contains(widget.actionValue.datasetAttr) + ? widget.actionValue.datasetAttr + : null, + icon: const Icon(Icons.arrow_drop_down), + underline: const SizedBox(), + onChanged: (final String? newValue) { + if (newValue != null) { + setState(() { + databaseAttribute = newValue; + }); + final old = widget.actionValue; + widget.actionValue.datasetAttr = newValue; + widget.callBack(widget.actionValue, old); + } + }, + isDense: true, + isExpanded: true, + items: state.datasets + .firstWhere( + (final element) => + element.getName == + widget.actionValue.datasetName, + ) + .getMap + .first + .keys + .map>((final String value) { + return DropdownMenuItem( + value: value, + child: TParagraph( + value, + ), + ); + }).toList(), + ), ), - ); - }).toList(), - ), - ), + ], + ); + }, + ), ], ); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart index a263ed3e..a0da42ef 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart @@ -23,13 +23,10 @@ class AudioControllerControl extends StatefulWidget { final Function(FTextTypeInput, FTextTypeInput) callBack; @override - AudioControllerControlState create tate() => AudioControllerControlState(); + AudioControllerControlState createState() => AudioControllerControlState(); } class AudioControllerControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -37,10 +34,8 @@ class AudioControllerControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -54,12 +49,7 @@ class AudioControllerControlState extends State { buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -91,43 +81,53 @@ class AudioControllerControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.audioController, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.audioController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.audioController, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.audioController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart index e0c407eb..96b9c49f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart @@ -27,9 +27,6 @@ class CameraControllerControl extends StatefulWidget { } class CameraControllerControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -37,10 +34,8 @@ class CameraControllerControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -53,12 +48,7 @@ class CameraControllerControlState extends State { return BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -90,43 +80,53 @@ class CameraControllerControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.cameraController, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.cameraController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.cameraController, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.cameraController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart index 8802ce9e..20b916f2 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart @@ -8,7 +8,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_cms/teta_cms.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; // Project imports: import 'package:teta_widgets/src/elements/index.dart'; @@ -38,94 +37,81 @@ class CMSCollectionControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } - }, - child: BlocBuilder>( - builder: (final context, final state) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only( - bottom: 8, - ), - child: Row( - children: const [ - TParagraph( - 'Collection', - ), - ], - ), + return BlocBuilder>( + builder: (final context, final state) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only( + bottom: 8, + ), + child: Row( + children: const [ + TParagraph( + 'Collection', + ), + ], ), - FutureBuilder>( - future: _future, - builder: (final context, final snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator(), - ); - } - dropdown = snapshot.data! - .firstWhereOrNull( - (final element) => - element.id == - (widget.collectionId ?? - (widget.node.body - .attributes[DBKeys.cmsCollection] - as FTextTypeInput?) - ?.value), - ) - ?.name; - final list = snapshot.data! - .where( - (final element) => - element.schema == CollectionSchema.public, - ) - .toList(); - return CDropdown( - value: dropdown, - items: list.map((final e) => e.name).toList(), - onChange: (final newValue) { - if (newValue != null) { - setState(() { - dropdown = newValue; - }); + ), + FutureBuilder>( + future: _future, + builder: (final context, final snapshot) { + if (!snapshot.hasData) { + return const Center( + child: CircularProgressIndicator(), + ); + } + dropdown = snapshot.data! + .firstWhereOrNull( + (final element) => + element.id == + (widget.collectionId ?? + (state.first.body.attributes[DBKeys.cmsCollection] + as FTextTypeInput?) + ?.value), + ) + ?.name; + final list = snapshot.data! + .where( + (final element) => + element.schema == CollectionSchema.public, + ) + .toList(); + return CDropdown( + value: dropdown, + items: list.map((final e) => e.name).toList(), + onChange: (final newValue) { + if (newValue != null) { + setState(() { + dropdown = newValue; + }); - final old = widget.collectionId; - final nw = list - .firstWhereOrNull( - (final element) => element.name == dropdown, - ) - ?.id; - if (widget.node.body.attributes[DBKeys.cmsCollection] != - null && - widget.node.body.attributes[DBKeys.cmsCollection] - is FTextTypeInput) { - (widget.node.body.attributes[DBKeys.cmsCollection] - as FTextTypeInput) - .value = nw; - } - if (nw != null) { - widget.callBack(nw, old); - } + final old = widget.collectionId; + final nw = list + .firstWhereOrNull( + (final element) => element.name == dropdown, + ) + ?.id; + if (state.first.body.attributes[DBKeys.cmsCollection] != + null && + state.first.body.attributes[DBKeys.cmsCollection] + is FTextTypeInput) { + (state.first.body.attributes[DBKeys.cmsCollection] + as FTextTypeInput) + .value = nw; } - }, - ); - }, - ), - ], - ); - }, - ), + if (nw != null) { + widget.callBack(nw, old); + } + } + }, + ); + }, + ), + ], + ); + }, ); } } diff --git a/teta_widgets/lib/src/elements/controls/atoms/dataset.dart b/teta_widgets/lib/src/elements/controls/atoms/dataset.dart index 858f158f..2e959357 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/dataset.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/dataset.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/dataset.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class DatasetControl extends StatefulWidget { const DatasetControl({ @@ -29,15 +28,12 @@ class DatasetControl extends StatefulWidget { } class DatasetControlState extends State { - int? nodeId; - bool? isUpdated; String databaseName = ''; String? databaseAttribute; @override void initState() { try { - nodeId = widget.node.nid; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttrName; } catch (_) {} @@ -46,69 +42,92 @@ class DatasetControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( - listener: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - setState(() { - isUpdated = true; - }); - nodeId = state.first.nid; - } - } - }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TParagraph( - widget.title, - ), - ], - ), - CDropdown( - value: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .contains(widget.value.datasetName) - ? widget.value.datasetName - : null, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - setState(() { - databaseName = newValue!; - }); - final old = widget.value; - widget.value.datasetName = newValue; - widget.callBack(widget.value, old); - }, - ), - _buildAttrSelection(context), - ], - ), + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TParagraph( + widget.title, + ), + ], + ), + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .contains(widget.value.datasetName) + ? widget.value.datasetName + : null, + items: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .toList(), + onChange: (final newValue) { + setState(() { + databaseName = newValue!; + }); + final old = widget.value; + widget.value.datasetName = newValue; + widget.callBack(widget.value, old); + }, + ); + }, + ), + _buildAttrSelection( + value: widget.value, + isAttrRequired: widget.isAttrRequired ?? false, + datasetName: databaseName, + callBack: widget.callBack, + ), + ], ); } +} + +class _buildAttrSelection extends StatefulWidget { + const _buildAttrSelection({ + final Key? key, + required this.value, + required this.isAttrRequired, + required this.datasetName, + required this.callBack, + }) : super(key: key); + + final FDataset value; + final bool isAttrRequired; + final String datasetName; + final Function(FDataset, FDataset) callBack; + + @override + __buildAttrSelectionState createState() => __buildAttrSelectionState(); +} - Widget _buildAttrSelection(final BuildContext context) { - var isAttrRequired = widget.isAttrRequired; +class __buildAttrSelectionState extends State<_buildAttrSelection> { + bool isAttrRequired = false; + String databaseAttribute = ''; - if (databaseName != '') { + @override + void initState() { + super.initState(); + isAttrRequired = widget.isAttrRequired; + if (widget.datasetName != '') { bool hasSubList; - widget.page.datasets + final datasets = (context.read().state as PageLoaded).datasets; + datasets .where( - (final element) => element.getName == databaseName, + (final element) => element.getName == widget.datasetName, ) .first .getMap .isNotEmpty - ? hasSubList = widget.page.datasets + ? hasSubList = datasets .where( - (final element) => element.getName == databaseName, + (final element) => element.getName == widget.datasetName, ) .first .hasSubList() @@ -117,63 +136,69 @@ class DatasetControlState extends State { isAttrRequired = true; } } + } - try { - if ((isAttrRequired ?? false) && databaseName != '') { - return CDropdown( - value: (widget.page.datasets - .where( - (final element) => element.getName == databaseName, - ) - .first - .getMap - .isNotEmpty - ? widget.page.datasets - .where( - (final element) => element.getName == databaseName, - ) - .first - .getMap - .first - : {}) - .keys - .toSet() - .contains(widget.value.datasetAttrName) - ? widget.value.datasetAttrName - : null, - items: ((widget.page.datasets - .where( - (final element) => element.getName == databaseName, - ) - .first - .getMap - .isNotEmpty) - ? widget.page.datasets - .where( - (final element) => element.getName == databaseName, - ) - .first - .getMap - .first - : {}) - .keys - .toSet() - .toList(), - onChange: (final newValue) { - setState(() { - databaseAttribute = newValue; - }); - final old = widget.value; - widget.value.datasetAttrName = newValue; - widget.callBack(widget.value, old); - }, - ); - } else { - return Container(); - } - } catch (e, st) { - print('DatasetAttrSelectError: $e'); - print('DatasetAttrSelectError: $st'); + @override + Widget build(final BuildContext context) { + if (isAttrRequired && widget.datasetName != '') { + return BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: (state.datasets + .where( + (final element) => + element.getName == widget.datasetName, + ) + .first + .getMap + .isNotEmpty + ? state.datasets + .where( + (final element) => + element.getName == widget.datasetName, + ) + .first + .getMap + .first + : {}) + .keys + .toSet() + .contains(widget.value.datasetAttrName) + ? widget.value.datasetAttrName + : null, + items: ((state.datasets + .where( + (final element) => + element.getName == widget.datasetName, + ) + .first + .getMap + .isNotEmpty) + ? state.datasets + .where( + (final element) => + element.getName == widget.datasetName, + ) + .first + .getMap + .first + : {}) + .keys + .toSet() + .toList(), + onChange: (final newValue) { + setState(() { + databaseAttribute = newValue!; + }); + final old = widget.value; + widget.value.datasetAttrName = newValue; + widget.callBack(widget.value, old); + }, + ); + }, + ); + } else { return Container(); } } diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart index 5fa05059..ce209b78 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart @@ -27,9 +27,6 @@ class GoogleMapsControl extends StatefulWidget { } class GoogleMapsControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -37,10 +34,8 @@ class GoogleMapsControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -54,12 +49,7 @@ class GoogleMapsControlState extends State { buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -91,43 +81,53 @@ class GoogleMapsControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.googleMapsController, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.googleMapsController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.googleMapsController, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.googleMapsController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart index b9f4b2a8..3304a728 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart @@ -37,7 +37,6 @@ class MapControllerControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { text = widget.value.value ?? ''; controller.text = text!; @@ -91,43 +90,53 @@ class MapControllerControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.mapController, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.mapController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.mapController, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.mapController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/atoms/name.dart b/teta_widgets/lib/src/elements/controls/atoms/name.dart index f8c56b67..2f6acbfd 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/name.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/name.dart @@ -32,9 +32,13 @@ class NameState extends State { @override void initState() { - controller.text = widget.title == 'Description' - ? widget.node.description ?? '' - : widget.node.name ?? widget.node.intrinsicState.displayName; + final nodes = context.read().state; + if (nodes.length == 1) { + final node = nodes.first; + controller.text = widget.title == 'Description' + ? nodes.first.description ?? '' + : nodes.first.name ?? nodes.first.intrinsicState.displayName; + } super.initState(); } @@ -59,16 +63,19 @@ class NameState extends State { }); }, onSubmitted: (final text) { - widget.title == 'Description' - ? widget.node.description = text - : widget.node.name = text; - widget.callBack( - text, + final nodes = context.read().state; + if (nodes.length == 1) { + final node = nodes.first; widget.title == 'Description' - ? widget.node.description ?? '' - : widget.node.name ?? - widget.node.intrinsicState.displayName, - ); + ? node.description = text + : node.name = text; + widget.callBack( + text, + widget.title == 'Description' + ? node.description ?? '' + : node.name ?? node.intrinsicState.displayName, + ); + } setState(() { isLoading = false; }); @@ -80,16 +87,19 @@ class NameState extends State { child: CButton( label: 'Submit', callback: () { - widget.title == 'Description' - ? widget.node.description = controller.text - : widget.node.name = controller.text; - widget.callBack( - controller.text, + final nodes = context.read().state; + if (nodes.length == 1) { + final node = nodes.first; widget.title == 'Description' - ? widget.node.description ?? '' - : widget.node.name ?? - widget.node.intrinsicState.displayName, - ); + ? node.description = controller.text + : node.name = controller.text; + widget.callBack( + controller.text, + widget.title == 'Description' + ? node.description ?? '' + : node.name ?? node.intrinsicState.displayName, + ); + } setState(() { isLoading = false; diff --git a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart index 2c2eba90..677b27dc 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart @@ -31,21 +31,26 @@ class ComponentControl extends StatefulWidget { class ComponentControlState extends State { String? dropdown; PageObject? pageObject; + List components = []; Map map = {}; @override void initState() { super.initState(); - final components = - widget.prj.pages!.where((final element) => !element.isPage).toList(); + final pages = context.read().state; + final focusBloc = context.read().state; + final name = + focusBloc.first.body.attributes[DBKeys.componentName] as String? ?? ''; + components = pages.where((final element) => !element.isPage).toList(); try { if (components.indexWhere((final element) => element.name == name) != -1) { pageObject = components.firstWhere((final element) => element.name == name); dropdown = pageObject?.name; - if (widget.node.body.attributes[DBKeys.paramsToSend] != null) { - map = widget.node.body.attributes[DBKeys.paramsToSend] + + if (focusBloc.first.body.attributes[DBKeys.paramsToSend] != null) { + map = focusBloc.first.body.attributes[DBKeys.paramsToSend] as Map? ?? {}; } @@ -78,22 +83,24 @@ class ComponentControlState extends State { value: dropdown, items: components.map((final e) => e.name).toList(), onChange: (final String? newValue) { + final focusBloc = context.read().state; + if (newValue != null) { - final old = widget.node.body.attributes[DBKeys.componentName] - as String?; + final old = focusBloc + .first.body.attributes[DBKeys.componentName] as String?; pageObject = components .firstWhere((final element) => element.name == newValue); - widget.node.body.attributes[DBKeys.componentName] = + focusBloc.first.body.attributes[DBKeys.componentName] = pageObject!.name; setState(() { dropdown = newValue; - name = '${pageObject!.id}'; }); widget.callBack(pageObject!.name, old ?? ''); } }, ), - if (pageObject != null && pageObject?.params != []) + if (pageObject != null && + pageObject?.defaultParams != []) Padding( padding: const EdgeInsets.only(top: 16), child: Stack( @@ -109,22 +116,29 @@ class ComponentControlState extends State { ), borderRadius: BorderRadius.circular(8), ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: pageObject!.params - .map( - (final variable) => Element( - variable: variable, - page: widget.page, - map: map, - callBackParameters: (final map) { - widget.node.body - .attributes[DBKeys.paramsToSend] = map; - widget.callBackParameters(map); - }, - ), - ) - .toList(), + child: BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: pageObject!.defaultParams + .map( + (final variable) => Element( + variable: variable, + page: state.page, + map: map, + callBackParameters: (final map) { + final node = + context.read().state; + node.first.body + .attributes[DBKeys.paramsToSend] = map; + widget.callBackParameters(map); + }, + ), + ) + .toList(), + ); + }, ), ), Container( @@ -188,13 +202,14 @@ class ElementState extends State { @override void initState() { super.initState(); + final state = context.read().state as PageLoaded; final params = Map.fromEntries( - widget.page.params + state.page.defaultParams .where((final element) => widget.variable.type == element.type) .map((final e) => MapEntry(e.name, e.get)), ); final states = Map.fromEntries( - widget.page.states + state.page.defaultStates .where((final element) => widget.variable.type == element.type) .map((final e) => MapEntry(e.name, e.get)), ); @@ -211,7 +226,7 @@ class ElementState extends State { states, ], ), - if (widget.variable.type == VariableType.string) ...widget.page.datasets + if (widget.variable.type == VariableType.string) ...state.datasets ]; try { dropdown = widget.map[widget.variable.id]['label'] as String; @@ -261,9 +276,8 @@ class ElementState extends State { onChange: (final String? newValue) { setState(() { dropdownDataset = newValue; - listSecondDropwdown = []; - listSecondDropwdown.addAll( - listDataset + listSecondDropwdown = [ + ...listDataset .where( (final element) => element.getName == dropdownDataset, @@ -271,7 +285,7 @@ class ElementState extends State { .map( (final e) => e.getMap.first, ), - ); + ]; }); }, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/page_params.dart b/teta_widgets/lib/src/elements/controls/atoms/page_params.dart index 7ce11bee..8263c033 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/page_params.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/page_params.dart @@ -6,13 +6,13 @@ import 'package:enum_to_string/enum_to_string.dart'; // Flutter imports: import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:hovering/hovering.dart'; import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/src/design_system/textfield/multi_line_textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/node.dart'; import 'package:uuid/uuid.dart'; class PageParamsControl extends StatefulWidget { @@ -47,22 +47,24 @@ class PaddingsState extends State { const pagePrefix = 'Param'; var pageName = ''; var index = 0; + final pageState = + BlocProvider.of(context).state as PageLoaded; do { index++; pageName = '$pagePrefix $index'; - } while (widget.page.params.indexWhere( + } while (pageState.params.indexWhere( (final element) => element.name == pageName, ) != -1); - widget.page.params.add( + widget.callBack([ + ...pageState.page.defaultParams, VariableObject( id: const Uuid().v1(), type: VariableType.string, name: pageName, defaultValue: '0', ), - ); - widget.callBack(widget.page.params); + ]); }, child: HoverWidget( hoverChild: Padding( @@ -100,51 +102,57 @@ class PaddingsState extends State { ), ], ), - Column( - children: widget.page.params - .map( - (final variable) => Row( - children: [ - Expanded( - child: HoverWidget( - hoverChild: item(variable, onHover: true), - onHover: (final e) {}, - child: item(variable, onHover: false), - ), - ), - Padding( - padding: const EdgeInsets.only( - left: 8, - top: 6, - right: 6, - ), - child: GestureDetector( - onTap: () { - widget.page.params.remove(variable); - widget.callBack(widget.page.params); - }, - child: Tooltip( - message: 'Delete. This action cannot be undone', + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + children: state.page.defaultParams + .map( + (final variable) => Row( + children: [ + Expanded( child: HoverWidget( - hoverChild: const Icon( - FeatherIcons.x, - color: Colors.red, - size: 20, - ), + hoverChild: item(variable, onHover: true), onHover: (final e) {}, - child: const Icon( - FeatherIcons.x, - color: Colors.white, - size: 20, + child: item(variable, onHover: false), + ), + ), + Padding( + padding: const EdgeInsets.only( + left: 8, + top: 6, + right: 6, + ), + child: GestureDetector( + onTap: () { + widget.callBack( + [...state.page.defaultParams]..remove(variable), + ); + }, + child: Tooltip( + message: 'Delete. This action cannot be undone', + child: HoverWidget( + hoverChild: const Icon( + FeatherIcons.x, + color: Colors.red, + size: 20, + ), + onHover: (final e) {}, + child: const Icon( + FeatherIcons.x, + color: Colors.white, + size: 20, + ), + ), ), ), ), - ), + ], ), - ], - ), - ) - .toList(), + ) + .toList(), + ); + }, ), ], ); @@ -156,7 +164,8 @@ class PaddingsState extends State { }) { return GestureDetector( onTap: () { - showAlert(context, widget.page, variable); + final page = (context.read().state as PageLoaded).page; + showAlert(context, page, variable); }, child: Container( margin: const EdgeInsets.only(top: 8), @@ -231,9 +240,9 @@ class PaddingsState extends State { ), GestureDetector( onTap: () { + widget + .callBack([...page.defaultParams]..remove(variable)); Navigator.of(context, rootNavigator: true).pop(null); - widget.page.params.remove(variable); - widget.callBack(widget.page.params); }, child: MouseRegion( cursor: SystemMouseCursors.click, @@ -274,7 +283,7 @@ class PaddingsState extends State { text: variable.name, backgroundColor: Palette.bgGrey, callBack: (final text) { - if (page.params.indexWhere( + if (page.defaultParams.indexWhere( (final element) => element.name.toLowerCase() == text.toLowerCase(), @@ -419,12 +428,12 @@ class PaddingsState extends State { child: CButton( label: 'Close', callback: () { - for (var i = 0; i < widget.page.params.length; i++) { - if (widget.page.params[i].id == variable.id) { - widget.page.params[i] = variable; + for (var i = 0; i < page.defaultParams.length; i++) { + if (page.defaultParams[i].id == variable.id) { + page.defaultParams[i] = variable; } } - widget.callBack(widget.page.params); + widget.callBack(page.defaultParams); Navigator.of(context, rootNavigator: true).pop(null); }, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/states.dart b/teta_widgets/lib/src/elements/controls/atoms/page_states.dart similarity index 82% rename from teta_widgets/lib/src/elements/controls/atoms/states.dart rename to teta_widgets/lib/src/elements/controls/atoms/page_states.dart index 30468116..bfbfae02 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/states.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/page_states.dart @@ -5,13 +5,13 @@ import 'package:enum_to_string/enum_to_string.dart'; // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:hovering/hovering.dart'; import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/src/design_system/textfield/multi_line_textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/node.dart'; import 'package:uuid/uuid.dart'; class StatesControl extends StatefulWidget { @@ -42,22 +42,25 @@ class StatesControlState extends State { const pagePrefix = 'State'; var pageName = ''; var index = 0; + final pageState = + BlocProvider.of(context).state as PageLoaded; do { index++; pageName = '$pagePrefix $index'; - } while (widget.page.states.indexWhere( + } while (pageState.page.defaultStates.indexWhere( (final element) => element.name == pageName, ) != -1); - widget.page.states.add( - VariableObject( - id: const Uuid().v1(), - type: VariableType.string, - name: pageName, - defaultValue: '0', - ), + widget.callBack( + [...pageState.page.defaultStates]..remove( + VariableObject( + id: const Uuid().v1(), + type: VariableType.string, + name: pageName, + defaultValue: '0', + ), + ), ); - widget.callBack(widget.page.states); }, child: HoverWidget( hoverChild: Padding( @@ -95,51 +98,57 @@ class StatesControlState extends State { ), ], ), - Column( - children: widget.page.states - .map( - (final variable) => Row( - children: [ - Expanded( - child: HoverWidget( - hoverChild: item(variable, onHover: true), - onHover: (final e) {}, - child: item(variable, onHover: false), - ), - ), - Padding( - padding: const EdgeInsets.only( - left: 8, - top: 6, - right: 6, - ), - child: GestureDetector( - onTap: () { - widget.page.states.remove(variable); - widget.callBack(widget.page.states); - }, - child: Tooltip( - message: 'Delete. This action cannot be undone', + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + children: state.page.defaultStates + .map( + (final variable) => Row( + children: [ + Expanded( child: HoverWidget( - hoverChild: const Icon( - FeatherIcons.x, - color: Colors.red, - size: 20, - ), + hoverChild: item(variable, onHover: true), onHover: (final e) {}, - child: const Icon( - FeatherIcons.x, - color: Colors.white, - size: 20, + child: item(variable, onHover: false), + ), + ), + Padding( + padding: const EdgeInsets.only( + left: 8, + top: 6, + right: 6, + ), + child: GestureDetector( + onTap: () { + widget.callBack( + [...state.page.defaultStates]..remove(variable), + ); + }, + child: Tooltip( + message: 'Delete. This action cannot be undone', + child: HoverWidget( + hoverChild: const Icon( + FeatherIcons.x, + color: Colors.red, + size: 20, + ), + onHover: (final e) {}, + child: const Icon( + FeatherIcons.x, + color: Colors.white, + size: 20, + ), + ), ), ), ), - ), + ], ), - ], - ), - ) - .toList(), + ) + .toList(), + ); + }, ), ], ); @@ -151,7 +160,9 @@ class StatesControlState extends State { }) { return GestureDetector( onTap: () { - showAlert(context, widget.page, variable); + final page = (context.read().state as PageLoaded).page; + + showAlert(context, page, variable); }, child: Container( margin: const EdgeInsets.only(top: 8), @@ -227,9 +238,10 @@ class StatesControlState extends State { ), GestureDetector( onTap: () { + widget.callBack( + [...page.defaultStates]..remove(variable), + ); Navigator.of(context, rootNavigator: true).pop(null); - widget.page.states.remove(variable); - widget.callBack(widget.page.states); }, child: MouseRegion( cursor: SystemMouseCursors.click, @@ -270,7 +282,7 @@ class StatesControlState extends State { backgroundColor: Palette.bgGrey, text: variable.name, callBack: (final text) { - if (page.states.indexWhere( + if (page.defaultStates.indexWhere( (final element) => element.name.toLowerCase() == text.toLowerCase(), @@ -413,12 +425,12 @@ class StatesControlState extends State { child: CButton( label: 'Close', callback: () { - for (var i = 0; i < widget.page.states.length; i++) { - if (widget.page.states[i].id == variable.id) { - widget.page.states[i] = variable; + for (var i = 0; i < page.defaultStates.length; i++) { + if (page.defaultStates[i].id == variable.id) { + page.defaultStates[i] = variable; } } - widget.callBack(widget.page.states); + widget.callBack(page.defaultStates); Navigator.of(context, rootNavigator: true).pop(null); }, ), diff --git a/teta_widgets/lib/src/elements/controls/atoms/text.dart b/teta_widgets/lib/src/elements/controls/atoms/text.dart index 82db886a..70b143c3 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text.dart @@ -44,9 +44,6 @@ class TextControl extends StatefulWidget { } class PaddingsState extends State { - int? nodeId; - bool? isUpdated; - String? text; late TextEditingController controller; late TextEditingController keyController; String databaseName = ''; @@ -58,18 +55,23 @@ class PaddingsState extends State { FTextTypeEnum typeOfInput = FTextTypeEnum.text; bool isChanged = false; + DatasetObject dataset = DatasetObject.empty(); + @override void initState() { controller = TextEditingController(); keyController = TextEditingController(); - nodeId = widget.node.nid; try { - text = widget.value.getValue(context); - controller.text = text!; + controller.text = widget.value.getValue(context); typeOfInput = widget.value.type!; if (widget.value.datasetName != null) { databaseName = widget.value.datasetName!; } + final datasets = (context.read().state as PageLoaded).datasets; + final index = datasets.indexWhere( + (final element) => element.getName == widget.value.datasetName, + ); + dataset = index != -1 ? datasets[index] : DatasetObject.empty(); databaseAttribute = widget.value.datasetAttr!; datasetSubListData = widget.value.datasetSubListData!; datasetSubMapData = widget.value.datasetSubMapData!; @@ -81,11 +83,6 @@ class PaddingsState extends State { @override Widget build(final BuildContext context) { - final index = widget.page.datasets.indexWhere( - (final element) => element.getName == widget.value.datasetName, - ); - final dataset = - index != -1 ? widget.page.datasets[index] : DatasetObject.empty(); return BlocListener( listener: (final context, final device) { controller.text = widget.value.getValue(context); @@ -94,14 +91,6 @@ class PaddingsState extends State { builder: (final context, final device) => BlocBuilder>( builder: (final context, final state) { - if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = widget.value.getValue(context); - } - } - } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -116,8 +105,7 @@ class PaddingsState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => - DevicesDialog(ctx: context), + builder: (final ctx) => const DevicesDialog(), ); }, child: Image.asset( @@ -348,128 +336,143 @@ class PaddingsState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - Column( - children: [ - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + children: [ + CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + widget.valueType != VariableType.dynamic + ? element.type == widget.valueType + : true, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - widget.valueType != VariableType.dynamic - ? element.type == widget.valueType - : true, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); - }, - ), - if ((widget.page.params + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ), + if ((state.page.defaultParams + .firstWhereOrNull( + (final element) => + element.name == + widget.value.paramName, + ) + ?.type ?? + VariableType.int) == + VariableType.json) + CTextField( + controller: keyController, + title: 'Map Key', + callBack: (final key) { + final old = widget.value; + widget.value.mapKey = key; + widget.callBack(widget.value, old); + }, + ), + ], + ); + }, + ), + if (widget.value.type == FTextTypeEnum.state) + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return Column( + children: [ + CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + widget.valueType != VariableType.dynamic + ? element.type == widget.valueType + : true, + ) + .map((final e) => e.name) + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ), + if (state.page.defaultStates .firstWhereOrNull( (final element) => - element.name == widget.value.paramName, + element.name == widget.value.stateName, ) - ?.type ?? - VariableType.int) == - VariableType.json) - CTextField( - controller: keyController, - title: 'Map Key', - callBack: (final key) { - final old = widget.value; - widget.value.mapKey = key; - widget.callBack(widget.value, old); - }, - ), - ], + ?.type == + VariableType.json) + CMiniTextField( + text: widget.value.mapKey, + title: 'Map Key', + callBack: (final key) { + final old = widget.value; + widget.value.mapKey = key; + widget.callBack(widget.value, old); + }, + ), + ], + ); + }, ), - if (widget.value.type == FTextTypeEnum.state) - Column( - children: [ - CDropdown( - value: widget.page.states - .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - widget.valueType != VariableType.dynamic - ? element.type == widget.valueType - : true, - ) - .map((final e) => e.name) + if (widget.value.type == FTextTypeEnum.languages) + BlocBuilder( + builder: (final context, final state) { + if (state is! ConfigStateLoaded) return const SizedBox(); + return CDropdown( + value: widget.value.keyTranslator, + items: state.config.appLanguage.terms.entries + .map((final e) => e.key) .toList(), - onChange: (final newValue) { + onChange: (final value) { final old = widget.value; - widget.value.stateName = newValue; + widget.value.keyTranslator = value; widget.callBack(widget.value, old); + setState(() {}); }, - ), - if (widget.page.states - .firstWhereOrNull( - (final element) => - element.name == widget.value.stateName, - ) - ?.type == - VariableType.json) - CMiniTextField( - text: widget.value.mapKey, - title: 'Map Key', - callBack: (final key) { - final old = widget.value; - widget.value.mapKey = key; - widget.callBack(widget.value, old); - }, - ), - ], - ), - if (widget.value.type == FTextTypeEnum.languages) - CDropdown( - value: widget.value.keyTranslator, - items: (BlocProvider.of(context) - .state! - .config - ?.appLanguage - ?.terms ?? - {}) - .entries - .map((final e) => e.key) - .toList(), - onChange: (final value) { - final old = widget.value; - widget.value.keyTranslator = value; - widget.callBack(widget.value, old); - setState(() {}); + ); }, ), if (widget.value.type == FTextTypeEnum.dataset) - CDropdown( - value: widget.page.datasets + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.datasets + .map((final e) => e.getName) + .where((final element) => element != 'null') + .contains(widget.value.datasetName) + ? widget.value.datasetName + : null, + items: state.datasets .map((final e) => e.getName) .where((final element) => element != 'null') - .contains(widget.value.datasetName) - ? widget.value.datasetName - : null, - items: widget.page.datasets - .map((final e) => e.getName) - .where((final element) => element != 'null') - .toList(), - onChange: (final newValue) { - setState(() { - databaseName = newValue!; - }); - final old = widget.value; - widget.value.datasetName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + setState(() { + databaseName = newValue!; + }); + final old = widget.value; + widget.value.datasetName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.valueType == VariableType.string || @@ -691,9 +694,7 @@ class PaddingsState extends State { in widget.value.combination ?? []) TextControl( valueType: VariableType.dynamic, - node: widget.node, value: element, - page: widget.page, title: '', isSubControl: true, withConvertTo: true, diff --git a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart index 67677293..eb823ebf 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart @@ -28,9 +28,6 @@ class WebViewControllerControl extends StatefulWidget { } class WebViewControllerControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -38,10 +35,8 @@ class WebViewControllerControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -54,12 +49,7 @@ class WebViewControllerControlState extends State { return BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -91,43 +81,53 @@ class WebViewControllerControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.webViewController, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.webViewController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.webViewController, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.webViewController, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/current_song_controll.dart b/teta_widgets/lib/src/elements/controls/current_song_controll.dart index 8b31478b..88eddbe4 100644 --- a/teta_widgets/lib/src/elements/controls/current_song_controll.dart +++ b/teta_widgets/lib/src/elements/controls/current_song_controll.dart @@ -27,9 +27,6 @@ class CurrentSongControl extends StatefulWidget { } class CurrentSongControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -37,10 +34,8 @@ class CurrentSongControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -54,12 +49,7 @@ class CurrentSongControlState extends State { buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -91,43 +81,53 @@ class CurrentSongControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.currentSongData, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.currentSongData, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.currentSongData, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.currentSongData, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart index c1ff7903..bc09f527 100644 --- a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart +++ b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart @@ -27,9 +27,6 @@ class GoogleMapsCubitControl extends StatefulWidget { } class GoogleMapsCubitControlState extends State { - int? nodeId; - bool? isUpdated; - String? text; TextEditingController controller = TextEditingController(); String databaseName = ''; String databaseAttribute = ''; @@ -37,10 +34,8 @@ class GoogleMapsCubitControlState extends State { @override void initState() { - nodeId = widget.node.nid; try { - text = widget.value.value ?? ''; - controller.text = text!; + controller.text = widget.value.value ?? ''; typeOfInput = widget.value.type!; databaseName = widget.value.datasetName!; databaseAttribute = widget.value.datasetAttr!; @@ -54,12 +49,7 @@ class GoogleMapsCubitControlState extends State { buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { - if (mounted) { - nodeId = state.first.nid; - controller.text = controller.text = widget.value.value ?? ''; - } - } + controller.text = controller.text = widget.value.value ?? ''; } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -91,43 +81,53 @@ class GoogleMapsCubitControlState extends State { ], ), if (widget.value.type == FTextTypeEnum.param) - CDropdown( - value: widget.page.params + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultParams + .map((final e) => e.name) + .contains(widget.value.paramName) + ? widget.value.paramName + : null, + items: state.page.defaultParams + .where( + (final element) => + element.type == VariableType.googleMapsCubit, + ) .map((final e) => e.name) - .contains(widget.value.paramName) - ? widget.value.paramName - : null, - items: widget.page.params - .where( - (final element) => - element.type == VariableType.googleMapsCubit, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.paramName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.paramName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), if (widget.value.type == FTextTypeEnum.state) - CDropdown( - value: widget.page.states + BlocBuilder( + builder: (final context, final state) { + if (state is! PageLoaded) return const SizedBox(); + return CDropdown( + value: state.page.defaultStates + .map((final e) => e.name) + .contains(widget.value.stateName) + ? widget.value.stateName + : null, + items: state.page.defaultStates + .where( + (final element) => + element.type == VariableType.googleMapsCubit, + ) .map((final e) => e.name) - .contains(widget.value.stateName) - ? widget.value.stateName - : null, - items: widget.page.states - .where( - (final element) => - element.type == VariableType.googleMapsCubit, - ) - .map((final e) => e.name) - .toList(), - onChange: (final newValue) { - final old = widget.value; - widget.value.stateName = newValue; - widget.callBack(widget.value, old); + .toList(), + onChange: (final newValue) { + final old = widget.value; + widget.value.stateName = newValue; + widget.callBack(widget.value, old); + }, + ); }, ), ], diff --git a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart index 758a227d..2c47bf77 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart @@ -3,13 +3,13 @@ // Flutter imports: import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/size.dart'; import 'package:teta_widgets/src/elements/controls/key_constants.dart'; import 'package:teta_widgets/src/elements/controls/type.dart'; import 'package:teta_widgets/src/elements/features/sizes.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class SizesPrefabControl extends StatelessWidget { const SizesPrefabControl({ @@ -37,6 +37,7 @@ class SizesPrefabControl extends StatelessWidget { keyAttr: DBKeys.width, isFromSizesPrefab: true, callBack: (final value, final old) { + final node = BlocProvider.of(context).state.first; ControlBuilder.toDB( node, context, @@ -52,13 +53,16 @@ class SizesPrefabControl extends StatelessWidget { title: 'Height', keyAttr: DBKeys.height, isFromSizesPrefab: true, - callBack: (final value, final old) => ControlBuilder.toDB( - node, - context, - DBKeys.height, - value, - old, - ), + callBack: (final value, final old) { + final node = BlocProvider.of(context).state.first; + ControlBuilder.toDB( + node, + context, + DBKeys.height, + value, + old, + ); + }, ), ], ); diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index ae3a8130..00f5e7bf 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -4,9 +4,9 @@ // Flutter imports: import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:teta_core/teta_core.dart'; -import 'package:teta_repositories/src/project_repository.dart'; import 'package:teta_repositories/src/project_styles_repository.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/fill.dart'; @@ -21,8 +21,8 @@ import 'package:teta_widgets/src/elements/controls/atoms/text_styles.dart'; import 'package:teta_widgets/src/elements/controls/type.dart'; import 'package:teta_widgets/src/elements/features/fill.dart'; import 'package:teta_widgets/src/elements/features/text_style.dart'; +import 'package:teta_widgets/src/elements/index.dart'; import 'package:teta_widgets/src/elements/nodes/enum.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextPrefabControl extends StatelessWidget { const TextPrefabControl({ @@ -38,200 +38,196 @@ class TextPrefabControl extends StatelessWidget { @override Widget build(final BuildContext context) { - return Column( - children: [ - TextStylesControl( - node: node, - textStyle: textStyle, - callBack: (final textStyleModel, final flag, final old) { - if (textStyleModel == null) return; - if (flag) { - sl.get().assignTextStyle( - styleName: textStyleModel, - node: node, - keyValue: keyValue, - ); - } - final old = textStyle; - textStyle.textStyleModel = textStyleModel; - ControlBuilder.toDB( - node, - context, - keyValue, - textStyle.toJson(), - old.toJson(), - ); - }, - ), - const Padding( - padding: EdgeInsets.only(top: 16), - child: Divider(height: 1, color: Colors.white38), - ), - if (!(node.globalType == NType.text) || - node.body.attributes[keyValue]?.textStyleModel == null) - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(top: 16), - child: TParagraph( - title ?? 'Text Properties', - ), - ), - Padding( - padding: const EdgeInsets.only(top: 16), - child: FontSizeControl( - node: node, - textStyle: textStyle, - callBack: (final value, final old) { - ControlBuilder.toDB( - node, - context, - keyValue, - value, - old, - ); - }, - ), - ), - Padding( - padding: const EdgeInsets.only(top: 16), - child: FontFamilyControl( - node: node, - textStyle: textStyle, - callBack: (final value, final old) => ControlBuilder.toDB( - node, - context, - keyValue, - value, - old, - ), - ), - ), - Padding( - padding: const EdgeInsets.only(top: 16), - child: FontWeightControl( - node: node, - textStyle: textStyle, - callBack: (final value, final old) => ControlBuilder.toDB( - node, - context, - keyValue, - value, - old, + return BlocBuilder>( + builder: (final context, final state) { + return Column( + children: [ + TextStylesControl( + textStyle: textStyle, + callBack: (final textStyleModel, final flag, final old) { + if (textStyleModel == null) return; + if (flag) { + sl.get().assignTextStyle( + styleName: textStyleModel, + node: state.first, + keyValue: keyValue, + ); + } + final old = textStyle; + textStyle.textStyleModel = textStyleModel; + ControlBuilder.toDB( + state.first, + context, + keyValue, + textStyle.toJson(), + old.toJson(), + ); + }, + ), + const Padding( + padding: EdgeInsets.only(top: 16), + child: Divider(height: 1, color: Colors.white38), + ), + if (!(state.first.globalType == NType.text) || + state.first.body.attributes[keyValue]?.textStyleModel == null) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(top: 16), + child: TParagraph( + title ?? 'Text Properties', + ), ), - ), - ), - Padding( - padding: const EdgeInsets.only(top: 16), - child: Row( - children: [ - Expanded( - child: FontStyleControls( - node: node, - textStyle: textStyle, - callBack: (final value, final old) => - ControlBuilder.toDB( - node, + Padding( + padding: const EdgeInsets.only(top: 16), + child: FontSizeControl( + textStyle: textStyle, + callBack: (final value, final old) { + ControlBuilder.toDB( + state.first, context, keyValue, value, old, + ); + }, + ), + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: FontFamilyControl( + textStyle: textStyle, + callBack: (final value, final old) => ControlBuilder.toDB( + state.first, + context, + keyValue, + value, + old, + ), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: FontWeightControl( + textStyle: textStyle, + callBack: (final value, final old) => ControlBuilder.toDB( + state.first, + context, + keyValue, + value, + old, + ), + ), + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Row( + children: [ + Expanded( + child: FontStyleControls( + textStyle: textStyle, + callBack: (final value, final old) => + ControlBuilder.toDB( + state.first, + context, + keyValue, + value, + old, + ), + ), ), + const Padding(padding: EdgeInsets.only(left: 8)), + const Spacer(), + ], + ), + ), + ], + ), + Padding( + padding: const EdgeInsets.only(top: 16, bottom: 16), + child: Row( + children: [ + Expanded( + child: TextAlignControls( + textStyle: textStyle, + callBack: (final value, final old) => ControlBuilder.toDB( + state.first, + context, + keyValue, + value, + old, ), ), - const Padding(padding: EdgeInsets.only(left: 8)), - const Spacer(), - ], - ), + ), + const Padding(padding: EdgeInsets.only(left: 8)), + Expanded( + child: TextDecorationControl( + textStyle: textStyle, + callBack: (final value, final old) => ControlBuilder.toDB( + state.first, + context, + keyValue, + value, + old, + ), + ), + ), + ], ), - ], - ), - Padding( - padding: const EdgeInsets.only(top: 16, bottom: 16), - child: Row( - children: [ - Expanded( - child: TextAlignControls( - node: node, - textStyle: textStyle, - callBack: (final value, final old) => ControlBuilder.toDB( - node, + ), + if (kDebugMode) + TextDirectionControl( + textDirection: textStyle.textDirection!, + callBack: (final dir, final old) { + final old = FTextStyle.fromJson(textStyle.toJson()); + textStyle.textDirection = dir; + ControlBuilder.toDB( + state.first, context, keyValue, - value, + textStyle.toJson(), old, - ), - ), + ); + }, ), - const Padding(padding: EdgeInsets.only(left: 8)), - Expanded( - child: TextDecorationControl( - node: node, - textStyle: textStyle, - callBack: (final value, final old) => ControlBuilder.toDB( - node, + const Gap(16), + FillControl( + title: 'Text Color', + fill: textStyle.fill ?? FFill(), + isImageEnabled: false, + isNoneEnabled: false, + type: FillTypeControlType.onlySolid, + callBack: (final color, final isStyled, final old) { + if (!isStyled) { + final old = FTextStyle.fromJson(textStyle.toJson()); + textStyle.fill = color; + ControlBuilder.toDB( + state.first, context, keyValue, - value, + textStyle.toJson(), old, - ), - ), - ), - ], - ), - ), - if (kDebugMode) - TextDirectionControl( - node: node, - textDirection: textStyle.textDirection!, - callBack: (final dir, final old) { - final old = FTextStyle.fromJson(textStyle.toJson()); - textStyle.textDirection = dir; - ControlBuilder.toDB( - node, - context, - keyValue, - textStyle.toJson(), - old, - ); - }, - ), - const Gap(16), - FillControl( - title: 'Text Color', - fill: textStyle.fill ?? FFill(), - isImageEnabled: false, - isNoneEnabled: false, - type: FillTypeControlType.onlySolid, - callBack: (final color, final isStyled, final old) { - if (!isStyled) { - final old = FTextStyle.fromJson(textStyle.toJson()); - textStyle.fill = color; - ControlBuilder.toDB( - node, - context, - keyValue, - textStyle.toJson(), - old, - ); - } - //! TODO: - /*else { - if (textStyle.fill!.paletteStyle is int) { - sl.get().updateColorStyle( - ColorStyleModel( - id: textStyle.fill!.paletteStyle! as int, - channelId: Constants.instance.currentChannelID!, - fill: color, - light: textStyle - ), - ); - } - }*/ - }, - ), - ], + ); + } + //! TODO: + /*else { + if (textStyle.fill!.paletteStyle is int) { + sl.get().updateColorStyle( + ColorStyleModel( + id: textStyle.fill!.paletteStyle! as int, + channelId: Constants.instance.currentChannelID!, + fill: color, + light: textStyle + ), + ); + } + }*/ + }, + ), + ], + ); + }, ); } } diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 2688bd10..766943a6 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -44,7 +44,7 @@ import 'package:teta_widgets/src/elements/controls/atoms/page_params.dart'; import 'package:teta_widgets/src/elements/controls/atoms/physics.dart'; import 'package:teta_widgets/src/elements/controls/atoms/size.dart'; import 'package:teta_widgets/src/elements/controls/atoms/src_image.dart'; -import 'package:teta_widgets/src/elements/controls/atoms/states.dart'; +import 'package:teta_widgets/src/elements/controls/atoms/page_states.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; import 'package:teta_widgets/src/elements/controls/atoms/webview_controller.dart'; import 'package:teta_widgets/src/elements/controls/current_song_controll.dart'; diff --git a/teta_widgets/lib/src/elements/features/actions/element.dart b/teta_widgets/lib/src/elements/features/actions/element.dart index 8feca765..8451cb7e 100644 --- a/teta_widgets/lib/src/elements/features/actions/element.dart +++ b/teta_widgets/lib/src/elements/features/actions/element.dart @@ -588,7 +588,9 @@ class FActionElement extends Equatable { /// Get avaiable action types for drop down list List getTypes( - final ProjectConfigModel? config, final PageObject page) { + final ProjectConfigModel? config, + final PageObject page, + ) { if (config != null) { try { return [ diff --git a/teta_widgets/lib/src/elements/features/fill.dart b/teta_widgets/lib/src/elements/features/fill.dart index e8f81530..959188e2 100644 --- a/teta_widgets/lib/src/elements/features/fill.dart +++ b/teta_widgets/lib/src/elements/features/fill.dart @@ -99,7 +99,7 @@ class FFill { if (element.name == paletteStyle) model = element; }); if (model != null) { - return isLight ? model!.light! : model!.fill!; + return isLight ? model!.light : model!.fill; } else { return FFill().ready(FFillType.solid); } @@ -129,8 +129,8 @@ class FFill { }); fill = (model != null) ? BlocProvider.of(context).state - ? model!.light! - : model!.fill! + ? model!.light + : model!.fill : FFill().ready(FFillType.solid); } return fill.levels!.first.color.toUpperCase(); diff --git a/teta_widgets/lib/src/elements/widgets/badge.dart b/teta_widgets/lib/src/elements/widgets/badge.dart index 928bcf38..c3bf5331 100644 --- a/teta_widgets/lib/src/elements/widgets/badge.dart +++ b/teta_widgets/lib/src/elements/widgets/badge.dart @@ -62,8 +62,8 @@ class WBadge extends StatelessWidget { HexColor _getbadgeColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart index 1670fd25..65b66d28 100644 --- a/teta_widgets/lib/src/elements/widgets/bottombaritem.dart +++ b/teta_widgets/lib/src/elements/widgets/bottombaritem.dart @@ -99,8 +99,8 @@ class WBottomBarItem extends StatelessWidget { ) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/card.dart b/teta_widgets/lib/src/elements/widgets/card.dart index 4336c20c..0a570a51 100644 --- a/teta_widgets/lib/src/elements/widgets/card.dart +++ b/teta_widgets/lib/src/elements/widgets/card.dart @@ -61,8 +61,8 @@ class WCard extends StatelessWidget { HexColor _getCardColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(color.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart b/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart index 7fe14c45..24641516 100644 --- a/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart +++ b/teta_widgets/lib/src/elements/widgets/circular_progress_indicator.dart @@ -41,8 +41,8 @@ class WCircularProgressIndicator extends StatelessWidget { HexColor _getCircularColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/component.dart b/teta_widgets/lib/src/elements/widgets/component.dart index 69be25ea..48e47399 100644 --- a/teta_widgets/lib/src/elements/widgets/component.dart +++ b/teta_widgets/lib/src/elements/widgets/component.dart @@ -68,7 +68,7 @@ class _WComponentState extends State { .toList() ], ); - final nodes = await fetch(_component, context); + await fetch(_component, context); } if (_component != null && !_component.isHardCoded) { Logger.printMessage('enter here'); @@ -145,7 +145,7 @@ class _WComponentState extends State { child: state.page.scaffold.toWidget( state: widget.state.copyWith( params: (widget.paramsToSend != null) - ? getVariableObjectsFromParams(page) + ? getVariableObjectsFromParams(state.page) : state.params, states: state.states, dataset: state.datasets, @@ -188,7 +188,7 @@ class _WComponentState extends State { } List getVariableObjectsFromParams(final PageObject page) { - return page.params.map((final e) { + return page.defaultParams.map((final e) { if (widget.paramsToSend?[e.id] != null) { if (widget.paramsToSend?[e.id]['dataset'] == 'Text') { e.value = widget.paramsToSend?[e.id]['label']; diff --git a/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart b/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart index 21372b33..54febd3d 100644 --- a/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart +++ b/teta_widgets/lib/src/elements/widgets/concentric_page_view.dart @@ -67,8 +67,8 @@ class _WConcentricPageViewState extends State { ) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(widget.fill.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/divider.dart b/teta_widgets/lib/src/elements/widgets/divider.dart index fb0d0fc7..6a4e557f 100644 --- a/teta_widgets/lib/src/elements/widgets/divider.dart +++ b/teta_widgets/lib/src/elements/widgets/divider.dart @@ -47,8 +47,8 @@ class WDivider extends StatelessWidget { HexColor _getDividerColor(final ColorStyleModel? model, final bool isLight) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(fill.levels!.first.color); } diff --git a/teta_widgets/lib/src/elements/widgets/placeholder.dart b/teta_widgets/lib/src/elements/widgets/placeholder.dart index 36e2ce38..87c49eda 100644 --- a/teta_widgets/lib/src/elements/widgets/placeholder.dart +++ b/teta_widgets/lib/src/elements/widgets/placeholder.dart @@ -59,11 +59,13 @@ class WPlaceholder extends StatelessWidget { // ignore: avoid_positional_boolean_parameters HexColor _getPlaceHolderColor( - final ColorStyleModel? model, final bool isLight) { + final ColorStyleModel? model, + final bool isLight, + ) { if (model != null) { return isLight - ? HexColor(model.light!.levels!.first.color) - : HexColor(model.fill!.levels!.first.color); + ? HexColor(model.light.levels!.first.color) + : HexColor(model.fill.levels!.first.color); } else { return HexColor(color.levels!.first.color); } From 9a8b70f95a8f93b20412edb6acacbe172f73cf15 Mon Sep 17 00:00:00 2001 From: andreabuttarelli Date: Sun, 29 Jan 2023 12:34:44 +0100 Subject: [PATCH 19/23] Update pubspec.yaml --- teta_widgets/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teta_widgets/pubspec.yaml b/teta_widgets/pubspec.yaml index c1fe5290..2e802d45 100644 --- a/teta_widgets/pubspec.yaml +++ b/teta_widgets/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: mixpanel_analytics: 2.1.1 # Bloc - flutter_bloc: 7.3.3 + flutter_bloc: 8.1.1 equatable: 2.0.3 # Typography & Icons From 4a08370e89c084e7355a710767964ff6ff49c39c Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Sun, 29 Jan 2023 12:38:47 +0100 Subject: [PATCH 20/23] feat(device mode cubit) --- .../src/elements/controls/atoms/aligns.dart | 24 ++++--- .../controls/atoms/border_radius.dart | 20 +++--- .../elements/controls/atoms/font_size.dart | 10 +-- .../src/elements/controls/atoms/margins.dart | 10 +-- .../lib/src/elements/controls/atoms/size.dart | 21 +++--- .../lib/src/elements/controls/atoms/text.dart | 9 +-- .../lib/src/elements/features/align.dart | 10 +-- .../src/elements/features/border_radius.dart | 4 +- .../lib/src/elements/features/font_size.dart | 8 +-- .../lib/src/elements/features/margins.dart | 14 ++-- .../lib/src/elements/features/sizes.dart | 19 +++--- .../elements/features/text_type_input.dart | 68 +++++++++++++------ teta_widgets/lib/src/elements/nodes/node.dart | 2 + .../widgets/responsive_condition.dart | 4 +- 14 files changed, 129 insertions(+), 94 deletions(-) diff --git a/teta_widgets/lib/src/elements/controls/atoms/aligns.dart b/teta_widgets/lib/src/elements/controls/atoms/aligns.dart index 57855a63..ff368080 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/aligns.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/aligns.dart @@ -37,7 +37,7 @@ class AlignsControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (final context, final device) => Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -50,13 +50,13 @@ class AlignsControlState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(), + builder: (final ctx) => const DevicesDialog(), ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == DeviceType.tablet + : device.info.identifier.type == DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, width: 24, @@ -91,17 +91,19 @@ class AlignsControlState extends State { final old = FAlign.fromJson(widget.align.toJson()); final device = BlocProvider.of(context).state; - Logger.printMessage('${device.identifier.type}'); + Logger.printMessage('${device.info.identifier.type}'); final align = widget.align.copyWith( - align: device.identifier.type == DeviceType.phone - ? FAlign.convertDropDownToValue(newValue) - : null, - alignTablet: device.identifier.type == DeviceType.tablet + align: device.info.identifier.type == DeviceType.phone ? FAlign.convertDropDownToValue(newValue) : null, + alignTablet: + device.info.identifier.type == DeviceType.tablet + ? FAlign.convertDropDownToValue(newValue) + : null, alignDesktop: - device.identifier.type == DeviceType.laptop || - device.identifier.type == DeviceType.desktop + device.info.identifier.type == DeviceType.laptop || + device.info.identifier.type == + DeviceType.desktop ? FAlign.convertDropDownToValue(newValue) : null, ); diff --git a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart index 8ee343b6..120fa7f1 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart @@ -47,11 +47,11 @@ class BorderRadiusControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener( + return BlocListener( listener: (final context, final device) { - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { radius = widget.borderRadius.radius; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { radius = widget.borderRadius.radiusTablet; } else { radius = widget.borderRadius.radiusDesktop; @@ -60,14 +60,14 @@ class BorderRadiusControlState extends State { controllers[i].text = '${radius![i]}'; } }, - child: BlocBuilder( + child: BlocBuilder( builder: (final context, final device) => BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { radius = widget.borderRadius.radius; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { radius = widget.borderRadius.radiusTablet; } else { radius = widget.borderRadius.radiusDesktop; @@ -96,13 +96,15 @@ class BorderRadiusControlState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(), + builder: (final ctx) => + const DevicesDialog(), ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == + DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == + : device.info.identifier.type == DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart index 6cf67cf4..bfca41ee 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart @@ -62,11 +62,11 @@ class FontSizeState extends State { @override Widget build(final BuildContext context) { - return BlocListener( + return BlocListener( listener: (final context, final state) { controller.text = '${widget.textStyle.fontSize!.get(context)}'; }, - child: BlocBuilder( + child: BlocBuilder( builder: (final context, final device) => BlocListener>( listener: (final context, final state) { @@ -87,13 +87,13 @@ class FontSizeState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(), + builder: (final ctx) => const DevicesDialog(), ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == DeviceType.tablet + : device.info.identifier.type == DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, width: 24, diff --git a/teta_widgets/lib/src/elements/controls/atoms/margins.dart b/teta_widgets/lib/src/elements/controls/atoms/margins.dart index 0819b344..a67d4d96 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/margins.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/margins.dart @@ -76,7 +76,7 @@ class MarginsState extends State { @override Widget build(final BuildContext context) { - return BlocListener( + return BlocListener( listener: (final context, final state) { margins = widget.value.getList(context); for (var i = 0; i < 4; i++) { @@ -92,7 +92,7 @@ class MarginsState extends State { } isLinked = !flag; }, - child: BlocBuilder( + child: BlocBuilder( builder: (final context, final device) => BlocBuilder>( builder: (final context, final state) { @@ -130,13 +130,13 @@ class MarginsState extends State { onTap: () { showDialog( context: context, - builder: (final ctx) => DevicesDialog(), + builder: (final ctx) => const DevicesDialog(), ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == + : device.info.identifier.type == DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, diff --git a/teta_widgets/lib/src/elements/controls/atoms/size.dart b/teta_widgets/lib/src/elements/controls/atoms/size.dart index b8fac563..83ffcd07 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/size.dart @@ -49,14 +49,14 @@ class SizeControlsState extends State { @override Widget build(final BuildContext context) { - return BlocListener( + return BlocListener( listener: (final context, final device) { flag = widget.size.get(context: context, isWidth: widget.isWidth) != null; String? size; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { size = widget.size.size; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { size = widget.size.sizeTablet; } else { size = widget.size.sizeDesktop; @@ -76,7 +76,7 @@ class SizeControlsState extends State { : '$size'; } }, - child: BlocBuilder( + child: BlocBuilder( builder: (final context, final device) => BlocBuilder>( builder: (final context, final state) { @@ -86,9 +86,9 @@ class SizeControlsState extends State { .get(context: context, isWidth: widget.isWidth) != null; var size = widget.size.size; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { size = widget.size.size; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { size = widget.size.sizeTablet; } else { size = widget.size.sizeDesktop; @@ -131,9 +131,10 @@ class SizeControlsState extends State { ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == DeviceType.tablet + : device.info.identifier.type == + DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, width: 20, @@ -261,10 +262,10 @@ class SizeControlsState extends State { padding: const EdgeInsets.only(right: 4), child: CMiniTextField( controller: controller, - text: (device.identifier.type == + text: (device.info.identifier.type == DeviceType.phone) ? widget.size.size - : (device.identifier.type == + : (device.info.identifier.type == DeviceType.tablet) ? widget.size.sizeTablet : widget.size.sizeDesktop, diff --git a/teta_widgets/lib/src/elements/controls/atoms/text.dart b/teta_widgets/lib/src/elements/controls/atoms/text.dart index 70b143c3..d64f18c6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text.dart @@ -83,11 +83,11 @@ class PaddingsState extends State { @override Widget build(final BuildContext context) { - return BlocListener( + return BlocListener( listener: (final context, final device) { controller.text = widget.value.getValue(context); }, - child: BlocBuilder( + child: BlocBuilder( builder: (final context, final device) => BlocBuilder>( builder: (final context, final state) { @@ -109,9 +109,10 @@ class PaddingsState extends State { ); }, child: Image.asset( - device.identifier.type == DeviceType.phone + device.info.identifier.type == DeviceType.phone ? Assets.icons.devices.smartphone.path - : device.identifier.type == DeviceType.tablet + : device.info.identifier.type == + DeviceType.tablet ? Assets.icons.devices.tablet.path : Assets.icons.devices.monitor.path, width: 20, diff --git a/teta_widgets/lib/src/elements/features/align.dart b/teta_widgets/lib/src/elements/features/align.dart index 5d905e2d..91e343e0 100644 --- a/teta_widgets/lib/src/elements/features/align.dart +++ b/teta_widgets/lib/src/elements/features/align.dart @@ -32,9 +32,9 @@ class FAlign { Alignment get(final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { return align!; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { return alignTablet ?? align!; } else { return alignDesktop ?? align!; @@ -43,10 +43,10 @@ class FAlign { String getStringForDropDown(final BuildContext context) { final device = BlocProvider.of(context).state; - Logger.printMessage('getStringForDropDown: ${device.identifier.type}'); - if (device.identifier.type == DeviceType.phone) { + Logger.printMessage('getStringForDropDown: ${device.info.identifier.type}'); + if (device.info.identifier.type == DeviceType.phone) { return convertValueToDropDown(align!); - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { return convertValueToDropDown(alignTablet ?? align!); } else { return convertValueToDropDown(alignDesktop ?? align!); diff --git a/teta_widgets/lib/src/elements/features/border_radius.dart b/teta_widgets/lib/src/elements/features/border_radius.dart index f68019cf..ab329185 100644 --- a/teta_widgets/lib/src/elements/features/border_radius.dart +++ b/teta_widgets/lib/src/elements/features/border_radius.dart @@ -88,9 +88,9 @@ class FBorderRadius { required final List value, }) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { radius = value; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { radiusTablet = value; } else { radiusDesktop = value; diff --git a/teta_widgets/lib/src/elements/features/font_size.dart b/teta_widgets/lib/src/elements/features/font_size.dart index 0565d485..e41b849f 100644 --- a/teta_widgets/lib/src/elements/features/font_size.dart +++ b/teta_widgets/lib/src/elements/features/font_size.dart @@ -31,9 +31,9 @@ class FFontSize { double get(final BuildContext context) { final device = BlocProvider.of(context).state; late double size; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { size = this.size; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { size = sizeTablet ?? this.size; } else { size = sizeDesktop ?? this.size; @@ -52,9 +52,9 @@ class FFontSize { void update(final double value, final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { size = value; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { sizeTablet = value; } else { sizeDesktop = value; diff --git a/teta_widgets/lib/src/elements/features/margins.dart b/teta_widgets/lib/src/elements/features/margins.dart index 21f5d060..6b23b015 100644 --- a/teta_widgets/lib/src/elements/features/margins.dart +++ b/teta_widgets/lib/src/elements/features/margins.dart @@ -27,9 +27,9 @@ class FMargins { EdgeInsets get(final BuildContext context) { var temp = marginsDesktop!; final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { temp = margins!; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { temp = marginsTablet!; } final left = MathExpression.parse(context: context, expression: temp[0]); @@ -46,9 +46,9 @@ class FMargins { List getList(final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { return margins!; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { return marginsTablet!; } else { return marginsDesktop!; @@ -58,7 +58,7 @@ class FMargins { static FMargins fromJson(final dynamic json) { if (json is List) { return FMargins( - margins: (json).map((final dynamic e) => '$e').toList(), + margins: json.map((final dynamic e) => '$e').toList(), ); } try { @@ -92,9 +92,9 @@ class FMargins { required final BuildContext context, }) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { margins = value; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { marginsTablet = value; } else { marginsDesktop = value; diff --git a/teta_widgets/lib/src/elements/features/sizes.dart b/teta_widgets/lib/src/elements/features/sizes.dart index c98d1a9d..ad549d4a 100644 --- a/teta_widgets/lib/src/elements/features/sizes.dart +++ b/teta_widgets/lib/src/elements/features/sizes.dart @@ -49,10 +49,10 @@ class FSize { var size = sizeDesktop ?? this.size!; var unit = unitDesktop ?? this.unit!; final device = BlocProvider.of(context).state; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { size = this.size ?? '0'; unit = this.unit!; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { size = sizeTablet ?? this.size ?? '0'; unit = unitTablet ?? this.unit!; } @@ -80,7 +80,8 @@ class FSize { if (unit == SizeUnit.percent || unit == SizeUnit.width || unit == SizeUnit.height) { - final screen = BlocProvider.of(context).state.screenSize; + final screen = + BlocProvider.of(context).state.info.screenSize; return isWidth ? value.toInt().w : value.toInt().h; } return value; @@ -88,9 +89,9 @@ class FSize { SizeUnit getUnit(final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { return unit = unit!; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { return unit = unitTablet ?? unit!; } return unitDesktop ?? unit!; @@ -101,9 +102,9 @@ class FSize { final BuildContext context, ) { final device = BlocProvider.of(context).state; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { size = newValue; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { sizeTablet = newValue; } else { sizeDesktop = newValue; @@ -115,9 +116,9 @@ class FSize { final BuildContext context, ) { final device = BlocProvider.of(context).state; - if (device.identifier.type == frame.DeviceType.phone) { + if (device.info.identifier.type == frame.DeviceType.phone) { unit = newUnit; - } else if (device.identifier.type == frame.DeviceType.tablet) { + } else if (device.info.identifier.type == frame.DeviceType.tablet) { unitTablet = newUnit; } else { unitDesktop = newUnit; diff --git a/teta_widgets/lib/src/elements/features/text_type_input.dart b/teta_widgets/lib/src/elements/features/text_type_input.dart index 45d45451..34ca17dc 100644 --- a/teta_widgets/lib/src/elements/features/text_type_input.dart +++ b/teta_widgets/lib/src/elements/features/text_type_input.dart @@ -15,7 +15,16 @@ import 'package:intl/intl.dart'; import 'package:recase/recase.dart'; import 'package:teta_core/teta_core.dart'; -enum FTextTypeEnum { text, imageUrl, param, state, dataset, asset, combined, languages } +enum FTextTypeEnum { + text, + imageUrl, + param, + state, + dataset, + asset, + combined, + languages +} enum ResultTypeEnum { string, @@ -92,7 +101,8 @@ class FTextTypeInput { final List states, ) { if (type == FTextTypeEnum.state) { - final state = states.firstWhereOrNull((final element) => element.name == stateName); + final state = + states.firstWhereOrNull((final element) => element.name == stateName); if (state?.type == VariableType.file) { return '${state?.file}'; } @@ -147,9 +157,11 @@ class FTextTypeInput { case ResultTypeEnum.string: return result; case ResultTypeEnum.int: - return int.tryParse(result as String) ?? 'Impossible to convert to int type'; + return int.tryParse(result as String) ?? + 'Impossible to convert to int type'; case ResultTypeEnum.double: - return double.tryParse(result as String) ?? 'Impossible to convert to double type'; + return double.tryParse(result as String) ?? + 'Impossible to convert to double type'; case ResultTypeEnum.bool: return (result as String?) == 'true' ? true @@ -182,7 +194,8 @@ class FTextTypeInput { ) { if (type == FTextTypeEnum.param) { try { - final param = params.firstWhereOrNull((final element) => element.name == paramName); + final param = params + .firstWhereOrNull((final element) => element.name == paramName); if (param?.type == VariableType.file) { return param?.file; } @@ -190,7 +203,8 @@ class FTextTypeInput { } catch (_) {} } if (type == FTextTypeEnum.state) { - final state = states.firstWhereOrNull((final element) => element.name == stateName); + final state = + states.firstWhereOrNull((final element) => element.name == stateName); if (state?.type == VariableType.file) { return state?.file; } @@ -198,7 +212,7 @@ class FTextTypeInput { } if (type == FTextTypeEnum.dataset) { Map? db = {}; - var dbLength = dataset + final dbLength = dataset .firstWhereOrNull((final element) => element.getName == datasetName) ?.getMap .length; @@ -244,9 +258,9 @@ class FTextTypeInput { } } final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { return value ?? ''; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { return valueTablet != '' ? valueTablet ?? value ?? '' : value ?? ''; } else { return valueDesktop != '' ? valueDesktop ?? value ?? '' : value ?? ''; @@ -255,9 +269,9 @@ class FTextTypeInput { String getValue(final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { return value ?? ''; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { return valueTablet != '' ? valueTablet ?? value ?? '' : value ?? ''; } else { return valueDesktop != '' ? valueDesktop ?? value ?? '' : value ?? ''; @@ -266,9 +280,9 @@ class FTextTypeInput { void updateValue(final String val, final BuildContext context) { final device = BlocProvider.of(context).state; - if (device.identifier.type == DeviceType.phone) { + if (device.info.identifier.type == DeviceType.phone) { value = val; - } else if (device.identifier.type == DeviceType.tablet) { + } else if (device.info.identifier.type == DeviceType.tablet) { valueTablet = val; } else { valueDesktop = val; @@ -306,12 +320,15 @@ class FTextTypeInput { datasetSubMapData: json?['dAT'] as String?, datasetLength: json?['dL'] as String?, keyTranslator: json?['kTrans'] as String?, - file: json?['f'] != null ? AssetFile.fromJson(json?['f'] as Map?) : null, + file: json?['f'] != null + ? AssetFile.fromJson(json?['f'] as Map?) + : null, mapKey: json?['mK'] as String?, combination: json?['cmb'] != null ? (json?['cmb'] as List) .map( - (final dynamic e) => FTextTypeInput.fromJson(e as Map), + (final dynamic e) => + FTextTypeInput.fromJson(e as Map), ) .toList() : [], @@ -388,7 +405,8 @@ class FTextTypeInput { return "TranslatorGenerator.instance.getString('''$keyTranslator''')"; } - final code = getRawToCode(loop, resultType: resultType, defaultValue: defaultValue); + final code = + getRawToCode(loop, resultType: resultType, defaultValue: defaultValue); if (type == FTextTypeEnum.combined || whiteSpace == false) { return code; @@ -420,7 +438,9 @@ class FTextTypeInput { }) { // The value is a hard coded text if (type == FTextTypeEnum.text) { - final v = (value?.replaceAll(' ', '').isNotEmpty ?? false) ? value : (defaultValue ?? '0'); + final v = (value?.replaceAll(' ', '').isNotEmpty ?? false) + ? value + : (defaultValue ?? '0'); final vT = valueTablet != null && valueTablet != '' ? (valueTablet?.replaceAll(' ', '').isNotEmpty ?? false) ? valueTablet @@ -437,7 +457,9 @@ class FTextTypeInput { : v ?? (defaultValue ?? '0'); if (resultType == ResultTypeEnum.string) { - final type = defaultValue != 'null' && defaultValue != null ? 'String' : 'String?'; + final type = defaultValue != 'null' && defaultValue != null + ? 'String' + : 'String?'; if (v == vT && v == vD) { return _calcStringType(v); } @@ -449,7 +471,8 @@ getValueForScreenType<$type>( desktop: ${_calcStringType(vD)}, )'''; } else if (resultType == ResultTypeEnum.int) { - final type = defaultValue != 'null' && defaultValue != null ? 'int' : 'int?'; + final type = + defaultValue != 'null' && defaultValue != null ? 'int' : 'int?'; if (v == vT && v == vD) { return int.tryParse('$v') != null ? '$v' : (defaultValue ?? '1'); } @@ -461,7 +484,9 @@ getValueForScreenType<$type>( desktop: ${int.tryParse('$vD') != null ? '$vD' : (defaultValue ?? '1')}, )"""; } else if (resultType == ResultTypeEnum.double) { - final type = defaultValue != 'null' && defaultValue != null ? 'double' : 'double?'; + final type = defaultValue != 'null' && defaultValue != null + ? 'double' + : 'double?'; if (v == vT && v == vD) { return double.tryParse('$v') != null ? '$v' : (defaultValue ?? '1'); } @@ -473,7 +498,8 @@ getValueForScreenType( desktop: ${double.tryParse('$vD') != null ? '$vD' : (defaultValue ?? '1')}, )"""; } else if (resultType == ResultTypeEnum.bool) { - final type = defaultValue != 'null' && defaultValue != null ? 'bool' : 'bool?'; + final type = + defaultValue != 'null' && defaultValue != null ? 'bool' : 'bool?'; if (v == vT && v == vD) { return '$v'.toLowerCase() == 'true' || '$v'.toLowerCase() == 'false' ? '$v'.toLowerCase() diff --git a/teta_widgets/lib/src/elements/nodes/node.dart b/teta_widgets/lib/src/elements/nodes/node.dart index 4a767e72..650b1d5d 100644 --- a/teta_widgets/lib/src/elements/nodes/node.dart +++ b/teta_widgets/lib/src/elements/nodes/node.dart @@ -97,6 +97,8 @@ abstract class CNode extends Equatable { child, children, body, + globalType, + intrinsicState, ]; /// Get all node controls. diff --git a/teta_widgets/lib/src/elements/widgets/responsive_condition.dart b/teta_widgets/lib/src/elements/widgets/responsive_condition.dart index aa908c34..b3bee6aa 100644 --- a/teta_widgets/lib/src/elements/widgets/responsive_condition.dart +++ b/teta_widgets/lib/src/elements/widgets/responsive_condition.dart @@ -30,7 +30,7 @@ class WResponsiveCondition extends StatelessWidget { @override Widget build(final BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (final context, final deviceInfostate) { // if (deviceInfostate.identifier.type == DeviceType.desktop) { // return visibleOnDesktop @@ -46,7 +46,7 @@ class WResponsiveCondition extends StatelessWidget { // ) // : const SizedBox(); // } - if (deviceInfostate.identifier.type == DeviceType.tablet) { + if (deviceInfostate.info.identifier.type == DeviceType.tablet) { return visibleOnTablet ? ChildConditionBuilder( ValueKey(state.toKey), From bda631d8e985df89e3d7b4f89b00faee18225687 Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Sun, 29 Jan 2023 19:42:01 +0100 Subject: [PATCH 21/23] feat(bloc version) --- teta_widgets/lib/src/elements/bodies/navigation/appbar.dart | 4 ++-- teta_widgets/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart index 8c373d13..265d792f 100644 --- a/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart +++ b/teta_widgets/lib/src/elements/bodies/navigation/appbar.dart @@ -62,9 +62,9 @@ class AppBarBody extends NodeBody { networkImage: '', onTap: () { sl.get().changeNode( - node: page.scaffold! as NDynamic, + node: page.scaffold as NDynamic, ); - page.scaffold!.body.attributes[DBKeys.showAppBar] = true; + page.scaffold.body.attributes[DBKeys.showAppBar] = true; }, ) ]; diff --git a/teta_widgets/pubspec.yaml b/teta_widgets/pubspec.yaml index 2e802d45..c1fe5290 100644 --- a/teta_widgets/pubspec.yaml +++ b/teta_widgets/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: mixpanel_analytics: 2.1.1 # Bloc - flutter_bloc: 8.1.1 + flutter_bloc: 7.3.3 equatable: 2.0.3 # Typography & Icons From 7aa15890b9a6e9a287657b83d5c3548107c7b388 Mon Sep 17 00:00:00 2001 From: Andrea Buttarelli on Mac Date: Mon, 30 Jan 2023 17:05:29 +0100 Subject: [PATCH 22/23] feat(tabs, deferred routing) --- .../src/elements/builder/node_selection.dart | 17 ++- .../src/elements/controls/atoms/action.dart | 22 +-- .../controls/atoms/action_element.dart | 19 ++- .../controls/atoms/apicalls_request.dart | 16 ++- .../controls/atoms/audio_controller.dart | 3 +- .../src/elements/controls/atoms/barcode.dart | 8 +- .../controls/atoms/border_radius.dart | 5 +- .../src/elements/controls/atoms/borders.dart | 3 +- .../controls/atoms/camera_controller.dart | 3 +- .../controls/atoms/cms_collections.dart | 16 ++- .../src/elements/controls/atoms/color.dart | 2 +- .../atoms/condition/value_of_condition.dart | 3 +- .../controls/atoms/cross_axis_alignment.dart | 5 +- .../src/elements/controls/atoms/db_map.dart | 3 +- .../elements/controls/atoms/fill/image.dart | 5 +- .../elements/controls/atoms/fill/linear.dart | 5 +- .../elements/controls/atoms/fill/radial.dart | 4 +- .../elements/controls/atoms/fill/solid.dart | 4 +- .../elements/controls/atoms/fill/style.dart | 3 +- .../controls/atoms/firebase/parameter.dart | 3 +- .../lib/src/elements/controls/atoms/flag.dart | 10 +- .../elements/controls/atoms/flat_text.dart | 3 +- .../elements/controls/atoms/font_size.dart | 2 +- .../elements/controls/atoms/font_style.dart | 3 +- .../controls/atoms/google_maps_control.dart | 3 +- .../atoms/google_maps_map_style_controls.dart | 6 +- .../controls/atoms/httpMethodControl.dart | 4 +- .../controls/atoms/main_axis_alignment.dart | 5 +- .../controls/atoms/main_axis_size.dart | 4 +- .../controls/atoms/map_controller.dart | 7 +- .../elements/controls/atoms/map_element.dart | 3 +- .../src/elements/controls/atoms/margins.dart | 3 +- .../lib/src/elements/controls/atoms/name.dart | 71 +++++----- .../controls/atoms/navigation/component.dart | 51 ++++--- .../lib/src/elements/controls/atoms/size.dart | 127 +++++++++++------- .../elements/controls/atoms/src_image.dart | 3 +- .../lib/src/elements/controls/atoms/text.dart | 3 +- .../elements/controls/atoms/text_align.dart | 3 +- .../controls/atoms/text_decoration.dart | 3 +- .../controls/atoms/text_direction.dart | 4 +- .../elements/controls/atoms/text_styles.dart | 19 ++- .../controls/atoms/video/video_url.dart | 32 ++--- .../controls/atoms/webview_controller.dart | 3 +- .../controls/current_song_controll.dart | 3 +- .../controls/google_maps_cubit_control.dart | 3 +- .../prefabs/sizes_prefab_control.dart | 12 +- .../controls/prefabs/text_prefab_control.dart | 34 ++--- .../lib/src/elements/controls/type.dart | 76 +++++++---- .../lib/src/elements/nodes/dynamic.dart | 3 - .../lib/src/elements/widgets/column.dart | 4 +- .../lib/src/elements/widgets/listview.dart | 4 +- .../lib/src/elements/widgets/row.dart | 4 +- .../lib/src/elements/widgets/scaffold.dart | 6 +- 53 files changed, 371 insertions(+), 299 deletions(-) diff --git a/teta_widgets/lib/src/elements/builder/node_selection.dart b/teta_widgets/lib/src/elements/builder/node_selection.dart index f12afdea..641be9e5 100644 --- a/teta_widgets/lib/src/elements/builder/node_selection.dart +++ b/teta_widgets/lib/src/elements/builder/node_selection.dart @@ -127,9 +127,9 @@ class _BodyState extends State<_Body> { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final onFocusNodes) { - return BlocBuilder( + return BlocBuilder( builder: (final context, final onHover) { return Stack( clipBehavior: Clip.none, @@ -141,10 +141,10 @@ class _BodyState extends State<_Body> { border: Border.all( color: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.state.node.nid, + element == widget.state.node.nid, ) != null || - onHover.nid == widget.state.node.nid + onHover == widget.state.node.nid ? primaryColor : Colors.transparent, style: (widget.state.forPlay) @@ -152,11 +152,11 @@ class _BodyState extends State<_Body> { : BorderStyle.solid, width: onFocusNodes.firstWhereOrNull( (final element) => - element.nid == widget.state.node.nid, + element == widget.state.node.nid, ) != null ? 1 - : onHover.nid == widget.state.node.nid + : onHover == widget.state.node.nid ? 2 : 0, ), @@ -164,11 +164,10 @@ class _BodyState extends State<_Body> { child: child, ), if (onFocusNodes.firstWhereOrNull( - (final element) => - element.nid == widget.state.node.nid, + (final element) => element == widget.state.node.nid, ) != null || - onHover.nid == widget.state.node.nid) + onHover == widget.state.node.nid) Transform.translate( offset: Offset( 0, diff --git a/teta_widgets/lib/src/elements/controls/atoms/action.dart b/teta_widgets/lib/src/elements/controls/atoms/action.dart index b60ec5b5..9a432b3d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action.dart @@ -64,19 +64,23 @@ class ActionControlState extends State { color: Colors.black, borderRadius: BorderRadius.circular(8), ), - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { + final nodeId = state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - for (final trigger - in state.first.intrinsicState.gestures.isNotEmpty - ? state.first.intrinsicState.gestures - : [ - ActionGesture.onTap, - ActionGesture.onLongPress, - ActionGesture.onDoubleTap - ]) + for (final trigger in node.intrinsicState.gestures.isNotEmpty + ? node.intrinsicState.gestures + : [ + ActionGesture.onTap, + ActionGesture.onLongPress, + ActionGesture.onDoubleTap + ]) Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart index 72d1c7f8..574b9315 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/action_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/action_element.dart @@ -250,7 +250,7 @@ class ActionElementControlState extends State { padding: const EdgeInsets.only(bottom: 8), child: SizedBox( width: double.maxFinite, - child: BlocListener>( + child: BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { delayController.text = @@ -301,7 +301,7 @@ class ActionElementControlState extends State { padding: const EdgeInsets.only(bottom: 8), child: SizedBox( width: double.maxFinite, - child: BlocListener>( + child: BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { loopController.text = @@ -1621,17 +1621,22 @@ class ActionElementControlState extends State { } }, ), - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { + final nodeId = state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); if ((widget.element.actionType == ActionType.state && widget.element.actionState == ActionState.changeWith && - !state.first.intrinsicState.gestures + !node.intrinsicState.gestures .contains(ActionGesture.onChange) && - (state.first.intrinsicState.type != NType.calendar && - state.first.intrinsicState.type != + (node.intrinsicState.type != NType.calendar && + node.intrinsicState.type != NType.cupertinoSegmentedControl && - state.first.intrinsicState.type != + node.intrinsicState.type != NType.cupertinoSwitch)) || (widget.element.actionType == ActionType.navigation && widget.element.actionNavigation == diff --git a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart index ce687e7a..c7e4bf14 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/apicalls_request.dart @@ -76,9 +76,14 @@ class ApiCallsRequestControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { if (state.length != 1) return const SizedBox(); + final nodeId = state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -100,7 +105,7 @@ class ApiCallsRequestControlState extends State { (final element) => element == (widget.requestName ?? - (state.first.body.attributes[DBKeys.requestName] + (node.body.attributes[DBKeys.requestName] as FTextTypeInput?) ?.value), ), @@ -121,11 +126,10 @@ class ApiCallsRequestControlState extends State { final nw = requestNames.firstWhereOrNull( (final element) => element == dropdown, ); - if (state.first.body.attributes[DBKeys.requestName] != - null && - state.first.body.attributes[DBKeys.requestName] + if (node.body.attributes[DBKeys.requestName] != null && + node.body.attributes[DBKeys.requestName] is FTextTypeInput) { - (state.first.body.attributes[DBKeys.requestName] + (node.body.attributes[DBKeys.requestName] as FTextTypeInput) .value = nw; } diff --git a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart index a0da42ef..66951b33 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/audio_controller.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class AudioControllerControl extends StatefulWidget { const AudioControllerControl({ @@ -45,7 +44,7 @@ class AudioControllerControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/barcode.dart b/teta_widgets/lib/src/elements/controls/atoms/barcode.dart index 4bea985f..a3c2ab51 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/barcode.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/barcode.dart @@ -31,20 +31,20 @@ class BarcodeControlState extends State { @override void initState() { - nodeId = BlocProvider.of(context).state.first.nid; + nodeId = BlocProvider.of(context).state.first; super.initState(); } @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { + if (state.first != nodeId) { setState(() { isUpdated = true; }); - nodeId = state.first.nid; + nodeId = state.first; } } }, diff --git a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart index 120fa7f1..8f59f681 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/border_radius.dart @@ -12,7 +12,6 @@ import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/border_radius.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class BorderRadiusControl extends StatefulWidget { const BorderRadiusControl({ @@ -62,7 +61,7 @@ class BorderRadiusControlState extends State { }, child: BlocBuilder( builder: (final context, final device) => - BlocListener>( + BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { if (device.info.identifier.type == DeviceType.phone) { @@ -77,7 +76,7 @@ class BorderRadiusControlState extends State { } } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/borders.dart b/teta_widgets/lib/src/elements/controls/atoms/borders.dart index 9514e6d1..c6052be9 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/borders.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/borders.dart @@ -15,7 +15,6 @@ import 'package:teta_widgets/src/elements/features/border.dart'; import 'package:teta_widgets/src/elements/features/border_style.dart'; import 'package:teta_widgets/src/elements/features/fill.dart'; import 'package:teta_widgets/src/elements/features/margins.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class BordersControl extends StatefulWidget { const BordersControl({ @@ -42,7 +41,7 @@ class BordersControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart index 96b9c49f..2f56c602 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/camera_controller.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class CameraControllerControl extends StatefulWidget { const CameraControllerControl({ @@ -45,7 +44,7 @@ class CameraControllerControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { controller.text = controller.text = widget.value.value ?? ''; diff --git a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart index 20b916f2..38fc5d35 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cms_collections.dart @@ -37,7 +37,7 @@ class CMSCollectionControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -62,12 +62,17 @@ class CMSCollectionControlState extends State { child: CircularProgressIndicator(), ); } + final nodeId = state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); dropdown = snapshot.data! .firstWhereOrNull( (final element) => element.id == (widget.collectionId ?? - (state.first.body.attributes[DBKeys.cmsCollection] + (node.body.attributes[DBKeys.cmsCollection] as FTextTypeInput?) ?.value), ) @@ -93,11 +98,10 @@ class CMSCollectionControlState extends State { (final element) => element.name == dropdown, ) ?.id; - if (state.first.body.attributes[DBKeys.cmsCollection] != - null && - state.first.body.attributes[DBKeys.cmsCollection] + if (node.body.attributes[DBKeys.cmsCollection] != null && + node.body.attributes[DBKeys.cmsCollection] is FTextTypeInput) { - (state.first.body.attributes[DBKeys.cmsCollection] + (node.body.attributes[DBKeys.cmsCollection] as FTextTypeInput) .value = nw; } diff --git a/teta_widgets/lib/src/elements/controls/atoms/color.dart b/teta_widgets/lib/src/elements/controls/atoms/color.dart index db159680..143166f6 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/color.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/color.dart @@ -52,7 +52,7 @@ class SingleColorControlState extends State { controller.text = tempColor; isUpdated = false; }*/ - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { //updateState(state); return Row( diff --git a/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart b/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart index 512b869a..250aef50 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/condition/value_of_condition.dart @@ -9,7 +9,6 @@ import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class ValueOfConditionControl extends StatefulWidget { /// Constructor @@ -42,7 +41,7 @@ class ValueOfConditionControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { controller.text = widget.valueOfCond.value ?? ''; }, diff --git a/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart b/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart index 3d043112..8027c878 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/cross_axis_alignment.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/cross_axis_alignment.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class CrossAxisAlignmentControls extends StatefulWidget { const CrossAxisAlignmentControls({ @@ -37,7 +36,7 @@ class CrossAxisAlignmentControlsState @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { setState(() { @@ -45,7 +44,7 @@ class CrossAxisAlignmentControlsState }); } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/db_map.dart b/teta_widgets/lib/src/elements/controls/atoms/db_map.dart index 56cd73c6..63eb3c8c 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/db_map.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/db_map.dart @@ -10,7 +10,6 @@ import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/map_element.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class DBMapControl extends StatefulWidget { const DBMapControl({ @@ -37,7 +36,7 @@ class DBMapControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) {} }, diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart index abb366c3..a4da634e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/image.dart @@ -10,7 +10,6 @@ import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/box_fit.dart'; import 'package:teta_widgets/src/elements/features/features.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class ImageFillControl extends StatefulWidget { /// Constructor @@ -44,13 +43,13 @@ class ImageFillControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { controller.text = widget.fill.levels!.first.color; } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { //updateState(state); return Column( diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart index b5995e02..4b8ef743 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/linear.dart @@ -13,7 +13,6 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/fill/widgets/gradient_swiper_control.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/features.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class LinearFillControl extends StatefulWidget { /// Constructor @@ -47,7 +46,7 @@ class ColorControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -503,7 +502,7 @@ class FillElementState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { editingController.text = widget.element.color; diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart index bab1ddce..44a6b7e3 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/radial.dart @@ -48,7 +48,7 @@ class ColorControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { //updateState(state); return Column( @@ -364,7 +364,7 @@ class FillElementState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { editingController.text = widget.element.color; diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart index c5862046..9271f88d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/solid.dart @@ -68,7 +68,7 @@ class SolidFillControlState extends State { }*/ return Column( children: [ - BlocListener>( + BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { if (widget.color != null) { @@ -83,7 +83,7 @@ class SolidFillControlState extends State { } } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return TContainer( padding: const EdgeInsets.symmetric(horizontal: 8), diff --git a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart index 19932242..ea700900 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/fill/style.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/features.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; //ignore: must_be_immutable class StyleFillControl extends StatefulWidget { @@ -32,7 +31,7 @@ class StyleFillControl extends StatefulWidget { class StyleFillControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { //updateState(state); return BlocBuilder>( diff --git a/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart b/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart index cc9715c6..766ded81 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/firebase/parameter.dart @@ -9,7 +9,6 @@ import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class FirestoreParameterControl extends StatefulWidget { const FirestoreParameterControl({ @@ -45,7 +44,7 @@ class ParameterState extends State { @override Widget build(final BuildContext context) { //controller.text = widget.value!.value ?? ''; - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { controller.text = widget.value.value ?? ''; diff --git a/teta_widgets/lib/src/elements/controls/atoms/flag.dart b/teta_widgets/lib/src/elements/controls/atoms/flag.dart index 3e3ea48b..c94b1a3d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/flag.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/flag.dart @@ -39,10 +39,12 @@ class FlagControlState extends State { switchOn = value; }); if (widget.keyValue != null) { - final nodes = BlocProvider.of(context).state; - if (nodes.isNotEmpty) { - nodes.first.body.attributes[widget.keyValue!] = value; - } + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + node.body.attributes[widget.keyValue!] = value; } widget.callBack(value, widget.value); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart b/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart index 5513602b..9dc2262a 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/flat_text.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/node.dart'; class FlatTextControl extends StatefulWidget { const FlatTextControl({ @@ -37,7 +36,7 @@ class FlatTextControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { controller!.text = widget.value; diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart index bfca41ee..3be415dc 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_size.dart @@ -68,7 +68,7 @@ class FontSizeState extends State { }, child: BlocBuilder( builder: (final context, final device) => - BlocListener>( + BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { controller.text = '${widget.textStyle.fontSize!.get(context)}'; diff --git a/teta_widgets/lib/src/elements/controls/atoms/font_style.dart b/teta_widgets/lib/src/elements/controls/atoms/font_style.dart index 4a776c30..9a32404d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/font_style.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/font_style.dart @@ -10,7 +10,6 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/widgets/selection_tab.dart'; import 'package:teta_widgets/src/elements/features/font_style.dart'; import 'package:teta_widgets/src/elements/features/text_style.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class FontStyleControls extends StatefulWidget { const FontStyleControls({ @@ -34,7 +33,7 @@ class TextStyleControlsState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart index ce209b78..ec3b21e7 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_control.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class GoogleMapsControl extends StatefulWidget { const GoogleMapsControl({ @@ -45,7 +44,7 @@ class GoogleMapsControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart index 317603d1..2c69ba0b 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/google_maps_map_style_controls.dart @@ -37,13 +37,13 @@ class GoogleMapsMapStyleControlsState @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { dropdown = widget.mapStyle.getString; } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -96,7 +96,7 @@ class GoogleMapsMapStyleControlsState } DropdownCustomMenuItem buildMapStyleMenuItem( - final String value, final String asset) => + final String value, final String asset,) => DropdownCustomMenuItem( value: value, child: Row( diff --git a/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart b/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart index dba6417a..2c6258b9 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/httpMethodControl.dart @@ -35,13 +35,13 @@ class _HttpMethodControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { dropdown = widget.httpMethod; } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart b/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart index f551adea..bd897892 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/main_axis_alignment.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/main_axis_alignment.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class MainAxisAlignmentControls extends StatefulWidget { const MainAxisAlignmentControls({ @@ -36,7 +35,7 @@ class MainAxisAlignmentControlsState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { setState(() { @@ -44,7 +43,7 @@ class MainAxisAlignmentControlsState extends State { }); } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart b/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart index 10900302..defb0618 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/main_axis_size.dart @@ -34,7 +34,7 @@ class MainAxisSizeControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { setState(() { @@ -42,7 +42,7 @@ class MainAxisSizeControlState extends State { }); } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart index 3304a728..a1f0737f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/map_controller.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class MapControllerControl extends StatefulWidget { const MapControllerControl({ @@ -49,13 +48,13 @@ class MapControllerControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { - if (state.first.nid != nodeId) { + if (state.first != nodeId) { if (mounted) { - nodeId = state.first.nid; + nodeId = state.first; controller.text = controller.text = widget.value.value ?? ''; } } diff --git a/teta_widgets/lib/src/elements/controls/atoms/map_element.dart b/teta_widgets/lib/src/elements/controls/atoms/map_element.dart index 09ddb4fc..b08d426d 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/map_element.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/map_element.dart @@ -9,7 +9,6 @@ import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class MapElementControl extends StatefulWidget { const MapElementControl({ @@ -37,7 +36,7 @@ class MapElementControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { setState(() { diff --git a/teta_widgets/lib/src/elements/controls/atoms/margins.dart b/teta_widgets/lib/src/elements/controls/atoms/margins.dart index a67d4d96..76d0a7e9 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/margins.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/margins.dart @@ -15,7 +15,6 @@ import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/margins.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class Margins extends StatefulWidget { const Margins({ @@ -94,7 +93,7 @@ class MarginsState extends State { }, child: BlocBuilder( builder: (final context, final device) => - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { if (mounted) { diff --git a/teta_widgets/lib/src/elements/controls/atoms/name.dart b/teta_widgets/lib/src/elements/controls/atoms/name.dart index 2f6acbfd..b63901e1 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/name.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/name.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: -import 'package:teta_widgets/src/elements/nodes/node.dart'; class NameControl extends StatefulWidget { const NameControl({ @@ -32,19 +31,21 @@ class NameState extends State { @override void initState() { - final nodes = context.read().state; - if (nodes.length == 1) { - final node = nodes.first; - controller.text = widget.title == 'Description' - ? nodes.first.description ?? '' - : nodes.first.name ?? nodes.first.intrinsicState.displayName; - } + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + controller.text = widget.title == 'Description' + ? node.description ?? '' + : node.name ?? node.intrinsicState.displayName; + super.initState(); } @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -63,19 +64,21 @@ class NameState extends State { }); }, onSubmitted: (final text) { - final nodes = context.read().state; - if (nodes.length == 1) { - final node = nodes.first; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + widget.title == 'Description' + ? node.description = text + : node.name = text; + widget.callBack( + text, widget.title == 'Description' - ? node.description = text - : node.name = text; - widget.callBack( - text, - widget.title == 'Description' - ? node.description ?? '' - : node.name ?? node.intrinsicState.displayName, - ); - } + ? node.description ?? '' + : node.name ?? node.intrinsicState.displayName, + ); + setState(() { isLoading = false; }); @@ -87,19 +90,21 @@ class NameState extends State { child: CButton( label: 'Submit', callback: () { - final nodes = context.read().state; - if (nodes.length == 1) { - final node = nodes.first; + final nodeId = + BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + widget.title == 'Description' + ? node.description = controller.text + : node.name = controller.text; + widget.callBack( + controller.text, widget.title == 'Description' - ? node.description = controller.text - : node.name = controller.text; - widget.callBack( - controller.text, - widget.title == 'Description' - ? node.description ?? '' - : node.name ?? node.intrinsicState.displayName, - ); - } + ? node.description ?? '' + : node.name ?? node.intrinsicState.displayName, + ); setState(() { isLoading = false; diff --git a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart index 677b27dc..b3413b07 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/navigation/component.dart @@ -38,9 +38,12 @@ class ComponentControlState extends State { void initState() { super.initState(); final pages = context.read().state; - final focusBloc = context.read().state; - final name = - focusBloc.first.body.attributes[DBKeys.componentName] as String? ?? ''; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + final name = node.body.attributes[DBKeys.componentName] as String? ?? ''; components = pages.where((final element) => !element.isPage).toList(); try { if (components.indexWhere((final element) => element.name == name) != @@ -49,8 +52,8 @@ class ComponentControlState extends State { components.firstWhere((final element) => element.name == name); dropdown = pageObject?.name; - if (focusBloc.first.body.attributes[DBKeys.paramsToSend] != null) { - map = focusBloc.first.body.attributes[DBKeys.paramsToSend] + if (node.body.attributes[DBKeys.paramsToSend] != null) { + map = node.body.attributes[DBKeys.paramsToSend] as Map? ?? {}; } @@ -83,15 +86,18 @@ class ComponentControlState extends State { value: dropdown, items: components.map((final e) => e.name).toList(), onChange: (final String? newValue) { - final focusBloc = context.read().state; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); if (newValue != null) { - final old = focusBloc - .first.body.attributes[DBKeys.componentName] as String?; + final old = + node.body.attributes[DBKeys.componentName] as String?; pageObject = components .firstWhere((final element) => element.name == newValue); - focusBloc.first.body.attributes[DBKeys.componentName] = - pageObject!.name; + node.body.attributes[DBKeys.componentName] = pageObject!.name; setState(() { dropdown = newValue; }); @@ -128,10 +134,21 @@ class ComponentControlState extends State { page: state.page, map: map, callBackParameters: (final map) { - final node = - context.read().state; - node.first.body - .attributes[DBKeys.paramsToSend] = map; + final nodeId = + BlocProvider.of(context) + .state + .first; + final node = (context + .read() + .state as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => + element.nid == nodeId, + ); + node.body.attributes[DBKeys.paramsToSend] = + map; widget.callBackParameters(map); }, ), @@ -291,11 +308,11 @@ class ElementState extends State { ), const Gap(Grid.small), if (dropdownDataset != null && dropdownDataset == 'Text') - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { - if (controller == null || nodeId != state.first.nid) { - nodeId = state.first.nid; + if (controller == null || nodeId != state.first) { + nodeId = state.first; controller = TextEditingController() ..text = widget.map[widget.variable.id] != null && widget.map[widget.variable.id]?['label'] != diff --git a/teta_widgets/lib/src/elements/controls/atoms/size.dart b/teta_widgets/lib/src/elements/controls/atoms/size.dart index 83ffcd07..6b18b229 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/size.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/size.dart @@ -11,7 +11,6 @@ import 'package:teta_core/src/design_system/textfield/minitextfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/features.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class SizeControl extends StatefulWidget { const SizeControl({ @@ -78,7 +77,7 @@ class SizeControlsState extends State { }, child: BlocBuilder( builder: (final context, final device) => - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { if (mounted) { @@ -155,12 +154,18 @@ class SizeControlsState extends State { final old = FSize.fromJson(widget.size.toJson()); value.replaceAll('%', ''); szs.updateSize(value, context); - final nodes = - BlocProvider.of(context).state; - if (nodes.length == 1) { - nodes.first.body.attributes[widget.keyAttr] = - szs; - } + final nodeId = BlocProvider.of(context) + .state + .first; + final node = (context.read().state + as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => element.nid == nodeId, + ); + + node.body.attributes[widget.keyAttr] = szs; widget.callBack(szs.toJson(), old.toJson()); }, value: flag, @@ -195,13 +200,20 @@ class SizeControlsState extends State { widget.size .updateUnit(SizeUnit.pixel, context); final szs = widget.size; - final nodes = - BlocProvider.of(context).state; - if (nodes.length == 1) { - nodes.first.body - .attributes[widget.keyAttr] = szs; - widget.callBack(szs.toJson(), old.toJson()); - } + final nodeId = + BlocProvider.of(context) + .state + .first; + final node = (context.read().state + as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => + element.nid == nodeId, + ); + node.body.attributes[widget.keyAttr] = szs; + widget.callBack(szs.toJson(), old.toJson()); }, child: unitIcon( unit: SizeUnit.pixel, @@ -215,13 +227,20 @@ class SizeControlsState extends State { widget.size .updateUnit(SizeUnit.percent, context); final szs = widget.size; - final nodes = - BlocProvider.of(context).state; - if (nodes.length == 1) { - nodes.first.body - .attributes[widget.keyAttr] = szs; - widget.callBack(szs.toJson(), old.toJson()); - } + final nodeId = + BlocProvider.of(context) + .state + .first; + final node = (context.read().state + as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => + element.nid == nodeId, + ); + node.body.attributes[widget.keyAttr] = szs; + widget.callBack(szs.toJson(), old.toJson()); }, child: unitIcon( unit: SizeUnit.percent, @@ -275,17 +294,25 @@ class SizeControlsState extends State { FSize.fromJson(widget.size.toJson()); value.replaceAll('%', ''); szs.updateSize(value, context); - final nodes = + final nodeId = BlocProvider.of(context) - .state; - if (nodes.length == 1) { - nodes.first.body - .attributes[widget.keyAttr] = szs; - widget.callBack( - szs.toJson(), - old.toJson(), - ); - } + .state + .first; + final node = (context + .read() + .state as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => + element.nid == nodeId, + ); + node.body.attributes[widget.keyAttr] = + szs; + widget.callBack( + szs.toJson(), + old.toJson(), + ); }, ), ), @@ -310,23 +337,29 @@ class SizeControlsState extends State { : '100%', context, ); - final nodes = + final nodeId = BlocProvider.of( context, - ).state; - if (nodes.length == 1) { - nodes.first.body.attributes[ - widget.keyAttr] = widget.size; - widget.callBack( - widget.size.toJson(), - old.toJson(), - ); - controller.text = - widget.size.unit == - SizeUnit.pixel - ? 'max' - : '100%'; - } + ).state.first; + final node = (context + .read() + .state as PageLoaded) + .page + .flatList + .firstWhere( + (final element) => + element.nid == nodeId, + ); + node.body.attributes[widget.keyAttr] = + widget.size; + widget.callBack( + widget.size.toJson(), + old.toJson(), + ); + controller.text = + widget.size.unit == SizeUnit.pixel + ? 'max' + : '100%'; }, child: maxIcon( unit: widget.size.unit, diff --git a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart index 66ae5c77..2d15a3de 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/src_image.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/src_image.dart @@ -11,7 +11,6 @@ import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class SrcImageControl extends StatefulWidget { const SrcImageControl({ @@ -74,7 +73,7 @@ class SrcImageControlState extends State { @override Widget build(final BuildContext context) { final pageState = context.watch().state as PageLoaded; - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { controller.text = widget.image.value ?? ''; diff --git a/teta_widgets/lib/src/elements/controls/atoms/text.dart b/teta_widgets/lib/src/elements/controls/atoms/text.dart index d64f18c6..b98da465 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text.dart @@ -17,7 +17,6 @@ import 'package:teta_core/src/design_system/textfield/textfield.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextControl extends StatefulWidget { const TextControl({ @@ -89,7 +88,7 @@ class PaddingsState extends State { }, child: BlocBuilder( builder: (final context, final device) => - BlocBuilder>( + BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_align.dart b/teta_widgets/lib/src/elements/controls/atoms/text_align.dart index dc086814..4083a839 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_align.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_align.dart @@ -10,7 +10,6 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/widgets/selection_tab.dart'; import 'package:teta_widgets/src/elements/features/features.dart'; import 'package:teta_widgets/src/elements/features/text_style.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextAlignControls extends StatefulWidget { const TextAlignControls({ @@ -39,7 +38,7 @@ class TextAlignControlsState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart b/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart index 0d63d707..6d134814 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_decoration.dart @@ -10,7 +10,6 @@ import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/elements/controls/atoms/widgets/selection_tab.dart'; import 'package:teta_widgets/src/elements/features/text_decoration.dart'; import 'package:teta_widgets/src/elements/features/text_style.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class TextDecorationControl extends StatelessWidget { const TextDecorationControl({ @@ -24,7 +23,7 @@ class TextDecorationControl extends StatelessWidget { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart b/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart index a01564d6..6483f4ed 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_direction.dart @@ -34,7 +34,7 @@ class TextDirectionControlState extends State { @override Widget build(final BuildContext context) { - return BlocListener>( + return BlocListener>( listener: (final context, final state) { if (state.isNotEmpty) { setState(() { @@ -42,7 +42,7 @@ class TextDirectionControlState extends State { }); } }, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final state) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart index 9b6f9d91..732d876e 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/text_styles.dart @@ -53,7 +53,7 @@ class TextStylesControlState extends State { ), Row( children: [ - if (widget.textStyle.textStyleModel == null) + if (textStyleModel == null) GestureDetector( onTap: () => showPicker( context, @@ -91,16 +91,19 @@ class TextStylesControlState extends State { ), BounceSmall( onTap: () { - if (widget.textStyle.textStyleModel == null) { + if (textStyleModel == null) { /*newTextStylePicker( context, BlocProvider.of(context));*/ BlocProvider.of(context) .changePanel(PanelsEnum.assets); } else { - final old = widget.textStyle.textStyleModel; + final old = textStyleModel; //String txtSM = widget.node.textStyleModel; //txtSM = null; widget.callBack(null, false, old); + setState(() { + textStyleModel = null; + }); } }, child: HoverWidget( @@ -112,9 +115,7 @@ class TextStylesControlState extends State { ), ), child: Icon( - (widget.textStyle.textStyleModel == null) - ? Icons.add - : Icons.remove, + (textStyleModel == null) ? Icons.add : Icons.remove, size: 24, color: Colors.white, ), @@ -128,9 +129,7 @@ class TextStylesControlState extends State { ), ), child: Icon( - (widget.textStyle.textStyleModel == null) - ? Icons.add - : Icons.remove, + (textStyleModel == null) ? Icons.add : Icons.remove, size: 24, color: Colors.white, ), @@ -141,7 +140,7 @@ class TextStylesControlState extends State { ), ], ), - if (widget.textStyle.textStyleModel != null) + if (textStyleModel != null) CButton( label: textStyleModel, callback: () { diff --git a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart index b66d7e59..aecb71d7 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/video/video_url.dart @@ -56,22 +56,24 @@ class PaddingsState extends State { null, context, ); - final nodes = BlocProvider.of(context).state; - if (nodes.isNotEmpty) { - controllerVideo = YoutubePlayerController( - initialVideoId: urlState!, - params: YoutubePlayerParams( - startAt: Duration( - seconds: nodes.first.body.attributes[DBKeys.startAt] as int, - ), - showControls: - nodes.first.body.attributes[DBKeys.showControls] as bool, - showFullscreenButton: - nodes.first.body.attributes[DBKeys.isFullWidth] as bool, - mute: true, + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); + + controllerVideo = YoutubePlayerController( + initialVideoId: urlState!, + params: YoutubePlayerParams( + startAt: Duration( + seconds: node.body.attributes[DBKeys.startAt] as int, ), - ); - } + showControls: node.body.attributes[DBKeys.showControls] as bool, + showFullscreenButton: node.body.attributes[DBKeys.isFullWidth] as bool, + mute: true, + ), + ); + super.initState(); } diff --git a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart index eb823ebf..5f5f1a4f 100644 --- a/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart +++ b/teta_widgets/lib/src/elements/controls/atoms/webview_controller.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class WebViewControllerControl extends StatefulWidget { const WebViewControllerControl({ @@ -46,7 +45,7 @@ class WebViewControllerControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { if (state.isNotEmpty) { controller.text = controller.text = widget.value.value ?? ''; diff --git a/teta_widgets/lib/src/elements/controls/current_song_controll.dart b/teta_widgets/lib/src/elements/controls/current_song_controll.dart index 88eddbe4..4e3f4764 100644 --- a/teta_widgets/lib/src/elements/controls/current_song_controll.dart +++ b/teta_widgets/lib/src/elements/controls/current_song_controll.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class CurrentSongControl extends StatefulWidget { const CurrentSongControl({ @@ -45,7 +44,7 @@ class CurrentSongControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { diff --git a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart index bc09f527..eb699ac2 100644 --- a/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart +++ b/teta_widgets/lib/src/elements/controls/google_maps_cubit_control.dart @@ -8,7 +8,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; // Project imports: import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -import 'package:teta_widgets/src/elements/nodes/node.dart'; class GoogleMapsCubitControl extends StatefulWidget { const GoogleMapsCubitControl({ @@ -45,7 +44,7 @@ class GoogleMapsCubitControlState extends State { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( buildWhen: (final previous, final current) => current != previous, builder: (final context, final state) { if (state.isNotEmpty) { diff --git a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart index 2c47bf77..d59d0109 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/sizes_prefab_control.dart @@ -37,7 +37,11 @@ class SizesPrefabControl extends StatelessWidget { keyAttr: DBKeys.width, isFromSizesPrefab: true, callBack: (final value, final old) { - final node = BlocProvider.of(context).state.first; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); ControlBuilder.toDB( node, context, @@ -54,7 +58,11 @@ class SizesPrefabControl extends StatelessWidget { keyAttr: DBKeys.height, isFromSizesPrefab: true, callBack: (final value, final old) { - final node = BlocProvider.of(context).state.first; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); ControlBuilder.toDB( node, context, diff --git a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart index 00f5e7bf..52cf523f 100644 --- a/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart +++ b/teta_widgets/lib/src/elements/controls/prefabs/text_prefab_control.dart @@ -18,11 +18,7 @@ import 'package:teta_widgets/src/elements/controls/atoms/text_align.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text_decoration.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text_direction.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text_styles.dart'; -import 'package:teta_widgets/src/elements/controls/type.dart'; -import 'package:teta_widgets/src/elements/features/fill.dart'; -import 'package:teta_widgets/src/elements/features/text_style.dart'; import 'package:teta_widgets/src/elements/index.dart'; -import 'package:teta_widgets/src/elements/nodes/enum.dart'; class TextPrefabControl extends StatelessWidget { const TextPrefabControl({ @@ -38,8 +34,12 @@ class TextPrefabControl extends StatelessWidget { @override Widget build(final BuildContext context) { - return BlocBuilder>( + return BlocBuilder>( builder: (final context, final state) { + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == state.first); return Column( children: [ TextStylesControl( @@ -49,14 +49,14 @@ class TextPrefabControl extends StatelessWidget { if (flag) { sl.get().assignTextStyle( styleName: textStyleModel, - node: state.first, + node: node, keyValue: keyValue, ); } final old = textStyle; textStyle.textStyleModel = textStyleModel; ControlBuilder.toDB( - state.first, + node, context, keyValue, textStyle.toJson(), @@ -68,8 +68,8 @@ class TextPrefabControl extends StatelessWidget { padding: EdgeInsets.only(top: 16), child: Divider(height: 1, color: Colors.white38), ), - if (!(state.first.globalType == NType.text) || - state.first.body.attributes[keyValue]?.textStyleModel == null) + if (!(node.globalType == NType.text) || + node.body.attributes[keyValue]?.textStyleModel == null) Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -85,7 +85,7 @@ class TextPrefabControl extends StatelessWidget { textStyle: textStyle, callBack: (final value, final old) { ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -99,7 +99,7 @@ class TextPrefabControl extends StatelessWidget { child: FontFamilyControl( textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -112,7 +112,7 @@ class TextPrefabControl extends StatelessWidget { child: FontWeightControl( textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -129,7 +129,7 @@ class TextPrefabControl extends StatelessWidget { textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -152,7 +152,7 @@ class TextPrefabControl extends StatelessWidget { child: TextAlignControls( textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -165,7 +165,7 @@ class TextPrefabControl extends StatelessWidget { child: TextDecorationControl( textStyle: textStyle, callBack: (final value, final old) => ControlBuilder.toDB( - state.first, + node, context, keyValue, value, @@ -183,7 +183,7 @@ class TextPrefabControl extends StatelessWidget { final old = FTextStyle.fromJson(textStyle.toJson()); textStyle.textDirection = dir; ControlBuilder.toDB( - state.first, + node, context, keyValue, textStyle.toJson(), @@ -203,7 +203,7 @@ class TextPrefabControl extends StatelessWidget { final old = FTextStyle.fromJson(textStyle.toJson()); textStyle.fill = color; ControlBuilder.toDB( - state.first, + node, context, keyValue, textStyle.toJson(), diff --git a/teta_widgets/lib/src/elements/controls/type.dart b/teta_widgets/lib/src/elements/controls/type.dart index 766943a6..316924ba 100644 --- a/teta_widgets/lib/src/elements/controls/type.dart +++ b/teta_widgets/lib/src/elements/controls/type.dart @@ -9,7 +9,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_repositories/src/node_repository.dart'; import 'package:teta_repositories/src/project_repository.dart'; -import 'package:teta_repositories/src/project_styles_repository.dart'; import 'package:teta_repositories/teta_repositories.dart'; // Project imports: import 'package:teta_widgets/src/elements/controls/atoms/action.dart'; @@ -41,10 +40,10 @@ import 'package:teta_widgets/src/elements/controls/atoms/map_controller.dart'; import 'package:teta_widgets/src/elements/controls/atoms/margins.dart'; import 'package:teta_widgets/src/elements/controls/atoms/navigation/component.dart'; import 'package:teta_widgets/src/elements/controls/atoms/page_params.dart'; +import 'package:teta_widgets/src/elements/controls/atoms/page_states.dart'; import 'package:teta_widgets/src/elements/controls/atoms/physics.dart'; import 'package:teta_widgets/src/elements/controls/atoms/size.dart'; import 'package:teta_widgets/src/elements/controls/atoms/src_image.dart'; -import 'package:teta_widgets/src/elements/controls/atoms/page_states.dart'; import 'package:teta_widgets/src/elements/controls/atoms/text.dart'; import 'package:teta_widgets/src/elements/controls/atoms/webview_controller.dart'; import 'package:teta_widgets/src/elements/controls/current_song_controll.dart'; @@ -55,7 +54,6 @@ import 'package:teta_widgets/src/elements/controls/prefabs/text_prefab_control.d import 'package:teta_widgets/src/elements/features/google_maps_map_style.dart'; import 'package:teta_widgets/src/elements/features/physic.dart'; import 'package:teta_widgets/src/elements/index.dart'; -import 'package:very_good_analysis/very_good_analysis.dart'; enum ControlType { /// Made for colors, gradients and images. @@ -189,7 +187,7 @@ class ControlBuilder { ) async { final prj = BlocProvider.of(context).state!; sl.get().track(prj.id); - sl.get().changeNode( + await sl.get().changeNode( node: node as NDynamic, ); } @@ -246,18 +244,22 @@ class ControlBuilder { required final BuildContext context, required final ControlObject control, }) { - final node = BlocProvider.of(context).state.first; + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); if (control.type == ControlType.barcode) { return BarcodeControl( key: ValueKey( - '${node.nid} ${(control.value as FTextTypeInput).value}', + '$nodeId ${(control.value as FTextTypeInput).value}', ), value: control.value.runtimeType == FTextTypeInput ? control.value as FTextTypeInput : FTextTypeInput(), callBack: (final value, final old) { ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value.toJson(), @@ -873,11 +875,16 @@ class ControlBuilder { required final BuildContext context, required final BoxFitControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return BoxFitControl( - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), boxFit: control.value, callBack: (final value, final old) => ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value, @@ -891,21 +898,22 @@ class ControlBuilder { required final BuildContext context, required final FlagControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return descriptionControlWidget( description: control.description, control: FlagControl( - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), title: control.title, keyValue: control.key, value: control.value as bool, callBack: (final value, final old) { - BlocProvider.of(context) - .state - .first - .body - .attributes[control.key] = value; + node.body.attributes[control.key] = value; ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value, @@ -924,23 +932,24 @@ class ControlBuilder { required final BuildContext context, required final FillControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return FillControl( title: control.title.isNotEmpty ? control.title : 'Fill', - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), isImageEnabled: isImageEnabled, isNoneEnabled: isNoneEnabled, type: isOnlySolid ? FillTypeControlType.onlySolid : FillTypeControlType.all, fill: control.value, callBack: (final value, final styled, final old) { - BlocProvider.of(context) - .state - .first - .body - .attributes[control.key] = value; + node.body.attributes[control.key] = value; if (!styled) { ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value.toJson(), @@ -964,12 +973,17 @@ class ControlBuilder { required final BuildContext context, required final FirestorePathControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return FirestorePathControl( - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), path: control.value, isForAddData: true, callBack: (final value, final old) => ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value.toJson(), @@ -985,15 +999,20 @@ class ControlBuilder { required final BuildContext context, required final SizeControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; + final node = (context.read().state as PageLoaded) + .page + .flatList + .firstWhere((final element) => element.nid == nodeId); return SizeControl( - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), isWidth: control.isWidth, title: control.title, size: control.value, isFromSizesPrefab: false, keyAttr: control.key, callBack: (final value, final old) => ControlBuilder.toDB( - BlocProvider.of(context).state.first, + node, context, control.key, value, @@ -1009,8 +1028,9 @@ class ControlBuilder { required final BuildContext context, required final SizesControlObject control, }) { + final nodeId = BlocProvider.of(context).state.first; return SizesPrefabControl( - key: ValueKey('${BlocProvider.of(context).state.first.nid}'), + key: ValueKey('$nodeId'), values: control.values, ); } diff --git a/teta_widgets/lib/src/elements/nodes/dynamic.dart b/teta_widgets/lib/src/elements/nodes/dynamic.dart index fc50d1a9..b7c38901 100644 --- a/teta_widgets/lib/src/elements/nodes/dynamic.dart +++ b/teta_widgets/lib/src/elements/nodes/dynamic.dart @@ -9,11 +9,8 @@ import 'package:flutter/material.dart'; import 'package:teta_core/teta_core.dart'; import 'package:teta_widgets/src/core/teta_widget/index.dart'; // Project imports: -import 'package:teta_widgets/src/elements/controls/control_model.dart'; -import 'package:teta_widgets/src/elements/controls/key_constants.dart'; import 'package:teta_widgets/src/elements/index.dart'; import 'package:teta_widgets/src/elements/intrinsic_states/class.dart'; -import 'package:teta_widgets/src/elements/nodes/children_enum.dart'; import 'package:teta_widgets/src/elements/nodes/node_body.dart'; // ignore: must_be_immutable diff --git a/teta_widgets/lib/src/elements/widgets/column.dart b/teta_widgets/lib/src/elements/widgets/column.dart index 34d0fbd6..46a06680 100644 --- a/teta_widgets/lib/src/elements/widgets/column.dart +++ b/teta_widgets/lib/src/elements/widgets/column.dart @@ -45,11 +45,11 @@ class _WColumnState extends State { Widget build(final BuildContext context) { return TetaWidget( state: widget.state, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final nodes) { if (nodes.length == 1) { final index = children - .indexWhere((final element) => element.nid == nodes.first.nid); + .indexWhere((final element) => element.nid == nodes.first); if (index != -1) { return ReorderableColumn( onReorder: (final oldIndex, final newIndex) { diff --git a/teta_widgets/lib/src/elements/widgets/listview.dart b/teta_widgets/lib/src/elements/widgets/listview.dart index 6e592279..b4a65573 100644 --- a/teta_widgets/lib/src/elements/widgets/listview.dart +++ b/teta_widgets/lib/src/elements/widgets/listview.dart @@ -84,11 +84,11 @@ class _WListViewState extends State { }, child: ScrollConfiguration( behavior: _MyCustomScrollBehavior(), - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final nodes) { if (nodes.length == 1) { final index = widget.children.indexWhere( - (final element) => element.nid == nodes.first.nid, + (final element) => element.nid == nodes.first, ); if (index != -1) { return ReorderableListView.builder( diff --git a/teta_widgets/lib/src/elements/widgets/row.dart b/teta_widgets/lib/src/elements/widgets/row.dart index 14c0a08a..04bc1380 100644 --- a/teta_widgets/lib/src/elements/widgets/row.dart +++ b/teta_widgets/lib/src/elements/widgets/row.dart @@ -50,11 +50,11 @@ class _WRowState extends State { Widget build(final BuildContext context) { return TetaWidget( state: widget._state, - child: BlocBuilder>( + child: BlocBuilder>( builder: (final context, final nodes) { if (nodes.length == 1) { final index = widget._children - .indexWhere((final element) => element.nid == nodes.first.nid); + .indexWhere((final element) => element.nid == nodes.first); if (index != -1) { return ReorderableRow( onReorder: (final oldIndex, final newIndex) { diff --git a/teta_widgets/lib/src/elements/widgets/scaffold.dart b/teta_widgets/lib/src/elements/widgets/scaffold.dart index 94440ab2..92d96006 100644 --- a/teta_widgets/lib/src/elements/widgets/scaffold.dart +++ b/teta_widgets/lib/src/elements/widgets/scaffold.dart @@ -71,8 +71,7 @@ class _WScaffoldState extends State { @override Widget build(final BuildContext context) { - final isPage = - (BlocProvider.of(context).state as PageLoaded).page.isPage; + final isPage = (context.watch().state as PageLoaded).page.isPage; if (!isPage && !widget.state.forPlay) { return SizedBox( child: Center( @@ -156,8 +155,7 @@ class _WScaffoldState extends State { (final element) => element.globalType == NType.drawer, ); - final isPage = - (BlocProvider.of(context).state as PageLoaded).page.isPage; + final isPage = (context.watch().state as PageLoaded).page.isPage; if (!isPage) return _childWids(context); return Stack( children: [ From b4244843ba966c02ec1c11b742671633388fe583 Mon Sep 17 00:00:00 2001 From: Jhaym3s Date: Sat, 4 Feb 2023 08:48:57 +0100 Subject: [PATCH 23/23] supabase storage and widget --- .../actions/supabase/request_phone_otp.dart | 67 ++++ .../elements/actions/supabase/sign_out.dart | 61 ++++ .../actions/supabase/signin_w_phone.dart | 79 +++++ .../actions/supabase/signup_w_phone.dart | 79 +++++ .../supabase/storage/storage_bucket_list.dart | 58 ++++ .../storage/storage_create_bucket.dart | 75 +++++ .../storage/storage_delete_bucket.dart | 75 +++++ .../supabase/storage/storage_download.dart | 90 ++++++ .../storage/storage_empty_bucket.dart | 77 +++++ .../storage/storage_list_all_files.dart | 79 +++++ .../storage/storage_retrive_bucket.dart | 75 +++++ .../storage/storage_update_binary.dart.dart | 140 +++++++++ .../storage/storage_update_bucket.dart | 77 +++++ .../actions/supabase/storage_upload.dart | 2 +- .../bodies/supabase/future_builder.dart | 29 ++ .../supabase/future_stream_builder.dart | 2 +- .../bodies/supabase/user_is_logged.dart | 81 +++++ .../elements/bodies/teta_cms/logged_user.dart | 2 +- .../code/templates/cms_logged_user.dart | 2 +- .../code/templates/future_builder.dart | 139 ++++++++- .../code/templates/stream_builder.dart | 1 + .../code/templates/user_is_logged.dart | 45 +++ .../src/elements/controls/key_constants.dart | 40 +++ .../elements/features/actions/element.dart | 289 +++++++++++++++++- .../features/actions/enums/supabase.dart | 21 +- teta_widgets/lib/src/elements/nodes/enum.dart | 1 + .../widgets/supabase/future_builder.dart | 154 ++++++++++ .../supabase/supabase_stream_builder.dart | 4 + .../widgets/supabase/user_is_logged.dart | 92 ++++++ .../widgets/teta_cms/logged_user.dart | 1 - 30 files changed, 1928 insertions(+), 9 deletions(-) create mode 100644 teta_widgets/lib/src/elements/actions/supabase/request_phone_otp.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/sign_out.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/signin_w_phone.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/signup_w_phone.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_bucket_list.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_create_bucket.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_delete_bucket.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_download.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_empty_bucket.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_list_all_files.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_retrive_bucket.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_binary.dart.dart create mode 100644 teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_bucket.dart create mode 100644 teta_widgets/lib/src/elements/bodies/supabase/user_is_logged.dart create mode 100644 teta_widgets/lib/src/elements/code/templates/user_is_logged.dart create mode 100644 teta_widgets/lib/src/elements/widgets/supabase/user_is_logged.dart diff --git a/teta_widgets/lib/src/elements/actions/supabase/request_phone_otp.dart b/teta_widgets/lib/src/elements/actions/supabase/request_phone_otp.dart new file mode 100644 index 00000000..40db6d7a --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/request_phone_otp.dart @@ -0,0 +1,67 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hive/hive.dart'; +import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; + +import '../../../../teta_widgets.dart'; +import '../../../core/teta_widget/index.dart'; +import '../navigation/open_page.dart'; +import '../snippets/change_state.dart'; + +class FASupabaseRequestPhoneOtp { + static Future action( + final BuildContext context, + final TetaWidgetState state, + final String value, + final CNode scaffold, + final String? nameOfPage, + final Map? paramsToSend, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + ///Phone number from state + final phone = takeStateFrom(page, 'phone'); + // Take status from states + final status = takeStateFrom(page, 'status'); + + if (phone != null) { + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.auth.signIn(phone: '${phone.get}'); + if (response.error == null) { + changeState(status, context, '${response.error?.message}'); + } + } + } + + } + + static String toCode( + final BuildContext context, + final String? nameOfPage, + final Map? paramsToSend, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final phone = takeStateFrom(page, 'phone'); + + if (phone == null) return ''; + return ''' + if (phone != null && otp != null) { + ${status != null ? "setState(() { status = 'Loading'; });" : ''} + final response = await Supabase.instance.client.auth.signIn(phone: phone); + if (response.error != null) { + ${status != null ? "setState(() { status = 'Failed'; });" : ''} + } else { + ${status != null ? "setState(() { status = 'Success'; });" : ''} + ${FActionNavigationOpenPage.toCode(context, nameOfPage, paramsToSend)} + } + } + '''; + } + + } diff --git a/teta_widgets/lib/src/elements/actions/supabase/sign_out.dart b/teta_widgets/lib/src/elements/actions/supabase/sign_out.dart new file mode 100644 index 00000000..e86d27ae --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/sign_out.dart @@ -0,0 +1,61 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hive/hive.dart'; +import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; + +import '../../../../teta_widgets.dart'; +import '../../../core/teta_widget/index.dart'; +import '../navigation/open_page.dart'; +import '../snippets/change_state.dart'; + +class FASupabaseSignOut{ + static Future action( + final BuildContext context, + final TetaWidgetState state, + final String value, + final CNode scaffold, + final String? nameOfPage, + final Map? paramsToSend, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.auth.signOut(); + if (response.error == null) { + changeState(status, context, '${response.error?.message}'); + } + } + + + } + + static String toCode( + final BuildContext context, + final String? nameOfPage, + final Map? paramsToSend, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + + return ''' + + ${status != null ? "setState(() { status = 'Loading'; });" : ''} + final response = await Supabase.instance.client.auth.signOut(); + if (response.error != null) { + ${status != null ? "setState(() { status = 'Failed'; });" : ''} + } else { + ${status != null ? "setState(() { status = 'Success'; });" : ''} + ${FActionNavigationOpenPage.toCode(context, nameOfPage, paramsToSend)} + } + + '''; + } + + } diff --git a/teta_widgets/lib/src/elements/actions/supabase/signin_w_phone.dart b/teta_widgets/lib/src/elements/actions/supabase/signin_w_phone.dart new file mode 100644 index 00000000..a7a336db --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/signin_w_phone.dart @@ -0,0 +1,79 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hive/hive.dart'; +import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; + +import '../../../../teta_widgets.dart'; +import '../../../core/teta_widget/index.dart'; +import '../navigation/open_page.dart'; +import '../snippets/change_state.dart'; + +class FASupabaseSignInWithPhone { + static Future action( + final BuildContext context, + final TetaWidgetState state, + final String value, + final CNode scaffold, + final String? nameOfPage, + final Map? paramsToSend, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + ///Phone number from state + final phone = takeStateFrom(page, 'phone'); + ///Phone number from state + final otp = takeStateFrom(page, 'otp'); + // Take status from states + final status = takeStateFrom(page, 'status'); + + if (phone != null && otp != null) { + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.auth.verifyOTP('${phone.get}', '${otp.get}'); + if (response.error == null) { + changeState(status, context, '${response.error?.message}'); + }else{ + changeState(status, context, 'Success'); + final box = await Hive.openBox('social_login'); + await box.put('key', {'phone': '${phone.get}'}); + await FActionNavigationOpenPage.action( + context, + state, + nameOfPage, + paramsToSend, + ); + } + } + } + + } + + static String toCode( + final BuildContext context, + final String? nameOfPage, + final Map? paramsToSend, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final phone = takeStateFrom(page, 'phone'); + final otp = takeStateFrom(page, 'otp'); + if (phone == null || otp == null) return ''; + return ''' + if (phone != null && otp != null) { + ${status != null ? "setState(() { status = 'Loading'; });" : ''} + final response = await Supabase.instance.client.auth.signUp(phone, otp); + if (response.error != null) { + ${status != null ? "setState(() { status = 'Failed'; });" : ''} + } else { + ${status != null ? "setState(() { status = 'Success'; });" : ''} + ${FActionNavigationOpenPage.toCode(context, nameOfPage, paramsToSend)} + } + } + '''; + } + + } diff --git a/teta_widgets/lib/src/elements/actions/supabase/signup_w_phone.dart b/teta_widgets/lib/src/elements/actions/supabase/signup_w_phone.dart new file mode 100644 index 00000000..480877a8 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/signup_w_phone.dart @@ -0,0 +1,79 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hive/hive.dart'; +import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; + +import '../../../../teta_widgets.dart'; +import '../../../core/teta_widget/index.dart'; +import '../navigation/open_page.dart'; +import '../snippets/change_state.dart'; + +class FASupabaseSignUpWithPhone { + static Future action( + final BuildContext context, + final TetaWidgetState state, + final String value, + final CNode scaffold, + final String? nameOfPage, + final Map? paramsToSend, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + ///Phone number from state + final phone = takeStateFrom(page, 'phone'); + ///Phone number from state + final password = takeStateFrom(page, 'password'); + // Take status from states + final status = takeStateFrom(page, 'status'); + + if (phone != null && password != null) { + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.auth.signUpWithPhone('${phone.get}', '${password.get}'); + if (response.error == null) { + changeState(status, context, '${response.error?.message}'); + }else{ + changeState(status, context, 'Success'); + final box = await Hive.openBox('social_login'); + await box.put('key', {'phone': '${phone.get}'}); + await FActionNavigationOpenPage.action( + context, + state, + nameOfPage, + paramsToSend, + ); + } + } + } + + } + + static String toCode( + final BuildContext context, + final String? nameOfPage, + final Map? paramsToSend, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final phone = takeStateFrom(page, 'phone'); + final password = takeStateFrom(page, 'password'); + if (phone == null || password == null) return ''; + return ''' + if (phone != null && otp != null) { + ${status != null ? "setState(() { status = 'Loading'; });" : ''} + final response = await Supabase.instance.client.auth.signUp(phone, password); + if (response.error != null) { + ${status != null ? "setState(() { status = 'Failed'; });" : ''} + } else { + ${status != null ? "setState(() { status = 'Success'; });" : ''} + ${FActionNavigationOpenPage.toCode(context, nameOfPage, paramsToSend)} + } + } + '''; + } + + } diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_bucket_list.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_bucket_list.dart new file mode 100644 index 00000000..cf241fb3 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_bucket_list.dart @@ -0,0 +1,58 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageBucketList { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage.listBuckets(); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + return r''' +await Supabase.instance.client.storage.listBucket(); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: ${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_create_bucket.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_create_bucket.dart new file mode 100644 index 00000000..cbd05c92 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_create_bucket.dart @@ -0,0 +1,75 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageCreateBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .createBucket( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.createBucket([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_delete_bucket.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_delete_bucket.dart new file mode 100644 index 00000000..3951a330 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_delete_bucket.dart @@ -0,0 +1,75 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:supabase/supabase.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageDeleteBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage.deleteBucket( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.deleteBucket([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_download.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_download.dart new file mode 100644 index 00000000..2ac4d419 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_download.dart @@ -0,0 +1,90 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageDownload { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .from( + supabaseFrom?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ) + .download( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + final from = supabaseFrom?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.from($from).download([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_empty_bucket.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_empty_bucket.dart new file mode 100644 index 00000000..a3167e56 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_empty_bucket.dart @@ -0,0 +1,77 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:supabase/supabase.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageEmptyBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .emptyBucket( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.emptyBucket([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_list_all_files.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_list_all_files.dart new file mode 100644 index 00000000..a5cbf934 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_list_all_files.dart @@ -0,0 +1,79 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageListAllFilesInBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .from( + supabaseFrom?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ).list(); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + final from = supabaseFrom?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.from($from).download([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_retrive_bucket.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_retrive_bucket.dart new file mode 100644 index 00000000..d61ee860 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_retrive_bucket.dart @@ -0,0 +1,75 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageRetrieveBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .getBucket( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.getBucket([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_binary.dart.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_binary.dart.dart new file mode 100644 index 00000000..8f5465d8 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_binary.dart.dart @@ -0,0 +1,140 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:recase/recase.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageUpdateBinaryUpload { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final String? stateName, + final String? stateName2, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final index = + states.indexWhere((final element) => element.name == stateName); + final client = BlocProvider.of(context).state; + if (client != null && index != -1) { + final bytes = await states[index].file?.readAsBytes(); + if (bytes == null || bytes.isEmpty) return; + final response = await client.storage + .from( + supabaseFrom?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ) + .updateBinary( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + bytes, + ); + if (response.error != null) changeState(status, context, 'Failed'); + final index2 = + states.indexWhere((final element) => element.name == stateName2); + final res = client.storage + .from( + supabaseFrom?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ) + .getPublicUrl( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + ); + if (res.error != null) { + Logger.printError( + 'Error retriving the public url from just uploaded file, error: ${res.error?.message}', + ); + } else if (res.data != null) { + changeState(states[index2], context, res.data!); + } + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final String stateName, + final String stateName2, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + final from = supabaseFrom?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + final varName = ReCase(stateName).camelCase; + final varName2 = ReCase(stateName2).camelCase; + return ''' +final bytes = await $varName.readAsBytes(); +await Supabase.instance.client.storage.from($from).uploadBinary($path,bytes); +final res = Supabase.instance.client.storage.from($from).getPublicUrl($path); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} else if (res.data != null) { + setState(() { + $varName2 = res.data!; + }); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_bucket.dart b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_bucket.dart new file mode 100644 index 00000000..154c6b23 --- /dev/null +++ b/teta_widgets/lib/src/elements/actions/supabase/storage/storage_update_bucket.dart @@ -0,0 +1,77 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: public_member_api_docs + +// Flutter imports: + +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:supabase/supabase.dart'; +import 'package:teta_core/teta_core.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; +import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; +import 'package:teta_widgets/src/elements/features/text_type_input.dart'; + +class FASupabaseStorageUpdateBucket { + static Future action( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final List params, + final List states, + final List dataset, + final int? loop, + ) async { + final page = BlocProvider.of(context).state as PageLoaded; + + // Take status from states + final status = takeStateFrom(page, 'status'); + + changeState(status, context, 'Loading'); + final client = BlocProvider.of(context).state; + if (client != null) { + final response = await client.storage + .updateBucket( + pathFile?.get( + params, + states, + dataset, + true, + loop, + context, + ) ?? + '', + const BucketOptions(public: false), + ); + if (response.error != null) changeState(status, context, 'Failed'); + changeState(status, context, 'Success'); + } + } + + static String toCode( + final BuildContext context, + final FTextTypeInput? supabaseFrom, + final FTextTypeInput? pathFile, + final int? loop, + ) { + final page = BlocProvider.of(context).state as PageLoaded; + final status = takeStateFrom(page, 'status'); + final client = BlocProvider.of(context).state; + + final path = pathFile?.toCode( + loop, + resultType: ResultTypeEnum.string, + defaultValue: '', + ); + return ''' +await Supabase.instance.client.storage.updateBucket([$path]); +if (res.error != null) { + debugPrint( + 'Error retriving the public url, error: \${res.error?.message}', + ); +} +'''; + } +} diff --git a/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart b/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart index 42aa4025..35373832 100644 --- a/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart +++ b/teta_widgets/lib/src/elements/actions/supabase/storage_upload.dart @@ -14,7 +14,7 @@ import 'package:teta_widgets/src/elements/actions/snippets/change_state.dart'; import 'package:teta_widgets/src/elements/actions/snippets/take_state_from.dart'; import 'package:teta_widgets/src/elements/features/text_type_input.dart'; -class FASupabaseStorageUpload { +class FASupabaseStorageBinaryUpload { static Future action( final BuildContext context, final FTextTypeInput? supabaseFrom, diff --git a/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart b/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart index 79a9de4f..525ced85 100644 --- a/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/supabase/future_builder.dart @@ -164,6 +164,19 @@ class SupabaseFutureBuilderBody extends NodeBody { ${(attributes[DBKeys.supabaseSearchValue] as FTextTypeInput).toJson()} ${(attributes[DBKeys.supabaseEqName] as FTextTypeInput).toJson()} ${(attributes[DBKeys.supabaseEqValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseContainsName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseContainsValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseFilterName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseFilterValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseFilterOperator] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseGreaterOrEqualName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseGreaterOrEqualValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseGreaterThanName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseGreaterThanValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseLessThanName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseLessThanValue] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseLessThanOrEqualName] as FTextTypeInput).toJson()} + ${(attributes[DBKeys.supabaseLessThanOrEqualValue] as FTextTypeInput).toJson()} ''', ), state: state, @@ -178,6 +191,22 @@ class SupabaseFutureBuilderBody extends NodeBody { searchValue: attributes[DBKeys.supabaseSearchValue] as FTextTypeInput, eqName: attributes[DBKeys.supabaseEqName] as FTextTypeInput, eqValue: attributes[DBKeys.supabaseEqValue] as FTextTypeInput, + containsName: attributes[DBKeys.supabaseContainsName] as FTextTypeInput, + containsValue: attributes[DBKeys.supabaseContainsValue] as FTextTypeInput, + filterName: attributes[DBKeys.supabaseFilterValue] as FTextTypeInput, + filterOperator: + attributes[DBKeys.supabaseFilterOperator] as FTextTypeInput, + filterValue: attributes[DBKeys.supabaseFilterValue] as FTextTypeInput, + gtEName: attributes[DBKeys.supabaseGreaterOrEqualName] as FTextTypeInput, + gtEValue: + attributes[DBKeys.supabaseGreaterOrEqualValue] as FTextTypeInput, + gtName: attributes[DBKeys.supabaseGreaterThanName] as FTextTypeInput, + gtValue: attributes[DBKeys.supabaseGreaterThanValue] as FTextTypeInput, + ltName: attributes[DBKeys.supabaseLessThanName] as FTextTypeInput, + ltValue: attributes[DBKeys.supabaseLessThanValue] as FTextTypeInput, + ltEName: attributes[DBKeys.supabaseLessThanOrEqualName] as FTextTypeInput, + ltEValue: + attributes[DBKeys.supabaseLessThanOrEqualValue] as FTextTypeInput, ); } diff --git a/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart b/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart index fb6ed8b9..51229315 100644 --- a/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart +++ b/teta_widgets/lib/src/elements/bodies/supabase/future_stream_builder.dart @@ -104,7 +104,7 @@ class SupabaseStreamBuilderBody extends NodeBody { '${(attributes[DBKeys.supabaseFromRange] as FTextTypeInput).value}', ); return WSupabaseStreamBuilder( - ValueKey(str.toString()), + ValueKey(str.toString()), state: state, children: children ?? [], from: attributes[DBKeys.supabaseFrom] as FTextTypeInput, diff --git a/teta_widgets/lib/src/elements/bodies/supabase/user_is_logged.dart b/teta_widgets/lib/src/elements/bodies/supabase/user_is_logged.dart new file mode 100644 index 00000000..600c225c --- /dev/null +++ b/teta_widgets/lib/src/elements/bodies/supabase/user_is_logged.dart @@ -0,0 +1,81 @@ + +import 'package:flutter/material.dart'; +import 'package:teta_core/gen/assets.gen.dart'; +import 'package:teta_widgets/src/elements/nodes/node_body.dart'; + +import '../../../../teta_widgets.dart'; +import '../../../core/teta_widget/index.dart'; +import '../../intrinsic_states/class.dart'; +import '../../nodes/categories.dart'; +import '../../widgets/supabase/user_is_logged.dart'; + +const _globalType = NType.supabaseUserIsLogged; + +final supabaseUserIsLoggedBuilderIntrinsicStates = IntrinsicStates( + nodeIcon: Assets.wIcons.supabaseLogoIcon, + nodeVideo: null, + nodeDescription: null, + advicedChildren: [ + NodeType.name(NType.container), + NodeType.name(NType.column), + NodeType.name(NType.row) + ], + blockedTypes: [], + synonymous: [ + NodeType.name(_globalType), + 'firestore', + 'firebase', + 'future builder', + 'stream builder', + ], + advicedChildrenCanHaveAtLeastAChild: [], + displayName: NodeType.name(_globalType), + type: _globalType, + category: NodeCategories.dynamicCollection, + maxChildren: 2, + canHave: ChildrenEnum.children, + addChildLabels: [], + gestures: [], + permissions: [], + packages: [], +); + +class SupabaseUserIsLoggedBody extends NodeBody{ + + @override + // ignore: overridden_fields + Map attributes = {}; + + @override + List get controls => []; + + @override + Widget toWidget({ + required final TetaWidgetState state, + final CNode? child, + final List? children, + }) { + return WSupabaseUserIsLogged( + ValueKey( + ''' + ${state.toKey} + $child + ''', + ), + state: state, + child: child, + ); + } + + @override + Future toCode( + final BuildContext context, + final CNode node, + final CNode? child, + final List? children, + final int pageId, + final int? loop, + ) => + Future.value(''); + +} diff --git a/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart index 44563878..41f5ecd7 100644 --- a/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/bodies/teta_cms/logged_user.dart @@ -90,4 +90,4 @@ class CMSLoggedUserBody extends NodeBody { children ?? [], loop, ); -} +} \ No newline at end of file diff --git a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart index 2f0a6a6d..c12ee1db 100644 --- a/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart +++ b/teta_widgets/lib/src/elements/code/templates/cms_logged_user.dart @@ -16,7 +16,7 @@ class CmsLoggedUserCodeTemplate { final List children, final int? loop, ) async { - var child = 'const SizedBox()'; + var child = 'const SizedBox()'; if (children.isNotEmpty) { child = await children.first.toCode(context); } diff --git a/teta_widgets/lib/src/elements/code/templates/future_builder.dart b/teta_widgets/lib/src/elements/code/templates/future_builder.dart index e3feced2..33427d46 100644 --- a/teta_widgets/lib/src/elements/code/templates/future_builder.dart +++ b/teta_widgets/lib/src/elements/code/templates/future_builder.dart @@ -18,6 +18,66 @@ class SupabaseFutureBuilderCodeTemplate { final List children, final int? loop, ) async { + final containsName = + (body.attributes[DBKeys.supabaseContainsName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final containsValue = + (body.attributes[DBKeys.supabaseContainsValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final gtName = + (body.attributes[DBKeys.supabaseGreaterThanName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final gtValue = + (body.attributes[DBKeys.supabaseGreaterThanValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final gtEName = + (body.attributes[DBKeys.supabaseGreaterOrEqualName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final gtEValue = + (body.attributes[DBKeys.supabaseGreaterOrEqualValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final ltName = + (body.attributes[DBKeys.supabaseLessThanName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final ltValue = + (body.attributes[DBKeys.supabaseLessThanValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final ltEName = + (body.attributes[DBKeys.supabaseLessThanOrEqualName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final ltEValue = + (body.attributes[DBKeys.supabaseLessThanOrEqualValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final filterName = + (body.attributes[DBKeys.supabaseFilterName] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); + final filterValue = + (body.attributes[DBKeys.supabaseFilterValue] as FTextTypeInput).toCode( + loop, + resultType: ResultTypeEnum.string, + ); final from = (body.attributes[DBKeys.supabaseFrom] as FTextTypeInput).toCode( loop, @@ -47,7 +107,6 @@ class SupabaseFutureBuilderCodeTemplate { resultType: ResultTypeEnum.int, defaultValue: '15', ); - final numberPage = (body.attributes[DBKeys.supabaseNumberPage] as FTextTypeInput).toCode( loop, @@ -77,6 +136,12 @@ class SupabaseFutureBuilderCodeTemplate { .from($from) .select($select) .order($order) + .ltE($ltEName,$ltEValue) + .lt($ltName,$ltValue) + .gte($gtEName,$gtEValue) + .gt($gtName,$gtValue) + .filter($filterName, $filterValue) + .contains($containsName, $containsValue) .range(($numberPage * $rangeFrom) - 1, $numberPage * $rangeTo) .execute(), builder: (context, snapshot) { @@ -88,6 +153,7 @@ class SupabaseFutureBuilderCodeTemplate { } ) '''; + final res = FormatterTest.format(code); if (res) { return code; @@ -144,6 +210,71 @@ class SupabaseFutureBuilderCodeTemplate { 0, resultType: ResultTypeEnum.string, ); + final gtEName = + (body.attributes[DBKeys.supabaseGreaterOrEqualName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final gtEValue = + (body.attributes[DBKeys.supabaseGreaterOrEqualValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final gtName = + (body.attributes[DBKeys.supabaseGreaterThanName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + + final gtValue = + (body.attributes[DBKeys.supabaseGreaterThanValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final ltName = + (body.attributes[DBKeys.supabaseLessThanName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + + final ltValue = + (body.attributes[DBKeys.supabaseLessThanValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final filterName = + (body.attributes[DBKeys.supabaseFilterName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + + final filterValue = + (body.attributes[DBKeys.supabaseFilterValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final ltEName = + (body.attributes[DBKeys.supabaseLessThanOrEqualName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + + final ltEValue = + (body.attributes[DBKeys.supabaseLessThanOrEqualValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final containsName = + (body.attributes[DBKeys.supabaseContainsName] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final containsValue = + (body.attributes[DBKeys.supabaseContainsValue] as FTextTypeInput).toCode( + 0, + resultType: ResultTypeEnum.string, + ); + final select = (body.attributes[DBKeys.supabaseSelect] as FTextTypeInput).toCode( 0, @@ -187,6 +318,12 @@ class SupabaseFutureBuilderCodeTemplate { future: Supabase.instance.client .from($from) .select($select) + .gt($gtName,$gtValue) + .gte($gtEName,$gtEValue) + .filter($filterName,$filterValue) + .lte($ltEName, $ltEValue) + .lt($ltName,$ltValue) + .contains($containsName, $containsValue) .order($order) .range(($numberPage * $rangeFrom) - 1, $numberPage * $rangeTo) .execute(), diff --git a/teta_widgets/lib/src/elements/code/templates/stream_builder.dart b/teta_widgets/lib/src/elements/code/templates/stream_builder.dart index 73bac6d3..207315fb 100644 --- a/teta_widgets/lib/src/elements/code/templates/stream_builder.dart +++ b/teta_widgets/lib/src/elements/code/templates/stream_builder.dart @@ -18,6 +18,7 @@ class StreamBuilderCodeTemplate { final List children, final int? loop, ) async { + final from = (body.attributes[DBKeys.supabaseFrom] as FTextTypeInput).toCode( loop, diff --git a/teta_widgets/lib/src/elements/code/templates/user_is_logged.dart b/teta_widgets/lib/src/elements/code/templates/user_is_logged.dart new file mode 100644 index 00000000..9611ec42 --- /dev/null +++ b/teta_widgets/lib/src/elements/code/templates/user_is_logged.dart @@ -0,0 +1,45 @@ + +import 'package:flutter/cupertino.dart'; + +import '../../../../teta_widgets.dart'; +import '../../nodes/node_body.dart'; +import '../formatter_test.dart'; + +class UserLoggedInCodeTemplate{ + + static Future toCode( + final BuildContext context, + final CNode node, + final CNode? child, + final int loop, + ) async { + var loader = 'const CircularProgressIndicator()'; + + const func = ''' + final userMap = snapshot.data as Map?; + if (doc == null) return const SizedBox(); + + final datasets = this.datasets; + datasets['Supabase user is logged'] = doc.data as List? ?? []; + '''; + final code = ''' +FutureBuilder( + future: Supabase.instance.client.auth.currentUser; + builder: (context, snapshot) { + if (!snapshot.hasData) { + return $loader; + } + $func + return $child; + } + ) + '''; + final res = FormatterTest.format(code); + if (res) { + return code; + } else { + return 'const SizedBox()'; + } + } + } + diff --git a/teta_widgets/lib/src/elements/controls/key_constants.dart b/teta_widgets/lib/src/elements/controls/key_constants.dart index 962e91e6..60b2f7aa 100644 --- a/teta_widgets/lib/src/elements/controls/key_constants.dart +++ b/teta_widgets/lib/src/elements/controls/key_constants.dart @@ -163,6 +163,46 @@ class DBKeys { /// Use for from's value in Supabase operation static const String supabaseFrom = 'spF'; + /// Use for contains's name in Supabase operation + static const String supabaseContainsName = 'spConN'; + + // Use for contains's value in Supabase operation + static const String supabaseContainsValue = 'spConV'; + + /// Use for greater's name in Supabase operation + static const String supabaseGreaterThanName = 'spGtN'; + + // Use for contains's value in Supabase operation + static const String supabaseGreaterThanValue = 'spGtV'; + + /// Use for greater's name in Supabase operation + static const String supabaseGreaterOrEqualName = 'spGtEN'; + + // Use for contains's value in Supabase operation + static const String supabaseGreaterOrEqualValue = 'spGtEV'; + + /// Use for less than name in Supabase operation + static const String supabaseLessThanName = 'spLtN'; + + // Use for less than value in Supabase operation + static const String supabaseLessThanValue = 'spLtV'; + + /// Use for less than or name in Supabase operation + static const String supabaseLessThanOrEqualName = 'spLtEN'; + + // Use for less than value in Supabase operation + static const String supabaseLessThanOrEqualValue = 'spLtEV'; + + /// Use for filter's name in Supabase operation + static const String supabaseFilterName = 'spFilN'; + + // Use for filter's value in Supabase operation + static const String supabaseFilterOperator = 'spFilV'; + + + // Use for filter's value in Supabase operation + static const String supabaseFilterValue = 'spFilV'; + /// Use for select's value in Supabase operation static const String supabaseSelect = 'spSl'; diff --git a/teta_widgets/lib/src/elements/features/actions/element.dart b/teta_widgets/lib/src/elements/features/actions/element.dart index 8451cb7e..57c497d6 100644 --- a/teta_widgets/lib/src/elements/features/actions/element.dart +++ b/teta_widgets/lib/src/elements/features/actions/element.dart @@ -115,6 +115,20 @@ import 'package:teta_widgets/src/elements/nodes/enum.dart'; import 'package:teta_widgets/src/elements/nodes/node.dart'; import 'package:uuid/uuid.dart'; +import '../../actions/supabase/request_phone_otp.dart'; +import '../../actions/supabase/sign_out.dart'; +import '../../actions/supabase/signin_w_phone.dart'; +import '../../actions/supabase/signup_w_phone.dart'; +import '../../actions/supabase/storage/storage_bucket_list.dart'; +import '../../actions/supabase/storage/storage_create_bucket.dart'; +import '../../actions/supabase/storage/storage_delete_bucket.dart'; +import '../../actions/supabase/storage/storage_download.dart'; +import '../../actions/supabase/storage/storage_empty_bucket.dart'; +import '../../actions/supabase/storage/storage_list_all_files.dart'; +import '../../actions/supabase/storage/storage_retrive_bucket.dart'; +import '../../actions/supabase/storage/storage_update_binary.dart.dart'; +import '../../actions/supabase/storage/storage_update_bucket.dart'; + class FActionElement extends Equatable { FActionElement({ this.id, @@ -1947,7 +1961,7 @@ class FActionElement extends Equatable { switch (actionSupabaseStorage) { case ActionSupabaseStorage.upload: await actionS( - () => FASupabaseStorageUpload.action( + () => FASupabaseStorageBinaryUpload.action( context, dbFrom, valueTextTypeInput, @@ -1976,6 +1990,143 @@ class FActionElement extends Equatable { context: context, state: state, ); + break; + case ActionSupabaseStorage.listBuckets: + await actionS( + () => FASupabaseStorageBucketList.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.createBucket: + await actionS( + () => FASupabaseStorageCreateBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.deleteBucket: + await actionS( + () => FASupabaseStorageDeleteBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.downloadFile: + await actionS( + () => FASupabaseStorageDownload.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.emptyBucket: + await actionS( + () => FASupabaseStorageEmptyBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.listAllFilesInBucket: + await actionS( + () => FASupabaseStorageListAllFilesInBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.getBucket: + await actionS( + () => FASupabaseStorageRetrieveBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.update: + await actionS( + () => FASupabaseStorageUpdateBinaryUpload.action( + context, + dbFrom, + valueTextTypeInput, + stateName, + stateName2, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); + break; + case ActionSupabaseStorage.updateBucket: + await actionS( + () => FASupabaseStorageUpdateBucket.action( + context, + dbFrom, + valueTextTypeInput, + state.params, + state.states, + state.dataset, + state.loop, + ), + context: context, + state: state, + ); break; case null: break; @@ -2887,6 +3038,46 @@ class FActionElement extends Equatable { context, ); + case ActionSupabaseAuth.signUpWithPhone: + return codeS( + FASupabaseSignUpWithPhone.toCode( + context, + nameOfPage, + paramsToSend, + ), + context, + ); + + case ActionSupabaseAuth.signInWithPhone: + return codeS( + FASupabaseSignInWithPhone.toCode( + context, + nameOfPage, + paramsToSend, + ), + context, + ); + + case ActionSupabaseAuth.requestOtp: + return codeS( + FASupabaseRequestPhoneOtp.toCode( + context, + nameOfPage, + paramsToSend, + ), + context, + ); + + case ActionSupabaseAuth.signOut: + return codeS( + FASupabaseSignOut.toCode( + context, + nameOfPage, + paramsToSend, + ), + context, + ); + case ActionSupabaseAuth.signInWithGoogle: return codeS( FASupabaseSignInWithProvider.toCode( @@ -3022,11 +3213,13 @@ class FActionElement extends Equatable { case null: return ''; } + break; + case ActionType.supabaseStorage: switch (actionSupabaseStorage) { case ActionSupabaseStorage.upload: return codeS( - FASupabaseStorageUpload.toCode( + FASupabaseStorageBinaryUpload.toCode( context, dbFrom, valueTextTypeInput, @@ -3046,6 +3239,98 @@ class FActionElement extends Equatable { ), context, ); + case ActionSupabaseStorage.update: + return codeS( + FASupabaseStorageUpdateBinaryUpload.toCode( + context, + dbFrom, + valueTextTypeInput, + stateName ?? '', + stateName2 ?? '', + loop, + ), + context, + ); + case ActionSupabaseStorage.listBuckets: + return codeS( + FASupabaseStorageBucketList.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.createBucket: + return codeS( + FASupabaseStorageCreateBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.deleteBucket: + return codeS( + FASupabaseStorageDeleteBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.downloadFile: + return codeS( + FASupabaseStorageDownload.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.emptyBucket: + return codeS( + FASupabaseStorageEmptyBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.listAllFilesInBucket: + return codeS( + FASupabaseStorageListAllFilesInBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.getBucket: + return codeS( + FASupabaseStorageRetrieveBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); + case ActionSupabaseStorage.updateBucket: + return codeS( + FASupabaseStorageUpdateBucket.toCode( + context, + dbFrom, + valueTextTypeInput, + loop, + ), + context, + ); case null: return ''; } diff --git a/teta_widgets/lib/src/elements/features/actions/enums/supabase.dart b/teta_widgets/lib/src/elements/features/actions/enums/supabase.dart index d46e4368..20614154 100644 --- a/teta_widgets/lib/src/elements/features/actions/enums/supabase.dart +++ b/teta_widgets/lib/src/elements/features/actions/enums/supabase.dart @@ -11,6 +11,7 @@ enum ActionSupabaseAuth { signInWithGitHub, signInWithGitLab, signInWithGoogle, + //signInWithLinkedin, //signInWithNotion, signInWithTwitch, @@ -19,15 +20,33 @@ enum ActionSupabaseAuth { signInWithSpotify, //signInWithWorkOS, //signInWithZoom, + requestOtp, + signUpWithPhone, + signInWithPhone, + signOut, } enum ActionSupabaseDB { insert, update, delete, + } -enum ActionSupabaseStorage { upload, remove } +enum ActionSupabaseStorage { + upload, + remove, + createBucket, + getBucket, + listBuckets, + updateBucket, + deleteBucket, + emptyBucket, + downloadFile, + listAllFilesInBucket, + update + + } enum ActionSupabaseFunctions { invoke, diff --git a/teta_widgets/lib/src/elements/nodes/enum.dart b/teta_widgets/lib/src/elements/nodes/enum.dart index 8dce0a85..db5ca0d9 100644 --- a/teta_widgets/lib/src/elements/nodes/enum.dart +++ b/teta_widgets/lib/src/elements/nodes/enum.dart @@ -130,6 +130,7 @@ enum NType { supabaseFutureBuilder, supabaseStreamBuilder, supabaseLoggedUser, + supabaseUserIsLogged, //Stripe stripeProductsBuilder, stripeShippingBuilder, diff --git a/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart b/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart index 765fa614..15bc3d5f 100644 --- a/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/supabase/future_builder.dart @@ -30,6 +30,19 @@ class WSupabaseFutureBuilder extends StatefulWidget { required this.eqName, required this.eqValue, required this.children, + required this.containsName, + required this.containsValue, + required this.filterName, + required this.filterValue, + required this.filterOperator, + required this.gtName, + required this.gtValue, + required this.gtEName, + required this.gtEValue, + required this.ltName, + required this.ltValue, + required this.ltEName, + required this.ltEValue, }) : super(key: key); final TetaWidgetState state; @@ -56,6 +69,19 @@ class WSupabaseFutureBuilder extends StatefulWidget { final FTextTypeInput searchValue; final FTextTypeInput eqName; final FTextTypeInput eqValue; + final FTextTypeInput containsName; + final FTextTypeInput containsValue; + final FTextTypeInput filterName; + final FTextTypeInput filterValue; + final FTextTypeInput filterOperator; + final FTextTypeInput gtName; + final FTextTypeInput gtValue; + final FTextTypeInput gtEName; + final FTextTypeInput gtEValue; + final FTextTypeInput ltName; + final FTextTypeInput ltValue; + final FTextTypeInput ltEName; + final FTextTypeInput ltEValue; /// The opzional child of this widget final List children; @@ -80,6 +106,112 @@ class _WSupabaseFutureBuilderState extends State { } Future calc() async { + final ltEName = widget.ltEName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final ltEValue = widget.ltEValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final ltName = widget.ltName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final ltValue = widget.ltValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final gtEName = widget.gtEName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final gtEValue = widget.gtEValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final gtName = widget.gtName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final gtValue = widget.gtValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final filterName = widget.filterName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final filterValue = widget.filterValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + final filterOperator = widget.filterOperator.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + + final containName = widget.containsName.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); + + final containValue = widget.containsValue.get( + widget.state.params, + widget.state.states, + widget.state.dataset, + widget.state.forPlay, + widget.state.loop, + context, + ); final from = widget.from.get( widget.state.params, widget.state.states, @@ -176,6 +308,28 @@ class _WSupabaseFutureBuilderState extends State { if (order.isNotEmpty) { query.order(order, ascending: true); } + if (gtName.isNotEmpty) { + query.gt(gtName, gtValue); + } + + if (gtEName.isNotEmpty) { + query.gte(gtEName, gtEValue); + } + + if (ltName.isNotEmpty) { + query.lt(ltName, ltValue); + } + + if (ltEName.isNotEmpty) { + query.lte(ltEName, ltEValue); + } + + if (filterName.isNotEmpty) { + query.filter(filterName, filterOperator, filterValue); + } + if (containName.isNotEmpty) { + query.contains(containName, int.tryParse(containValue) ?? 0); + } if (searchName.isNotEmpty) { //query.textSearch(searchName, searchValue, type: TextSearchType.plain); query.ilike(searchName, '%$searchValue%'); diff --git a/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart b/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart index 501c8a8d..dfe55e34 100644 --- a/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart +++ b/teta_widgets/lib/src/elements/widgets/supabase/supabase_stream_builder.dart @@ -80,6 +80,7 @@ class _WSupabaseStreamBuilderState extends State { widget.state.loop, context, ); + final valueFromRange = int.tryParse(fromRange) != null ? int.parse(fromRange) : 0; @@ -90,6 +91,9 @@ class _WSupabaseStreamBuilderState extends State { if (order.isNotEmpty) { query.order(order, ascending: true); } + if (order.isNotEmpty) { + query.order(order, ascending: true); + } if (valueFromRange != 0) { query.limit(valueFromRange); } diff --git a/teta_widgets/lib/src/elements/widgets/supabase/user_is_logged.dart b/teta_widgets/lib/src/elements/widgets/supabase/user_is_logged.dart new file mode 100644 index 00000000..58ebe390 --- /dev/null +++ b/teta_widgets/lib/src/elements/widgets/supabase/user_is_logged.dart @@ -0,0 +1,92 @@ +// Flutter imports: +// Package imports: +// ignore_for_file: avoid_dynamic_calls + +// Flutter imports: +import 'package:flutter/material.dart'; +// Package imports: +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:supabase/supabase.dart'; +import 'package:teta_core/teta_core.dart'; +import 'package:teta_widgets/src/core/teta_widget/index.dart'; +// Project imports: +import 'package:teta_widgets/src/elements/index.dart'; + +// ignore_for_file: public_member_api_docs + +class WSupabaseUserIsLogged extends StatefulWidget { + /// Construct + const WSupabaseUserIsLogged( + final Key? key, { + required this.state, + required this.child, + }) : super(key: key); + + final TetaWidgetState state; + /// The opzional child of this widget + final CNode? child; + + @override + _WSupabaseUserIsLoggedState createState() => _WSupabaseUserIsLoggedState(); +} + +class _WSupabaseUserIsLoggedState extends State { + bool isLoaded = true; + Future>? _future; + SupabaseClient? client; + + @override + void initState() { + super.initState(); + client = BlocProvider.of(context).state; + _future = getUserMap(); + } + + Future> getUserMap() async { + final user = client!.auth.currentUser; + if (user == null) { + return {}; + } + return user.toJson(); + } + + @override + Widget build(final BuildContext context) { + if (client == null) { + return const Center( + child: THeadline3( + 'Supabase is not initialized yet', + ), + ); + } + + return NodeSelectionBuilder( + state: widget.state, + child: FutureBuilder>( + future: _future, + builder: (final context, final snapshot) { + if (snapshot.data == null) { + if (widget.child != null) { + return widget.child!.toWidget(state: widget.state); + } else { + return const Center( + child: CircularProgressIndicator(), + ); + } + } + + final data = snapshot.data!; + final datasets = addDataset(context, widget.state.dataset, + DatasetObject(name: 'Supabase Auth User', map: [data]),); + return widget.child!.toWidget( + state: widget.state.copyWith( + dataset: widget.state.dataset.isEmpty + ? datasets + : widget.state.dataset, + ), + ); + }, + ), + ); + } +} diff --git a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart index b546b9af..0d3fd211 100644 --- a/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart +++ b/teta_widgets/lib/src/elements/widgets/teta_cms/logged_user.dart @@ -70,7 +70,6 @@ class _WCMSLoggedUserState extends State { ); } } - final data = snapshot.data as TetaUser?; final map = { 'isLogged': data?.isLogged,