diff --git a/lib/src/commands/create/create_app_command.dart b/lib/src/commands/create/create_app_command.dart index 76d0f1d..af5350a 100644 --- a/lib/src/commands/create/create_app_command.dart +++ b/lib/src/commands/create/create_app_command.dart @@ -24,7 +24,7 @@ class CreateAppCommand extends Command { @override String get description => - 'Creates a stacked application with all the basics setup'; + 'Creates a Stacked application with all the basics setup.'; @override String get name => kTemplateNameApp; @@ -68,30 +68,30 @@ class CreateAppCommand extends Command { configFilePath: argResults![ksConfigPath], ); - final appName = argResults!.rest.first; - final appNameWithoutPath = appName.split('/').last; + final workingDirectory = argResults!.rest.first; + final appName = workingDirectory.split('/').last; final templateType = argResults![ksTemplateType]; - unawaited(_analyticsService.createAppEvent(name: appNameWithoutPath)); + unawaited(_analyticsService.createAppEvent(name: appName)); _processService.formattingLineLength = argResults![ksLineLength]; - await _processService.runCreateApp(appName: appName); + await _processService.runCreateApp(appName: workingDirectory); _log.stackedOutput(message: 'Add Stacked Magic ... ', isBold: true); await _templateService.renderTemplate( templateName: name, - name: appNameWithoutPath, + name: appName, verbose: true, - outputPath: appName, + outputPath: workingDirectory, useBuilder: argResults![ksV1] ?? _configService.v1, templateType: templateType, ); - _replaceConfigFile(appName: appName); - await _processService.runPubGet(appName: appName); - await _processService.runBuildRunner(appName: appName); - await _processService.runFormat(appName: appName); - await _clean(appName: appName); + _replaceConfigFile(appName: workingDirectory); + await _processService.runPubGet(appName: workingDirectory); + await _processService.runBuildRunner(workingDirectory: workingDirectory); + await _processService.runFormat(appName: workingDirectory); + await _clean(workingDirectory: workingDirectory); } catch (e) { _log.warn(message: e.toString()); } @@ -101,21 +101,21 @@ class CreateAppCommand extends Command { /// /// - Deletes widget_test.dart file /// - Removes unused imports - Future _clean({required String appName}) async { + Future _clean({required String workingDirectory}) async { _log.stackedOutput(message: 'Cleaning project...'); // Removes `widget_test` file to avoid failing unit tests on created app if (await _fileService.fileExists( - filePath: '$appName/test/widget_test.dart', + filePath: '$workingDirectory/test/widget_test.dart', )) { await _fileService.deleteFile( - filePath: '$appName/test/widget_test.dart', + filePath: '$workingDirectory/test/widget_test.dart', verbose: false, ); } // Analyze the project and return output lines - final issues = await _processService.runAnalyze(appName: appName); + final issues = await _processService.runAnalyze(appName: workingDirectory); for (var i in issues) { if (!i.endsWith('unused_import')) continue; @@ -123,7 +123,7 @@ class CreateAppCommand extends Command { final log = i.split(' • ')[2].split(':'); await _fileService.removeLinesOnFile( - filePath: '$appName/${log[0]}', + filePath: '$workingDirectory/${log[0]}', linesNumber: [int.parse(log[1])], ); } diff --git a/lib/src/commands/create/create_bottom_sheet_command.dart b/lib/src/commands/create/create_bottom_sheet_command.dart index b1f7ff7..39bf948 100644 --- a/lib/src/commands/create/create_bottom_sheet_command.dart +++ b/lib/src/commands/create/create_bottom_sheet_command.dart @@ -70,27 +70,27 @@ class CreateBottomSheetCommand extends Command with ProjectStructureValidator { final templateType = argResults![ksTemplateType]; unawaited( _analyticsService.createBottomSheetEvent(name: bottomSheetName)); - final outputPath = + final workingDirectory = argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults![ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); await _templateService.renderTemplate( templateName: name, name: bottomSheetName, - outputPath: outputPath, + outputPath: workingDirectory, verbose: true, excludeRoute: argResults![ksExcludeRoute], hasModel: argResults![ksModel], templateType: templateType, ); - await _processService.runBuildRunner(appName: outputPath); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } catch (e) { _log.warn(message: e.toString()); } diff --git a/lib/src/commands/create/create_command.dart b/lib/src/commands/create/create_command.dart index dcd1669..ee23ccc 100644 --- a/lib/src/commands/create/create_command.dart +++ b/lib/src/commands/create/create_command.dart @@ -5,6 +5,7 @@ import 'create_bottom_sheet_command.dart'; import 'create_dialog_command.dart'; import 'create_service_command.dart'; import 'create_view_command.dart'; +import 'create_widget_command.dart'; /// A command with subcommands that allows you to create / scaffold /// different parts of the stacked application @@ -17,10 +18,11 @@ class CreateCommand extends Command { String get name => 'create'; CreateCommand() { - addSubcommand(CreateViewCommand()); - addSubcommand(CreateServiceCommand()); addSubcommand(CreateAppCommand()); addSubcommand(CreateBottomSheetCommand()); addSubcommand(CreateDialogCommand()); + addSubcommand(CreateServiceCommand()); + addSubcommand(CreateViewCommand()); + addSubcommand(CreateWidgetCommand()); } } diff --git a/lib/src/commands/create/create_dialog_command.dart b/lib/src/commands/create/create_dialog_command.dart index 14d5881..90fbe76 100644 --- a/lib/src/commands/create/create_dialog_command.dart +++ b/lib/src/commands/create/create_dialog_command.dart @@ -69,27 +69,27 @@ class CreateDialogCommand extends Command with ProjectStructureValidator { final dialogName = argResults!.rest.first; final templateType = argResults![ksTemplateType]; unawaited(_analyticsService.createDialogEvent(name: dialogName)); - final outputPath = + final workingDirectory = argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults![ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); await _templateService.renderTemplate( templateName: name, name: dialogName, - outputPath: outputPath, + outputPath: workingDirectory, verbose: true, excludeRoute: argResults![ksExcludeRoute], hasModel: argResults![ksModel], templateType: templateType, ); - await _processService.runBuildRunner(appName: outputPath); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } catch (e) { _log.warn(message: e.toString()); } diff --git a/lib/src/commands/create/create_service_command.dart b/lib/src/commands/create/create_service_command.dart index 82d17a1..af5e7fb 100644 --- a/lib/src/commands/create/create_service_command.dart +++ b/lib/src/commands/create/create_service_command.dart @@ -64,25 +64,25 @@ class CreateServiceCommand extends Command with ProjectStructureValidator { final serviceName = argResults!.rest.first; final templateType = argResults![ksTemplateType]; unawaited(_analyticsService.createServiceEvent(name: serviceName)); - final outputPath = + final workingDirectory = argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults?[ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); await _templateService.renderTemplate( templateName: name, name: serviceName, - outputPath: outputPath, + outputPath: workingDirectory, verbose: true, excludeRoute: argResults![ksExcludeDependency], templateType: templateType, ); - await _processService.runBuildRunner(appName: outputPath); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } catch (e) { _log.warn(message: e.toString()); } diff --git a/lib/src/commands/create/create_view_command.dart b/lib/src/commands/create/create_view_command.dart index 69e51d5..19a3172 100644 --- a/lib/src/commands/create/create_view_command.dart +++ b/lib/src/commands/create/create_view_command.dart @@ -34,6 +34,7 @@ class CreateViewCommand extends Command with ProjectStructureValidator { defaultsTo: false, help: kCommandHelpExcludeRoute, ); + argParser.addFlag( ksV1, aliases: [ksUseBuilder], @@ -69,15 +70,15 @@ class CreateViewCommand extends Command with ProjectStructureValidator { final viewName = argResults!.rest.first; var templateType = argResults![ksTemplateType] as String?; unawaited(_analyticsService.createViewEvent(name: viewName)); - final outputPath = + final workingDirectory = argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults![ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); // Determine which template to use with the following rules: // 1. If the template is supplied we use that template @@ -88,13 +89,13 @@ class CreateViewCommand extends Command with ProjectStructureValidator { await _templateService.renderTemplate( templateName: name, name: viewName, - outputPath: outputPath, + outputPath: workingDirectory, verbose: true, excludeRoute: argResults![ksExcludeRoute], useBuilder: argResults![ksV1] ?? _configService.v1, templateType: templateType, ); - await _processService.runBuildRunner(appName: outputPath); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } catch (e) { _log.warn(message: e.toString()); } diff --git a/lib/src/commands/create/create_widget_command.dart b/lib/src/commands/create/create_widget_command.dart new file mode 100644 index 0000000..8646be2 --- /dev/null +++ b/lib/src/commands/create/create_widget_command.dart @@ -0,0 +1,90 @@ +import 'dart:async'; + +import 'package:args/command_runner.dart'; +import 'package:stacked_cli/src/constants/command_constants.dart'; +import 'package:stacked_cli/src/constants/message_constants.dart'; +import 'package:stacked_cli/src/locator.dart'; +import 'package:stacked_cli/src/mixins/project_structure_validator_mixin.dart'; +import 'package:stacked_cli/src/services/analytics_service.dart'; +import 'package:stacked_cli/src/services/colorized_log_service.dart'; +import 'package:stacked_cli/src/services/config_service.dart'; +import 'package:stacked_cli/src/services/process_service.dart'; +import 'package:stacked_cli/src/services/pubspec_service.dart'; +import 'package:stacked_cli/src/services/template_service.dart'; +import 'package:stacked_cli/src/templates/template_constants.dart'; + +class CreateWidgetCommand extends Command with ProjectStructureValidator { + final _log = locator(); + final _configService = locator(); + final _processService = locator(); + final _pubspecService = locator(); + final _templateService = locator(); + final _analyticsService = locator(); + + @override + String get description => 'Creates a widget with their model file.'; + + @override + String get name => kTemplateNameWidget; + + CreateWidgetCommand() { + argParser + ..addOption( + ksLineLength, + abbr: 'l', + help: kCommandHelpLineLength, + valueHelp: '80', + ) + ..addOption( + ksTemplateType, + abbr: 't', + // TODO (Create Widget Templates): Generate a constant with these values + // when running the compile command + allowed: ['empty'], + defaultsTo: 'empty', + help: kCommandHelpCreateWidgetTemplate, + ) + ..addOption( + ksConfigPath, + abbr: 'c', + help: kCommandHelpConfigFilePath, + ) + ..addFlag( + ksModel, + defaultsTo: true, + help: kCommandHelpModel, + ); + } + + @override + Future run() async { + try { + final widgetName = argResults!.rest.first; + final templateType = argResults![ksTemplateType]; + final workingDirectory = + argResults!.rest.length > 1 ? argResults!.rest[1] : null; + + await _configService.composeAndLoadConfigFile( + configFilePath: argResults![ksConfigPath], + projectPath: workingDirectory, + ); + + _processService.formattingLineLength = argResults![ksLineLength]; + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); + + await _templateService.renderTemplate( + templateName: name, + name: widgetName, + outputPath: workingDirectory, + verbose: true, + hasModel: argResults![ksModel], + templateType: templateType, + ); + + unawaited(_analyticsService.createWidgetEvent(name: widgetName)); + } catch (e) { + _log.warn(message: e.toString()); + } + } +} diff --git a/lib/src/commands/delete/delete_command.dart b/lib/src/commands/delete/delete_command.dart index 8a673d9..29be3e5 100644 --- a/lib/src/commands/delete/delete_command.dart +++ b/lib/src/commands/delete/delete_command.dart @@ -14,7 +14,7 @@ class DeleteCommand extends Command { String get name => 'delete'; DeleteCommand() { - addSubcommand(DeleteViewCommand()); addSubcommand(DeleteServiceCommand()); + addSubcommand(DeleteViewCommand()); } } diff --git a/lib/src/commands/delete/delete_service_command.dart b/lib/src/commands/delete/delete_service_command.dart index ec5fcb6..975094f 100644 --- a/lib/src/commands/delete/delete_service_command.dart +++ b/lib/src/commands/delete/delete_service_command.dart @@ -54,18 +54,19 @@ class DeleteServiceCommand extends Command with ProjectStructureValidator { unawaited(_analyticsService.deleteServiceEvent( name: argResults!.rest.first, )); - final outputPath = argResults!.rest.length > 1 ? argResults!.rest[1] : null; + final workingDirectory = + argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults?[ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); - await deleteServiceAndTestFiles(outputPath: outputPath); - await removeServiceFromTestHelper(outputPath: outputPath); - await removeServiceFromDependency(outputPath: outputPath); - await _processService.runBuildRunner(appName: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); + await deleteServiceAndTestFiles(outputPath: workingDirectory); + await removeServiceFromTestHelper(outputPath: workingDirectory); + await removeServiceFromDependency(outputPath: workingDirectory); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } /// It deletes the service and test files diff --git a/lib/src/commands/delete/delete_view_commad.dart b/lib/src/commands/delete/delete_view_commad.dart index 5e5222e..fa0a8d8 100644 --- a/lib/src/commands/delete/delete_view_commad.dart +++ b/lib/src/commands/delete/delete_view_commad.dart @@ -52,17 +52,18 @@ class DeleteViewCommand extends Command with ProjectStructureValidator { @override Future run() async { unawaited(_analyticsService.deleteViewEvent(name: argResults!.rest.first)); - final outputPath = argResults!.rest.length > 1 ? argResults!.rest[1] : null; + final workingDirectory = + argResults!.rest.length > 1 ? argResults!.rest[1] : null; await _configService.composeAndLoadConfigFile( configFilePath: argResults![ksConfigPath], - projectPath: outputPath, + projectPath: workingDirectory, ); _processService.formattingLineLength = argResults?[ksLineLength]; - await _pubspecService.initialise(workingDirectory: outputPath); - await validateStructure(outputPath: outputPath); - await deleteViewAndTestFiles(outputPath: outputPath); - await removeViewFromRoute(outputPath: outputPath); - await _processService.runBuildRunner(appName: outputPath); + await _pubspecService.initialise(workingDirectory: workingDirectory); + await validateStructure(outputPath: workingDirectory); + await deleteViewAndTestFiles(outputPath: workingDirectory); + await removeViewFromRoute(outputPath: workingDirectory); + await _processService.runBuildRunner(workingDirectory: workingDirectory); } /// It deletes the view and test files diff --git a/lib/src/commands/generate/generate_command.dart b/lib/src/commands/generate/generate_command.dart index 7911a7c..d8eb7ad 100644 --- a/lib/src/commands/generate/generate_command.dart +++ b/lib/src/commands/generate/generate_command.dart @@ -14,7 +14,7 @@ class GenerateCommand extends Command { @override String get description => - '''Generates the code for the stacked application if any changes were made'''; + '''Generates the code for the stacked application if any changes were made.'''; @override String get name => kTemplateNameGenerate; diff --git a/lib/src/commands/update/update_command.dart b/lib/src/commands/update/update_command.dart index 34f2674..d4d99e2 100644 --- a/lib/src/commands/update/update_command.dart +++ b/lib/src/commands/update/update_command.dart @@ -5,6 +5,7 @@ import 'package:stacked_cli/src/locator.dart'; import 'package:stacked_cli/src/services/analytics_service.dart'; import 'package:stacked_cli/src/services/process_service.dart'; import 'package:stacked_cli/src/services/pub_service.dart'; +import 'package:stacked_cli/src/templates/template_constants.dart'; class UpdateCommand extends Command { final _analyticsService = locator(); @@ -12,10 +13,10 @@ class UpdateCommand extends Command { final _pubService = locator(); @override - String get description => '''Updates stacked_cli to latest version'''; + String get description => '''Updates stacked_cli to latest version.'''; @override - String get name => 'update'; + String get name => kTemplateNameUpdate; @override Future run() async { diff --git a/lib/src/constants/message_constants.dart b/lib/src/constants/message_constants.dart index 7be67ce..d85e3b0 100644 --- a/lib/src/constants/message_constants.dart +++ b/lib/src/constants/message_constants.dart @@ -42,19 +42,22 @@ const String kCommandHelpLineLength = 'When a number is provided, it will be used as the line length for formatting code.'; const String kCommandHelpCreateAppTemplate = - 'Selects the type of starter template to use when creating a new app. One oriented for mobile first or web first'; + 'Selects the type of starter template to use when creating a new app. One oriented for mobile first or web first.'; const String kCommandHelpConfigFilePath = - 'Sets the file path for the custom config'; + 'Sets the file path for the custom config.'; const String kCommandHelpCreateViewTemplate = - 'Selects the type of view to create instead of the default empty view'; + 'Selects the type of view to create instead of the default empty view.'; + +const String kCommandHelpCreateWidgetTemplate = + 'Selects the type of widget to create instead of the default empty widget.'; const String kCommandHelpCreateDialogTemplate = - 'Selects the type of dialog to create instead of the default empty dialog'; + 'Selects the type of dialog to create instead of the default empty dialog.'; const String kCommandHelpCreateBottomSheetTemplate = - 'Selects the type of bottom sheet to create instead of the default empty bottom sheet'; + 'Selects the type of bottom sheet to create instead of the default empty bottom sheet.'; const String kCommandHelpExcludeDependency = 'When a service is excluded it will not be added to your app.dart dependencies collection.'; diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index 44161bf..40f0420 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -14,6 +14,11 @@ class Config with _$Config { /// Path where services will be genereated. @JsonKey(name: 'services_path') @Default('services') String servicesPath, + /// Path where widgets will be genereated. + @JsonKey(name: 'widgets_path') + @Default('ui/widgets/common') + String widgetsPath, + /// Path where bottom sheets will be genereated. @JsonKey(name: 'bottom_sheets_path') @Default('ui/bottom_sheets') @@ -63,6 +68,11 @@ class Config with _$Config { @Default('viewmodels') String testViewsPath, + /// Path where widget models unit tests will be genereated. + @JsonKey(name: 'test_widgets_path') + @Default('widget_models') + String testWidgetsPath, + /// The name of the locator to use when registering test mocks @JsonKey(name: 'locator_name') @Default('locator') String locatorName, diff --git a/lib/src/models/config_model.freezed.dart b/lib/src/models/config_model.freezed.dart index 5d0d668..a05d728 100644 --- a/lib/src/models/config_model.freezed.dart +++ b/lib/src/models/config_model.freezed.dart @@ -28,6 +28,10 @@ mixin _$Config { @JsonKey(name: 'services_path') String get servicesPath => throw _privateConstructorUsedError; + /// Path where widgets will be genereated. + @JsonKey(name: 'widgets_path') + String get widgetsPath => throw _privateConstructorUsedError; + /// Path where bottom sheets will be genereated. @JsonKey(name: 'bottom_sheets_path') String get bottomSheetsPath => throw _privateConstructorUsedError; @@ -69,6 +73,10 @@ mixin _$Config { @JsonKey(name: 'test_views_path') String get testViewsPath => throw _privateConstructorUsedError; + /// Path where widget models unit tests will be genereated. + @JsonKey(name: 'test_widgets_path') + String get testWidgetsPath => throw _privateConstructorUsedError; + /// The name of the locator to use when registering test mocks @JsonKey(name: 'locator_name') String get locatorName => throw _privateConstructorUsedError; @@ -106,6 +114,7 @@ abstract class $ConfigCopyWith<$Res> { $Res call( {@JsonKey(name: 'views_path') String viewsPath, @JsonKey(name: 'services_path') String servicesPath, + @JsonKey(name: 'widgets_path') String widgetsPath, @JsonKey(name: 'bottom_sheets_path') String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') String bottomSheetTypeFilePath, @@ -118,6 +127,7 @@ abstract class $ConfigCopyWith<$Res> { @JsonKey(name: 'test_helpers_file_path') String testHelpersFilePath, @JsonKey(name: 'test_services_path') String testServicesPath, @JsonKey(name: 'test_views_path') String testViewsPath, + @JsonKey(name: 'test_widgets_path') String testWidgetsPath, @JsonKey(name: 'locator_name') String locatorName, @JsonKey(name: 'register_mocks_function') String registerMocksFunction, @JsonKey(name: 'v1') bool v1, @@ -140,6 +150,7 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config> $Res call({ Object? viewsPath = null, Object? servicesPath = null, + Object? widgetsPath = null, Object? bottomSheetsPath = null, Object? bottomSheetTypeFilePath = null, Object? bottomSheetBuilderFilePath = null, @@ -150,6 +161,7 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config> Object? testHelpersFilePath = null, Object? testServicesPath = null, Object? testViewsPath = null, + Object? testWidgetsPath = null, Object? locatorName = null, Object? registerMocksFunction = null, Object? v1 = null, @@ -165,6 +177,10 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config> ? _value.servicesPath : servicesPath // ignore: cast_nullable_to_non_nullable as String, + widgetsPath: null == widgetsPath + ? _value.widgetsPath + : widgetsPath // ignore: cast_nullable_to_non_nullable + as String, bottomSheetsPath: null == bottomSheetsPath ? _value.bottomSheetsPath : bottomSheetsPath // ignore: cast_nullable_to_non_nullable @@ -205,6 +221,10 @@ class _$ConfigCopyWithImpl<$Res, $Val extends Config> ? _value.testViewsPath : testViewsPath // ignore: cast_nullable_to_non_nullable as String, + testWidgetsPath: null == testWidgetsPath + ? _value.testWidgetsPath + : testWidgetsPath // ignore: cast_nullable_to_non_nullable + as String, locatorName: null == locatorName ? _value.locatorName : locatorName // ignore: cast_nullable_to_non_nullable @@ -238,6 +258,7 @@ abstract class _$$_ConfigCopyWith<$Res> implements $ConfigCopyWith<$Res> { $Res call( {@JsonKey(name: 'views_path') String viewsPath, @JsonKey(name: 'services_path') String servicesPath, + @JsonKey(name: 'widgets_path') String widgetsPath, @JsonKey(name: 'bottom_sheets_path') String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') String bottomSheetTypeFilePath, @@ -250,6 +271,7 @@ abstract class _$$_ConfigCopyWith<$Res> implements $ConfigCopyWith<$Res> { @JsonKey(name: 'test_helpers_file_path') String testHelpersFilePath, @JsonKey(name: 'test_services_path') String testServicesPath, @JsonKey(name: 'test_views_path') String testViewsPath, + @JsonKey(name: 'test_widgets_path') String testWidgetsPath, @JsonKey(name: 'locator_name') String locatorName, @JsonKey(name: 'register_mocks_function') String registerMocksFunction, @JsonKey(name: 'v1') bool v1, @@ -269,6 +291,7 @@ class __$$_ConfigCopyWithImpl<$Res> $Res call({ Object? viewsPath = null, Object? servicesPath = null, + Object? widgetsPath = null, Object? bottomSheetsPath = null, Object? bottomSheetTypeFilePath = null, Object? bottomSheetBuilderFilePath = null, @@ -279,6 +302,7 @@ class __$$_ConfigCopyWithImpl<$Res> Object? testHelpersFilePath = null, Object? testServicesPath = null, Object? testViewsPath = null, + Object? testWidgetsPath = null, Object? locatorName = null, Object? registerMocksFunction = null, Object? v1 = null, @@ -294,6 +318,10 @@ class __$$_ConfigCopyWithImpl<$Res> ? _value.servicesPath : servicesPath // ignore: cast_nullable_to_non_nullable as String, + widgetsPath: null == widgetsPath + ? _value.widgetsPath + : widgetsPath // ignore: cast_nullable_to_non_nullable + as String, bottomSheetsPath: null == bottomSheetsPath ? _value.bottomSheetsPath : bottomSheetsPath // ignore: cast_nullable_to_non_nullable @@ -334,6 +362,10 @@ class __$$_ConfigCopyWithImpl<$Res> ? _value.testViewsPath : testViewsPath // ignore: cast_nullable_to_non_nullable as String, + testWidgetsPath: null == testWidgetsPath + ? _value.testWidgetsPath + : testWidgetsPath // ignore: cast_nullable_to_non_nullable + as String, locatorName: null == locatorName ? _value.locatorName : locatorName // ignore: cast_nullable_to_non_nullable @@ -364,6 +396,7 @@ class _$_Config implements _Config { _$_Config( {@JsonKey(name: 'views_path') this.viewsPath = 'ui/views', @JsonKey(name: 'services_path') this.servicesPath = 'services', + @JsonKey(name: 'widgets_path') this.widgetsPath = 'ui/widgets/common', @JsonKey(name: 'bottom_sheets_path') this.bottomSheetsPath = 'ui/bottom_sheets', @JsonKey(name: 'bottom_sheet_type_file_path') @@ -381,6 +414,8 @@ class _$_Config implements _Config { this.testHelpersFilePath = 'helpers/test_helpers.dart', @JsonKey(name: 'test_services_path') this.testServicesPath = 'services', @JsonKey(name: 'test_views_path') this.testViewsPath = 'viewmodels', + @JsonKey(name: 'test_widgets_path') + this.testWidgetsPath = 'widget_models', @JsonKey(name: 'locator_name') this.locatorName = 'locator', @JsonKey(name: 'register_mocks_function') this.registerMocksFunction = 'registerServices', @@ -401,6 +436,11 @@ class _$_Config implements _Config { @JsonKey(name: 'services_path') final String servicesPath; + /// Path where widgets will be genereated. + @override + @JsonKey(name: 'widgets_path') + final String widgetsPath; + /// Path where bottom sheets will be genereated. @override @JsonKey(name: 'bottom_sheets_path') @@ -452,6 +492,11 @@ class _$_Config implements _Config { @JsonKey(name: 'test_views_path') final String testViewsPath; + /// Path where widget models unit tests will be genereated. + @override + @JsonKey(name: 'test_widgets_path') + final String testWidgetsPath; + /// The name of the locator to use when registering test mocks @override @JsonKey(name: 'locator_name') @@ -483,7 +528,7 @@ class _$_Config implements _Config { @override String toString() { - return 'Config(viewsPath: $viewsPath, servicesPath: $servicesPath, bottomSheetsPath: $bottomSheetsPath, bottomSheetTypeFilePath: $bottomSheetTypeFilePath, bottomSheetBuilderFilePath: $bottomSheetBuilderFilePath, dialogsPath: $dialogsPath, dialogTypeFilePath: $dialogTypeFilePath, dialogBuilderFilePath: $dialogBuilderFilePath, stackedAppFilePath: $stackedAppFilePath, testHelpersFilePath: $testHelpersFilePath, testServicesPath: $testServicesPath, testViewsPath: $testViewsPath, locatorName: $locatorName, registerMocksFunction: $registerMocksFunction, v1: $v1, lineLength: $lineLength, preferWeb: $preferWeb)'; + return 'Config(viewsPath: $viewsPath, servicesPath: $servicesPath, widgetsPath: $widgetsPath, bottomSheetsPath: $bottomSheetsPath, bottomSheetTypeFilePath: $bottomSheetTypeFilePath, bottomSheetBuilderFilePath: $bottomSheetBuilderFilePath, dialogsPath: $dialogsPath, dialogTypeFilePath: $dialogTypeFilePath, dialogBuilderFilePath: $dialogBuilderFilePath, stackedAppFilePath: $stackedAppFilePath, testHelpersFilePath: $testHelpersFilePath, testServicesPath: $testServicesPath, testViewsPath: $testViewsPath, testWidgetsPath: $testWidgetsPath, locatorName: $locatorName, registerMocksFunction: $registerMocksFunction, v1: $v1, lineLength: $lineLength, preferWeb: $preferWeb)'; } @override @@ -495,6 +540,8 @@ class _$_Config implements _Config { other.viewsPath == viewsPath) && (identical(other.servicesPath, servicesPath) || other.servicesPath == servicesPath) && + (identical(other.widgetsPath, widgetsPath) || + other.widgetsPath == widgetsPath) && (identical(other.bottomSheetsPath, bottomSheetsPath) || other.bottomSheetsPath == bottomSheetsPath) && (identical( @@ -518,6 +565,8 @@ class _$_Config implements _Config { other.testServicesPath == testServicesPath) && (identical(other.testViewsPath, testViewsPath) || other.testViewsPath == testViewsPath) && + (identical(other.testWidgetsPath, testWidgetsPath) || + other.testWidgetsPath == testWidgetsPath) && (identical(other.locatorName, locatorName) || other.locatorName == locatorName) && (identical(other.registerMocksFunction, registerMocksFunction) || @@ -531,25 +580,28 @@ class _$_Config implements _Config { @JsonKey(ignore: true) @override - int get hashCode => Object.hash( - runtimeType, - viewsPath, - servicesPath, - bottomSheetsPath, - bottomSheetTypeFilePath, - bottomSheetBuilderFilePath, - dialogsPath, - dialogTypeFilePath, - dialogBuilderFilePath, - stackedAppFilePath, - testHelpersFilePath, - testServicesPath, - testViewsPath, - locatorName, - registerMocksFunction, - v1, - lineLength, - preferWeb); + int get hashCode => Object.hashAll([ + runtimeType, + viewsPath, + servicesPath, + widgetsPath, + bottomSheetsPath, + bottomSheetTypeFilePath, + bottomSheetBuilderFilePath, + dialogsPath, + dialogTypeFilePath, + dialogBuilderFilePath, + stackedAppFilePath, + testHelpersFilePath, + testServicesPath, + testViewsPath, + testWidgetsPath, + locatorName, + registerMocksFunction, + v1, + lineLength, + preferWeb + ]); @JsonKey(ignore: true) @override @@ -569,6 +621,7 @@ abstract class _Config implements Config { factory _Config( {@JsonKey(name: 'views_path') final String viewsPath, @JsonKey(name: 'services_path') final String servicesPath, + @JsonKey(name: 'widgets_path') final String widgetsPath, @JsonKey(name: 'bottom_sheets_path') final String bottomSheetsPath, @JsonKey(name: 'bottom_sheet_type_file_path') final String bottomSheetTypeFilePath, @@ -582,6 +635,7 @@ abstract class _Config implements Config { @JsonKey(name: 'test_helpers_file_path') final String testHelpersFilePath, @JsonKey(name: 'test_services_path') final String testServicesPath, @JsonKey(name: 'test_views_path') final String testViewsPath, + @JsonKey(name: 'test_widgets_path') final String testWidgetsPath, @JsonKey(name: 'locator_name') final String locatorName, @JsonKey(name: 'register_mocks_function') final String registerMocksFunction, @@ -603,6 +657,11 @@ abstract class _Config implements Config { String get servicesPath; @override + /// Path where widgets will be genereated. + @JsonKey(name: 'widgets_path') + String get widgetsPath; + @override + /// Path where bottom sheets will be genereated. @JsonKey(name: 'bottom_sheets_path') String get bottomSheetsPath; @@ -654,6 +713,11 @@ abstract class _Config implements Config { String get testViewsPath; @override + /// Path where widget models unit tests will be genereated. + @JsonKey(name: 'test_widgets_path') + String get testWidgetsPath; + @override + /// The name of the locator to use when registering test mocks @JsonKey(name: 'locator_name') String get locatorName; diff --git a/lib/src/models/config_model.g.dart b/lib/src/models/config_model.g.dart index dc08add..e1a5b00 100644 --- a/lib/src/models/config_model.g.dart +++ b/lib/src/models/config_model.g.dart @@ -9,6 +9,7 @@ part of 'config_model.dart'; _$_Config _$$_ConfigFromJson(Map json) => _$_Config( viewsPath: json['views_path'] as String? ?? 'ui/views', servicesPath: json['services_path'] as String? ?? 'services', + widgetsPath: json['widgets_path'] as String? ?? 'ui/widgets/common', bottomSheetsPath: json['bottom_sheets_path'] as String? ?? 'ui/bottom_sheets', bottomSheetTypeFilePath: json['bottom_sheet_type_file_path'] as String? ?? @@ -27,6 +28,7 @@ _$_Config _$$_ConfigFromJson(Map json) => _$_Config( 'helpers/test_helpers.dart', testServicesPath: json['test_services_path'] as String? ?? 'services', testViewsPath: json['test_views_path'] as String? ?? 'viewmodels', + testWidgetsPath: json['test_widgets_path'] as String? ?? 'widget_models', locatorName: json['locator_name'] as String? ?? 'locator', registerMocksFunction: json['register_mocks_function'] as String? ?? 'registerServices', @@ -38,6 +40,7 @@ _$_Config _$$_ConfigFromJson(Map json) => _$_Config( Map _$$_ConfigToJson(_$_Config instance) => { 'views_path': instance.viewsPath, 'services_path': instance.servicesPath, + 'widgets_path': instance.widgetsPath, 'bottom_sheets_path': instance.bottomSheetsPath, 'bottom_sheet_type_file_path': instance.bottomSheetTypeFilePath, 'bottom_sheet_builder_file_path': instance.bottomSheetBuilderFilePath, @@ -48,6 +51,7 @@ Map _$$_ConfigToJson(_$_Config instance) => { 'test_helpers_file_path': instance.testHelpersFilePath, 'test_services_path': instance.testServicesPath, 'test_views_path': instance.testViewsPath, + 'test_widgets_path': instance.testWidgetsPath, 'locator_name': instance.locatorName, 'register_mocks_function': instance.registerMocksFunction, 'v1': instance.v1, diff --git a/lib/src/services/analytics_service.dart b/lib/src/services/analytics_service.dart index 588abcb..e79bff4 100644 --- a/lib/src/services/analytics_service.dart +++ b/lib/src/services/analytics_service.dart @@ -96,6 +96,18 @@ class AnalyticsService { await _waitLastPingOrCloseAtTimeout(); } + /// Sends create widget command event + Future createWidgetEvent({required String name}) async { + final version = await locator().getCurrentVersion(); + await _analytics.sendEvent( + 'command', + 'create', + label: 'widget', + parameters: {kcdVersion: version, kcdName: name}, + ); + await _waitLastPingOrCloseAtTimeout(); + } + /// Sends delete service command event Future deleteServiceEvent({required String name}) async { final version = await locator().getCurrentVersion(); diff --git a/lib/src/services/config_service.dart b/lib/src/services/config_service.dart index 32c4e11..3a59048 100644 --- a/lib/src/services/config_service.dart +++ b/lib/src/services/config_service.dart @@ -87,6 +87,14 @@ class ConfigService { _customConfig.testViewsPath, ); + /// Relative path where widgets will be genereated. + String get widgetPath => _customConfig.widgetsPath; + + /// Relative import path related to widget models of test helpers and mock services. + String get widgetTestHelpersImport => getFilePathToHelpersAndMocks( + _customConfig.testWidgetsPath, + ); + /// Returns boolean value to determine view builder style. /// /// False: StackedView diff --git a/lib/src/services/process_service.dart b/lib/src/services/process_service.dart index a8b9d22..2a38427 100644 --- a/lib/src/services/process_service.dart +++ b/lib/src/services/process_service.dart @@ -39,7 +39,7 @@ class ProcessService { /// Args: /// appName (String): The name of the app. Future runBuildRunner({ - String? appName, + String? workingDirectory, bool shouldWatch = false, bool shouldDeleteConflictingOutputs = true, }) async { @@ -50,7 +50,7 @@ class ProcessService { shouldWatch ? ksWatch : ksBuild, if (shouldDeleteConflictingOutputs) ksDeleteConflictingOutputs, ], - workingDirectory: appName, + workingDirectory: workingDirectory, ); } diff --git a/lib/src/services/template_service.dart b/lib/src/services/template_service.dart index 9b80ab7..170bca3 100644 --- a/lib/src/services/template_service.dart +++ b/lib/src/services/template_service.dart @@ -125,6 +125,8 @@ class TemplateService { /// The name to use for the views when generating the view template required String name, + + /// When value is true, should log on stdout what is happening during command execution. bool verbose = false, /// When set to true the newly generated view will not be added to the app.dart file @@ -206,17 +208,19 @@ class TemplateService { } } - if (templateName == 'bottom_sheet' || templateName == 'dialog') { + const templatesAllowed = ['bottom_sheet', 'dialog', 'widget']; + if (templatesAllowed.any((template) => template == templateName)) { if (!hasModel && templateFile.relativeOutputPath.contains('model')) { continue; } if (templateFile.relativeOutputPath.contains('_use_model.dart.stk')) { template.templateFiles[i + 2] = TemplateFile( - relativeOutputPath: - template.templateFiles[i + 2].relativeOutputPath, - content: templateFile.content, - fileType: FileType.text); + relativeOutputPath: + template.templateFiles[i + 2].relativeOutputPath, + content: templateFile.content, + fileType: FileType.text, + ); continue; } @@ -347,6 +351,8 @@ class TemplateService { kTemplatePropertyDialogBuilderFilePath: _configService.dialogBuilderFilePath, kTemplatePropertyDialogTypeFilePath: _configService.dialogTypeFilePath, + kTemplatePropertyWidgetTestHelpersImport: + _configService.widgetTestHelpersImport, }; } diff --git a/lib/src/templates/app/mobile/lib/ui/common/ui_helpers.dart.stk b/lib/src/templates/app/mobile/lib/ui/common/ui_helpers.dart.stk index 6a654bf..9c35f03 100644 --- a/lib/src/templates/app/mobile/lib/ui/common/ui_helpers.dart.stk +++ b/lib/src/templates/app/mobile/lib/ui/common/ui_helpers.dart.stk @@ -19,8 +19,8 @@ const Widget verticalSpaceMedium = SizedBox(height: _mediumSize); const Widget verticalSpaceLarge = SizedBox(height: _largeSize); const Widget verticalSpaceMassive = SizedBox(height: _massiveSize); -Widget spacedDivider = Column( - children: const [ +Widget spacedDivider = const Column( + children: [ verticalSpaceMedium, Divider(color: Colors.blueGrey, height: 5.0), verticalSpaceMedium, diff --git a/lib/src/templates/app/mobile/lib/ui/views/startup/startup_view.dart.stk b/lib/src/templates/app/mobile/lib/ui/views/startup/startup_view.dart.stk index c16bf02..9edb798 100644 --- a/lib/src/templates/app/mobile/lib/ui/views/startup/startup_view.dart.stk +++ b/lib/src/templates/app/mobile/lib/ui/views/startup/startup_view.dart.stk @@ -14,27 +14,19 @@ class StartupView extends StackedView { StartupViewModel viewModel, Widget? child, ) { - return Scaffold( + return const Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + Text( 'STACKED', - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.w900, - ), + style: TextStyle(fontSize: 40, fontWeight: FontWeight.w900), ), Row( mainAxisSize: MainAxisSize.min, - children: const [ - Text( - 'Loading ...', - style: TextStyle( - fontSize: 16, - ), - ), + children: [ + Text('Loading ...', style: TextStyle(fontSize: 16)), horizontalSpaceSmall, SizedBox( width: 16, diff --git a/lib/src/templates/app/mobile/stacked.json.stk b/lib/src/templates/app/mobile/stacked.json.stk index 50ef70a..1be3305 100644 --- a/lib/src/templates/app/mobile/stacked.json.stk +++ b/lib/src/templates/app/mobile/stacked.json.stk @@ -1,18 +1,21 @@ { - "stacked_app_file_path": "app/app.dart", - "services_path": "services", - "views_path": "ui/views", - "bottom_sheets_path": "ui/bottom_sheets", - "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", "bottom_sheet_builder_file_path": "ui/setup/setup_bottom_sheet_ui.dart", - "dialogs_path": "ui/dialogs", - "dialog_type_file_path": "enums/dialog_type.dart", + "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", + "bottom_sheets_path": "ui/bottom_sheets", "dialog_builder_file_path": "ui/setup/setup_dialog_ui.dart", + "dialog_type_file_path": "enums/dialog_type.dart", + "dialogs_path": "ui/dialogs", + "line_length": 80, + "locator_name": "locator", + "prefer_web": false, + "register_mocks_function": "registerServices", + "services_path": "services", + "stacked_app_file_path": "app/app.dart", "test_helpers_file_path": "helpers/test_helpers.dart", "test_services_path": "services", "test_views_path": "viewmodels", - "locator_name": "locator", - "register_mocks_function": "registerServices", + "test_widgets_path": "widget_models", "v1": false, - "line_length": 80 + "views_path": "ui/views", + "widgets_path": "ui/widgets/common" } \ No newline at end of file diff --git a/lib/src/templates/app/web/lib/ui/common/ui_helpers.dart.stk b/lib/src/templates/app/web/lib/ui/common/ui_helpers.dart.stk index 6a654bf..9c35f03 100644 --- a/lib/src/templates/app/web/lib/ui/common/ui_helpers.dart.stk +++ b/lib/src/templates/app/web/lib/ui/common/ui_helpers.dart.stk @@ -19,8 +19,8 @@ const Widget verticalSpaceMedium = SizedBox(height: _mediumSize); const Widget verticalSpaceLarge = SizedBox(height: _largeSize); const Widget verticalSpaceMassive = SizedBox(height: _massiveSize); -Widget spacedDivider = Column( - children: const [ +Widget spacedDivider = const Column( + children: [ verticalSpaceMedium, Divider(color: Colors.blueGrey, height: 5.0), verticalSpaceMedium, diff --git a/lib/src/templates/app/web/lib/ui/views/startup/startup_view.dart.stk b/lib/src/templates/app/web/lib/ui/views/startup/startup_view.dart.stk index c16bf02..9edb798 100644 --- a/lib/src/templates/app/web/lib/ui/views/startup/startup_view.dart.stk +++ b/lib/src/templates/app/web/lib/ui/views/startup/startup_view.dart.stk @@ -14,27 +14,19 @@ class StartupView extends StackedView { StartupViewModel viewModel, Widget? child, ) { - return Scaffold( + return const Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + Text( 'STACKED', - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.w900, - ), + style: TextStyle(fontSize: 40, fontWeight: FontWeight.w900), ), Row( mainAxisSize: MainAxisSize.min, - children: const [ - Text( - 'Loading ...', - style: TextStyle( - fontSize: 16, - ), - ), + children: [ + Text('Loading ...', style: TextStyle(fontSize: 16)), horizontalSpaceSmall, SizedBox( width: 16, diff --git a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.desktop.dart.stk b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.desktop.dart.stk index 6bfa2bc..361128e 100644 --- a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.desktop.dart.stk +++ b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.desktop.dart.stk @@ -10,12 +10,12 @@ class UnknownViewDesktop extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( diff --git a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.mobile.dart.stk b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.mobile.dart.stk index 62f52df..540bb93 100644 --- a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.mobile.dart.stk +++ b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.mobile.dart.stk @@ -10,12 +10,12 @@ class UnknownViewMobile extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( diff --git a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.tablet.dart.stk b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.tablet.dart.stk index a487b87..f5e5ea1 100644 --- a/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.tablet.dart.stk +++ b/lib/src/templates/app/web/lib/ui/views/unknown/unknown_view.tablet.dart.stk @@ -10,12 +10,12 @@ class UnknownViewTablet extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( diff --git a/lib/src/templates/app/web/stacked.json.stk b/lib/src/templates/app/web/stacked.json.stk index 6826b32..9dc2f24 100644 --- a/lib/src/templates/app/web/stacked.json.stk +++ b/lib/src/templates/app/web/stacked.json.stk @@ -1,19 +1,21 @@ { - "stacked_app_file_path": "app/app.dart", - "services_path": "services", - "views_path": "ui/views", - "bottom_sheets_path": "ui/bottom_sheets", - "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", "bottom_sheet_builder_file_path": "ui/setup/setup_bottom_sheet_ui.dart", - "dialogs_path": "ui/dialogs", - "dialog_type_file_path": "enums/dialog_type.dart", + "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", + "bottom_sheets_path": "ui/bottom_sheets", "dialog_builder_file_path": "ui/setup/setup_dialog_ui.dart", + "dialog_type_file_path": "enums/dialog_type.dart", + "dialogs_path": "ui/dialogs", + "line_length": 80, + "locator_name": "locator", + "prefer_web": true, + "register_mocks_function": "registerServices", + "services_path": "services", + "stacked_app_file_path": "app/app.dart", "test_helpers_file_path": "helpers/test_helpers.dart", "test_services_path": "services", "test_views_path": "viewmodels", - "locator_name": "locator", - "register_mocks_function": "registerServices", + "test_widgets_path": "widget_models", "v1": false, - "line_length": 80, - "prefer_web": true -} + "views_path": "ui/views", + "widgets_path": "ui/widgets/common" +} \ No newline at end of file diff --git a/lib/src/templates/compiled_template_map.dart b/lib/src/templates/compiled_template_map.dart index cf07dff..6a245c6 100644 --- a/lib/src/templates/compiled_template_map.dart +++ b/lib/src/templates/compiled_template_map.dart @@ -260,6 +260,29 @@ Map> kCompiledStackedTemplates = { modificationFiles: [], ), }, + 'widget': { + 'empty': StackedTemplate( + templateFiles: [ + TemplateFile( + relativeOutputPath: kWidgetEmptyTemplateGenericModelTestPath, + content: kWidgetEmptyTemplateGenericModelTestContent, + fileType: FileType.text), + TemplateFile( + relativeOutputPath: kWidgetEmptyTemplateGenericUseModelPath, + content: kWidgetEmptyTemplateGenericUseModelContent, + fileType: FileType.text), + TemplateFile( + relativeOutputPath: kWidgetEmptyTemplateGenericPath, + content: kWidgetEmptyTemplateGenericContent, + fileType: FileType.text), + TemplateFile( + relativeOutputPath: kWidgetEmptyTemplateGenericModelPath, + content: kWidgetEmptyTemplateGenericModelContent, + fileType: FileType.text), + ], + modificationFiles: [], + ), + }, 'dialog': { 'empty': StackedTemplate( templateFiles: [ @@ -285,21 +308,18 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-dialog', modificationTemplate: '''StackedDialog(classType: {{dialogName}}),''', - modificationProblemError: - 'The dialog registration should be stored in lib/app/app.dart', - modificationName: - 'Add \'{{dialogName}}\' dependency to StackedApp annotations file', + modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart', + modificationName: 'Add \'{{dialogName}}\' dependency to StackedApp annotations file', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''', - modificationProblemError: - 'The dialog registration should be stored in lib/app/app.dart', + modificationTemplate: '''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''', + modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart', modificationName: 'Add import for \'{{dialogName}}\' class', ), - ], + ], ), }, 'view': { @@ -327,22 +347,18 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-route', modificationTemplate: '''MaterialRoute(page: {{viewName}}),''', - modificationProblemError: - 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: - 'Add {{viewName}} route where @StackedApp annotation is located', + modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: 'Add {{viewName}} route where @StackedApp annotation is located', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', - modificationProblemError: - 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: - 'Add {{viewName}} route import where @StackedApp annotation is located', + modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', + modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located', ), - ], + ], ), 'web': StackedTemplate( templateFiles: [ @@ -376,22 +392,18 @@ Map> kCompiledStackedTemplates = { relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-route', modificationTemplate: '''CustomRoute(page: {{viewName}}),''', - modificationProblemError: - 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: - 'Add {{viewName}} route where @StackedApp annotation is located', + modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: 'Add {{viewName}} route where @StackedApp annotation is located', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', - modificationProblemError: - 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', - modificationName: - 'Add {{viewName}} route import where @StackedApp annotation is located', + modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''', + modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/', + modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located', ), - ], + ], ), }, 'service': { @@ -410,72 +422,63 @@ Map> kCompiledStackedTemplates = { ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-create', - modificationTemplate: - '''Mock{{serviceName}} getAndRegister{{serviceName}}() { + modificationTemplate: '''Mock{{serviceName}} getAndRegister{{serviceName}}() { _removeRegistrationIfExists<{{serviceName}}>(); final service = Mock{{serviceName}}(); {{locatorName}}.registerSingleton<{{serviceName}}>(service); return service; }''', - modificationProblemError: - 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Add {{serviceName}} mock to test helpers', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-service', - modificationTemplate: - '''LazySingleton(classType: {{serviceName}}),''', - modificationProblemError: - 'The service registration should be stored in lib/app/app.dart', - modificationName: - 'Add {{serviceName}} dependency to StackedApp annotations file', + modificationTemplate: '''LazySingleton(classType: {{serviceName}}),''', + modificationProblemError: 'The service registration should be stored in lib/app/app.dart', + modificationName: 'Add {{serviceName}} dependency to StackedApp annotations file', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', - modificationProblemError: - 'The service registration should be stored in lib/app/app.dart', - modificationName: - 'Add {{serviceName}} import to StackedApp annotations file', + modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', + modificationProblemError: 'The service registration should be stored in lib/app/app.dart', + modificationName: 'Add {{serviceName}} import to StackedApp annotations file', ), + ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-spec', - modificationTemplate: - '''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''', - modificationProblemError: - 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationTemplate: '''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''', + modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Create {{serviceName}} mock to test helpers', ), + ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-mock-register', modificationTemplate: '''getAndRegister{{serviceName}}();''', - modificationProblemError: - 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', + modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart', modificationName: 'Add {{serviceName}} register to test helpers', ), + ModificationFile( relativeModificationPath: 'test/helpers/test_helpers.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', - modificationProblemError: - 'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file', + modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''', + modificationProblemError: 'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file', modificationName: 'Add {{serviceName}} import to test helpers', ), - ], + ], ), }, 'bottom_sheet': { 'empty': StackedTemplate( templateFiles: [ TemplateFile( - relativeOutputPath: - kBottomSheetEmptyTemplateGenericSheetModelTestPath, + relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetModelTestPath, content: kBottomSheetEmptyTemplateGenericSheetModelTestContent, fileType: FileType.text), TemplateFile( @@ -483,8 +486,7 @@ return service; content: kBottomSheetEmptyTemplateGenericSheetModelContent, fileType: FileType.text), TemplateFile( - relativeOutputPath: - kBottomSheetEmptyTemplateGenericSheetUseModelPath, + relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetUseModelPath, content: kBottomSheetEmptyTemplateGenericSheetUseModelContent, fileType: FileType.text), TemplateFile( @@ -496,23 +498,19 @@ return service; ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-bottom-sheet', - modificationTemplate: - '''StackedBottomsheet(classType: {{sheetName}}),''', - modificationProblemError: - 'The bottom sheet registration should be stored in lib/app/app.dart', - modificationName: - 'Add \'{{sheetName}}\' dependency to StackedApp annotations file', + modificationTemplate: '''StackedBottomsheet(classType: {{sheetName}}),''', + modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart', + modificationName: 'Add \'{{sheetName}}\' dependency to StackedApp annotations file', ), + ModificationFile( relativeModificationPath: 'lib/app/app.dart', modificationIdentifier: '// @stacked-import', - modificationTemplate: - '''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''', - modificationProblemError: - 'The bottom sheet registration should be stored in lib/app/app.dart', + modificationTemplate: '''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''', + modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart', modificationName: 'Add import for \'{{sheetName}}\' class', ), - ], + ], ), }, }; diff --git a/lib/src/templates/compiled_templates.dart b/lib/src/templates/compiled_templates.dart index dfb1cf7..221fdca 100644 --- a/lib/src/templates/compiled_templates.dart +++ b/lib/src/templates/compiled_templates.dart @@ -1,35 +1,39 @@ /// NOTE: This is generated code from the compileTemplates command. Do not modify by hand /// This file should be checked into source control. + // -------- StackedJsonStk Template Data ---------- -const String kAppWebTemplateStackedJsonStkPath = 'stacked.json.stk'; +const String kAppWebTemplateStackedJsonStkPath = + 'stacked.json.stk'; const String kAppWebTemplateStackedJsonStkContent = ''' { - "stacked_app_file_path": "app/app.dart", - "services_path": "services", - "views_path": "ui/views", - "bottom_sheets_path": "ui/bottom_sheets", - "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", "bottom_sheet_builder_file_path": "ui/setup/setup_bottom_sheet_ui.dart", - "dialogs_path": "ui/dialogs", - "dialog_type_file_path": "enums/dialog_type.dart", + "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", + "bottom_sheets_path": "ui/bottom_sheets", "dialog_builder_file_path": "ui/setup/setup_dialog_ui.dart", + "dialog_type_file_path": "enums/dialog_type.dart", + "dialogs_path": "ui/dialogs", + "line_length": 80, + "locator_name": "locator", + "prefer_web": true, + "register_mocks_function": "registerServices", + "services_path": "services", + "stacked_app_file_path": "app/app.dart", "test_helpers_file_path": "helpers/test_helpers.dart", "test_services_path": "services", "test_views_path": "viewmodels", - "locator_name": "locator", - "register_mocks_function": "registerServices", + "test_widgets_path": "widget_models", "v1": false, - "line_length": 80, - "prefer_web": true + "views_path": "ui/views", + "widgets_path": "ui/widgets/common" } - '''; // -------------------------------------------------- + // -------- UnknownViewmodelTest Template Data ---------- const String kAppWebTemplateUnknownViewmodelTestPath = @@ -51,6 +55,7 @@ void main() { // -------------------------------------------------- + // -------- HomeViewmodelTest Template Data ---------- const String kAppWebTemplateHomeViewmodelTestPath = @@ -102,6 +107,7 @@ void main() { // -------------------------------------------------- + // -------- NoticeSheetModelTest Template Data ---------- const String kAppWebTemplateNoticeSheetModelTestPath = @@ -124,6 +130,7 @@ void main() { // -------------------------------------------------- + // -------- InfoAlertDialogModelTest Template Data ---------- const String kAppWebTemplateInfoAlertDialogModelTestPath = @@ -146,6 +153,7 @@ void main() { // -------------------------------------------------- + // -------- TestHelpers Template Data ---------- const String kAppWebTemplateTestHelpersPath = @@ -235,9 +243,11 @@ void _removeRegistrationIfExists() { // -------------------------------------------------- + // -------- BuildYamlStk Template Data ---------- -const String kAppWebTemplateBuildYamlStkPath = 'build.yaml.stk'; +const String kAppWebTemplateBuildYamlStkPath = + 'build.yaml.stk'; const String kAppWebTemplateBuildYamlStkContent = ''' targets: @@ -250,9 +260,11 @@ targets: // -------------------------------------------------- + // -------- MainIconPngStk Template Data ---------- -const String kAppWebTemplateMainIconPngStkPath = 'web/main-icon.png.stk'; +const String kAppWebTemplateMainIconPngStkPath = + 'web/main-icon.png.stk'; const String kAppWebTemplateMainIconPngStkContent = ''' iVBORw0KGgoAAAANSUhEUgAAALMAAACzCAYAAADCFC3zAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAN5SURBVHgB7daLjVNBDEDRF0QjVEIrdMLSAS3RyZZAByGWdqUQ5Z/5eGbOkSw3cC152wAAAAAAAAAAAAAAAACAjHZbYfuDDW77tdvt3raCvmzQXvGQg5hprUrIQcy0VC3kIGZaqRpyEDMtVA85iJnamoQcxExNzUIOYqaWpiEHMVND85CDmCmtS8hBzJTULeQgZkrpGnIQMyV0DzmImVelCDmImVekCTmImWelCjmImWekCzmImUelDDmImUekDTmImXulDjmImXukDzmImVuGCDmImWuGCTmImUuGCjmImXOGCzmImVNDhhzEzLFhQw5i5tPQIQcxE4YPOYiZKUIOYl7bNCEHMa9rqpCDmNc0XchBzOuZMuQg5rVMG3IQ8zqmDjmIeQ3ThxzEPL8lQg5intsyIQcxz2upkIOY57RcyEHM81ky5CDmuSwbchDzPJYOOYh5DsuHHMQ8PiF/EPPYhHxEzOMS8gkxj0nIZ4h5PEK+QMxjEfIVYh6HkG8Q8xiEfAcx5yfkO4k5NyE/QMx5CflBYs5JyE8Qcz5CfpKYcxHyC8Sch5BfJOYchFyAmPsTciFi7kvIBYm5HyEXJuY+hFyBmNsTciVibkvIFYm5HSFXttsK2+/3bxunvh/mz8axv4fj/r0VVDxm/nc47p+H9bZx6v0Q87etIG9GRUJuS8yVCLk9MVcg5D7EXJiQ+xFzQULuS8yFCLk/MRcg5BzE/CIh5yHmFwg5FzE/Scj5iPkJQs5JzA8Scl5ifoCQcxPznYScn5jvIOQxiPkGIY9DzFcIeSxivkDI4xHzGUIek5hPCHlcYj4i5LGJ+YOQxyfmTcizWD5mIc9j6ZiFPJdlYxbyfJaMWchzWi5mIc9rqZiFPLdlYhby/JaIWchrmD5mIa9j6piFvJZpYxbyeqaMWchrmi5mIa9rqpiFvLZpYhYyU8QsZMLwMQuZT0PHLGSODRuzkDk1ZMxC5pzhYhYylwwVs5C5ZpiYhcwtQ8QsZO6RPmYhc6/UMQuZR6SNWcg8KmXMQuYZ6WIWMs9KFbOQeUWamIXMq1LELGRK6B6zkCmla8xCpqRuMQuZ0rrELGRqaB6zkKmlacxCpqZmMQuZ2prELGRaqB6zkGmlasxCpqVqMQuZ1qrELGR6+LoVdgj5x2HFvG9w2fsGAAAAAAAAAAAAAAAAACzhH8sFZqawpyetAAAAAElFTkSuQmCC @@ -260,9 +272,11 @@ iVBORw0KGgoAAAANSUhEUgAAALMAAACzCAYAAADCFC3zAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNS // -------------------------------------------------- + // -------- IndexHtmlStk Template Data ---------- -const String kAppWebTemplateIndexHtmlStkPath = 'web/index.html.stk'; +const String kAppWebTemplateIndexHtmlStkPath = + 'web/index.html.stk'; const String kAppWebTemplateIndexHtmlStkContent = ''' @@ -440,9 +454,11 @@ const String kAppWebTemplateIndexHtmlStkContent = ''' // -------------------------------------------------- + // -------- FaviconPngStk Template Data ---------- -const String kAppWebTemplateFaviconPngStkPath = 'web/favicon.png.stk'; +const String kAppWebTemplateFaviconPngStkPath = + 'web/favicon.png.stk'; const String kAppWebTemplateFaviconPngStkContent = ''' iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAHaSURBVHgBpVTNasJAEN7dxLQl+FNEFBRR8VCQgo+gryCkh9499CnUg/gMvo3eFWw9eBLS4sWT2oOHRLOdWWLYxkRT+8GS3cnkm28mM0tIMOhpwzmn7plKdurawz9EdLtdNhqNWKvVekyn0ynLsghjTPg4jsNt26a6rnO09/v9r2Qy6UwmkwOlwoX7yZVqtWqA07v78uqKx+NmsVhsw179Jc4wDKVcLrejEvkXCHlBDlmdlkgkPm8lhKw+arWahipRKikUCspqtSqe2FOpFKnX6+QSZrMZ2W63Yr/b7Z6htshl45kOh8MnOWKj0eCXAD8vSKmOf54ho6qqnEREr9fDbjizZzIZikBCut/v6X/IENBeQikSck3TrnFdJJMghJ3V0L86nc5ZHbHOsk82m9WFUCTEzg8DkEVRhpOE6jhD57CUo5IR4tVQpMyCUg5KM0LKorH5crn8lqNhY4/HY9JsNkMVYWPLWK/XXutRmJQHGPQ5uXH0cGxLpdK9SNeVe8jlcgNyI2CWB6ZpHjwDjgxGyOfzb3+5JIBoXqlUXuG2uSOnHpQCUSi0slgs7qCNVAwCEHXZbDZYV+8sZpYxJxaLHaFc1nQ6PYLZCcsAy6BIT0U6eza83X2CBH4AHNJFlWlQookAAAAASUVORK5CYII= @@ -450,9 +466,11 @@ iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNS // -------------------------------------------------- + // -------- READMEMdStk Template Data ---------- -const String kAppWebTemplateREADMEMdStkPath = 'README.md.stk'; +const String kAppWebTemplateREADMEMdStkPath = + 'README.md.stk'; const String kAppWebTemplateREADMEMdStkContent = ''' # stacked_app @@ -476,9 +494,11 @@ samples, guidance on mobile development, and a full API reference. // -------------------------------------------------- + // -------- Main Template Data ---------- -const String kAppWebTemplateMainPath = 'lib/main.dart.stk'; +const String kAppWebTemplateMainPath = + 'lib/main.dart.stk'; const String kAppWebTemplateMainContent = ''' import 'package:flutter/material.dart'; @@ -531,6 +551,7 @@ class MyApp extends StatelessWidget { // -------------------------------------------------- + // -------- AppConstants Template Data ---------- const String kAppWebTemplateAppConstantsPath = @@ -547,9 +568,11 @@ const double kdDesktopMaxContentHeight = 750; // -------------------------------------------------- + // -------- UiHelpers Template Data ---------- -const String kAppWebTemplateUiHelpersPath = 'lib/ui/common/ui_helpers.dart.stk'; +const String kAppWebTemplateUiHelpersPath = + 'lib/ui/common/ui_helpers.dart.stk'; const String kAppWebTemplateUiHelpersContent = ''' import 'dart:math'; @@ -573,8 +596,8 @@ const Widget verticalSpaceMedium = SizedBox(height: _mediumSize); const Widget verticalSpaceLarge = SizedBox(height: _largeSize); const Widget verticalSpaceMassive = SizedBox(height: _massiveSize); -Widget spacedDivider = Column( - children: const [ +Widget spacedDivider = const Column( + children: [ verticalSpaceMedium, Divider(color: Colors.blueGrey, height: 5.0), verticalSpaceMedium, @@ -635,6 +658,7 @@ double getResponsiveFontSize(BuildContext context, // -------------------------------------------------- + // -------- AppStrings Template Data ---------- const String kAppWebTemplateAppStringsPath = @@ -649,9 +673,11 @@ const String ksHomeBottomSheetDescription = // -------------------------------------------------- + // -------- AppColors Template Data ---------- -const String kAppWebTemplateAppColorsPath = 'lib/ui/common/app_colors.dart.stk'; +const String kAppWebTemplateAppColorsPath = + 'lib/ui/common/app_colors.dart.stk'; const String kAppWebTemplateAppColorsContent = ''' import 'package:flutter/material.dart'; @@ -670,6 +696,7 @@ const Color kcBackgroundColor = kcDarkGreyColor; // -------------------------------------------------- + // -------- NoticeSheetModel Template Data ---------- const String kAppWebTemplateNoticeSheetModelPath = @@ -684,6 +711,7 @@ class NoticeSheetModel extends BaseViewModel {} // -------------------------------------------------- + // -------- NoticeSheet Template Data ---------- const String kAppWebTemplateNoticeSheetPath = @@ -752,6 +780,7 @@ class NoticeSheet extends StackedView { // -------------------------------------------------- + // -------- InfoAlertDialogModel Template Data ---------- const String kAppWebTemplateInfoAlertDialogModelPath = @@ -766,6 +795,7 @@ class InfoAlertDialogModel extends BaseViewModel {} // -------------------------------------------------- + // -------- InfoAlertDialog Template Data ---------- const String kAppWebTemplateInfoAlertDialogPath = @@ -885,6 +915,7 @@ class InfoAlertDialog extends StackedView { // -------------------------------------------------- + // -------- HomeViewDesktop Template Data ---------- const String kAppWebTemplateHomeViewDesktopPath = @@ -971,6 +1002,7 @@ class HomeViewDesktop extends ViewModelWidget { // -------------------------------------------------- + // -------- HomeViewMobile Template Data ---------- const String kAppWebTemplateHomeViewMobilePath = @@ -1057,6 +1089,7 @@ class HomeViewMobile extends ViewModelWidget { // -------------------------------------------------- + // -------- HomeView Template Data ---------- const String kAppWebTemplateHomeViewPath = @@ -1099,6 +1132,7 @@ class HomeView extends StackedView { // -------------------------------------------------- + // -------- HomeViewmodel Template Data ---------- const String kAppWebTemplateHomeViewmodelPath = @@ -1146,6 +1180,7 @@ class HomeViewModel extends BaseViewModel { // -------------------------------------------------- + // -------- HomeViewTablet Template Data ---------- const String kAppWebTemplateHomeViewTabletPath = @@ -1232,6 +1267,7 @@ class HomeViewTablet extends ViewModelWidget { // -------------------------------------------------- + // -------- UnknownView Template Data ---------- const String kAppWebTemplateUnknownViewPath = @@ -1274,6 +1310,7 @@ class UnknownView extends StackedView { // -------------------------------------------------- + // -------- UnknownViewDesktop Template Data ---------- const String kAppWebTemplateUnknownViewDesktopPath = @@ -1292,12 +1329,12 @@ class UnknownViewDesktop extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( @@ -1329,6 +1366,7 @@ class UnknownViewDesktop extends ViewModelWidget { // -------------------------------------------------- + // -------- UnknownViewTablet Template Data ---------- const String kAppWebTemplateUnknownViewTabletPath = @@ -1347,12 +1385,12 @@ class UnknownViewTablet extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( @@ -1384,6 +1422,7 @@ class UnknownViewTablet extends ViewModelWidget { // -------------------------------------------------- + // -------- UnknownViewmodel Template Data ---------- const String kAppWebTemplateUnknownViewmodelPath = @@ -1398,6 +1437,7 @@ class UnknownViewModel extends BaseViewModel {} // -------------------------------------------------- + // -------- UnknownViewMobile Template Data ---------- const String kAppWebTemplateUnknownViewMobilePath = @@ -1416,12 +1456,12 @@ class UnknownViewMobile extends ViewModelWidget { @override Widget build(BuildContext context, UnknownViewModel viewModel) { - return Scaffold( + return const Scaffold( backgroundColor: kcBackgroundColor, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text( '404', style: TextStyle( @@ -1452,6 +1492,7 @@ class UnknownViewMobile extends ViewModelWidget { // -------------------------------------------------- + // -------- StartupViewmodel Template Data ---------- const String kAppWebTemplateStartupViewmodelPath = @@ -1479,6 +1520,7 @@ class StartupViewModel extends BaseViewModel { // -------------------------------------------------- + // -------- StartupView Template Data ---------- const String kAppWebTemplateStartupViewPath = @@ -1501,27 +1543,19 @@ class StartupView extends StackedView { StartupViewModel viewModel, Widget? child, ) { - return Scaffold( + return const Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + Text( 'STACKED', - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.w900, - ), + style: TextStyle(fontSize: 40, fontWeight: FontWeight.w900), ), Row( mainAxisSize: MainAxisSize.min, - children: const [ - Text( - 'Loading ...', - style: TextStyle( - fontSize: 16, - ), - ), + children: [ + Text('Loading ...', style: TextStyle(fontSize: 16)), horizontalSpaceSmall, SizedBox( width: 16, @@ -1553,6 +1587,7 @@ class StartupView extends StackedView { // -------------------------------------------------- + // -------- ScaleOnHover Template Data ---------- const String kAppWebTemplateScaleOnHoverPath = @@ -1602,6 +1637,7 @@ class _ScaleOnHoverState extends State { // -------------------------------------------------- + // -------- TranslateOnHover Template Data ---------- const String kAppWebTemplateTranslateOnHoverPath = @@ -1658,9 +1694,11 @@ class _TranslateOnHoverState extends State { // -------------------------------------------------- + // -------- App Template Data ---------- -const String kAppWebTemplateAppPath = 'lib/app/app.dart.stk'; +const String kAppWebTemplateAppPath = + 'lib/app/app.dart.stk'; const String kAppWebTemplateAppContent = ''' import 'package:{{packageName}}/{{{bottomSheetsPath}}}/notice/notice_sheet.dart'; @@ -1704,6 +1742,7 @@ class App {} // -------------------------------------------------- + // -------- HoverExtensions Template Data ---------- const String kAppWebTemplateHoverExtensionsPath = @@ -1758,9 +1797,11 @@ extension HoverExtensions on Widget { // -------------------------------------------------- + // -------- PubspecYamlStk Template Data ---------- -const String kAppWebTemplatePubspecYamlStkPath = 'pubspec.yaml.stk'; +const String kAppWebTemplatePubspecYamlStkPath = + 'pubspec.yaml.stk'; const String kAppWebTemplatePubspecYamlStkContent = ''' name: {{packageName}} @@ -1867,9 +1908,11 @@ flutter: // -------------------------------------------------- + // -------- SettingsJsonStk Template Data ---------- -const String kAppWebTemplateSettingsJsonStkPath = '.vscode/settings.json.stk'; +const String kAppWebTemplateSettingsJsonStkPath = + '.vscode/settings.json.stk'; const String kAppWebTemplateSettingsJsonStkContent = ''' { @@ -1883,33 +1926,39 @@ const String kAppWebTemplateSettingsJsonStkContent = ''' // -------------------------------------------------- + // -------- StackedJsonStk Template Data ---------- -const String kAppMobileTemplateStackedJsonStkPath = 'stacked.json.stk'; +const String kAppMobileTemplateStackedJsonStkPath = + 'stacked.json.stk'; const String kAppMobileTemplateStackedJsonStkContent = ''' { - "stacked_app_file_path": "app/app.dart", - "services_path": "services", - "views_path": "ui/views", - "bottom_sheets_path": "ui/bottom_sheets", - "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", "bottom_sheet_builder_file_path": "ui/setup/setup_bottom_sheet_ui.dart", - "dialogs_path": "ui/dialogs", - "dialog_type_file_path": "enums/dialog_type.dart", + "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", + "bottom_sheets_path": "ui/bottom_sheets", "dialog_builder_file_path": "ui/setup/setup_dialog_ui.dart", + "dialog_type_file_path": "enums/dialog_type.dart", + "dialogs_path": "ui/dialogs", + "line_length": 80, + "locator_name": "locator", + "prefer_web": false, + "register_mocks_function": "registerServices", + "services_path": "services", + "stacked_app_file_path": "app/app.dart", "test_helpers_file_path": "helpers/test_helpers.dart", "test_services_path": "services", "test_views_path": "viewmodels", - "locator_name": "locator", - "register_mocks_function": "registerServices", + "test_widgets_path": "widget_models", "v1": false, - "line_length": 80 + "views_path": "ui/views", + "widgets_path": "ui/widgets/common" } '''; // -------------------------------------------------- + // -------- HomeViewmodelTest Template Data ---------- const String kAppMobileTemplateHomeViewmodelTestPath = @@ -1961,6 +2010,7 @@ void main() { // -------------------------------------------------- + // -------- NoticeSheetModelTest Template Data ---------- const String kAppMobileTemplateNoticeSheetModelTestPath = @@ -1983,6 +2033,7 @@ void main() { // -------------------------------------------------- + // -------- InfoAlertDialogModelTest Template Data ---------- const String kAppMobileTemplateInfoAlertDialogModelTestPath = @@ -2005,6 +2056,7 @@ void main() { // -------------------------------------------------- + // -------- TestHelpers Template Data ---------- const String kAppMobileTemplateTestHelpersPath = @@ -2094,9 +2146,11 @@ void _removeRegistrationIfExists() { // -------------------------------------------------- + // -------- READMEMdStk Template Data ---------- -const String kAppMobileTemplateREADMEMdStkPath = 'README.md.stk'; +const String kAppMobileTemplateREADMEMdStkPath = + 'README.md.stk'; const String kAppMobileTemplateREADMEMdStkContent = ''' # stacked_app @@ -2120,9 +2174,11 @@ samples, guidance on mobile development, and a full API reference. // -------------------------------------------------- + // -------- Main Template Data ---------- -const String kAppMobileTemplateMainPath = 'lib/main.dart.stk'; +const String kAppMobileTemplateMainPath = + 'lib/main.dart.stk'; const String kAppMobileTemplateMainContent = ''' import 'package:flutter/material.dart'; @@ -2169,6 +2225,7 @@ class MyApp extends StatelessWidget { // -------------------------------------------------- + // -------- UiHelpers Template Data ---------- const String kAppMobileTemplateUiHelpersPath = @@ -2196,8 +2253,8 @@ const Widget verticalSpaceMedium = SizedBox(height: _mediumSize); const Widget verticalSpaceLarge = SizedBox(height: _largeSize); const Widget verticalSpaceMassive = SizedBox(height: _massiveSize); -Widget spacedDivider = Column( - children: const [ +Widget spacedDivider = const Column( + children: [ verticalSpaceMedium, Divider(color: Colors.blueGrey, height: 5.0), verticalSpaceMedium, @@ -2258,6 +2315,7 @@ double getResponsiveFontSize(BuildContext context, // -------------------------------------------------- + // -------- AppStrings Template Data ---------- const String kAppMobileTemplateAppStringsPath = @@ -2272,6 +2330,7 @@ const String ksHomeBottomSheetDescription = // -------------------------------------------------- + // -------- AppColors Template Data ---------- const String kAppMobileTemplateAppColorsPath = @@ -2292,6 +2351,7 @@ const Color kcBackgroundColor = kcDarkGreyColor; // -------------------------------------------------- + // -------- NoticeSheetModel Template Data ---------- const String kAppMobileTemplateNoticeSheetModelPath = @@ -2306,6 +2366,7 @@ class NoticeSheetModel extends BaseViewModel {} // -------------------------------------------------- + // -------- NoticeSheet Template Data ---------- const String kAppMobileTemplateNoticeSheetPath = @@ -2374,6 +2435,7 @@ class NoticeSheet extends StackedView { // -------------------------------------------------- + // -------- InfoAlertDialogModel Template Data ---------- const String kAppMobileTemplateInfoAlertDialogModelPath = @@ -2388,6 +2450,7 @@ class InfoAlertDialogModel extends BaseViewModel {} // -------------------------------------------------- + // -------- InfoAlertDialog Template Data ---------- const String kAppMobileTemplateInfoAlertDialogPath = @@ -2507,6 +2570,7 @@ class InfoAlertDialog extends StackedView { // -------------------------------------------------- + // -------- HomeViewV1 Template Data ---------- const String kAppMobileTemplateHomeViewV1Path = @@ -2595,6 +2659,7 @@ class HomeView extends StatelessWidget { // -------------------------------------------------- + // -------- HomeView Template Data ---------- const String kAppMobileTemplateHomeViewPath = @@ -2690,6 +2755,7 @@ class HomeView extends StackedView { // -------------------------------------------------- + // -------- HomeViewmodel Template Data ---------- const String kAppMobileTemplateHomeViewmodelPath = @@ -2737,6 +2803,7 @@ class HomeViewModel extends BaseViewModel { // -------------------------------------------------- + // -------- StartupViewmodel Template Data ---------- const String kAppMobileTemplateStartupViewmodelPath = @@ -2766,6 +2833,7 @@ class StartupViewModel extends BaseViewModel { // -------------------------------------------------- + // -------- StartupViewV1 Template Data ---------- const String kAppMobileTemplateStartupViewV1Path = @@ -2831,6 +2899,7 @@ class StartupView extends StatelessWidget { // -------------------------------------------------- + // -------- StartupView Template Data ---------- const String kAppMobileTemplateStartupViewPath = @@ -2853,27 +2922,19 @@ class StartupView extends StackedView { StartupViewModel viewModel, Widget? child, ) { - return Scaffold( + return const Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + Text( 'STACKED', - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.w900, - ), + style: TextStyle(fontSize: 40, fontWeight: FontWeight.w900), ), Row( mainAxisSize: MainAxisSize.min, - children: const [ - Text( - 'Loading ...', - style: TextStyle( - fontSize: 16, - ), - ), + children: [ + Text('Loading ...', style: TextStyle(fontSize: 16)), horizontalSpaceSmall, SizedBox( width: 16, @@ -2905,9 +2966,11 @@ class StartupView extends StackedView { // -------------------------------------------------- + // -------- App Template Data ---------- -const String kAppMobileTemplateAppPath = 'lib/app/app.dart.stk'; +const String kAppMobileTemplateAppPath = + 'lib/app/app.dart.stk'; const String kAppMobileTemplateAppContent = ''' import 'package:{{packageName}}/{{{bottomSheetsPath}}}/notice/notice_sheet.dart'; @@ -2945,9 +3008,11 @@ class App {} // -------------------------------------------------- + // -------- PubspecYamlStk Template Data ---------- -const String kAppMobileTemplatePubspecYamlStkPath = 'pubspec.yaml.stk'; +const String kAppMobileTemplatePubspecYamlStkPath = + 'pubspec.yaml.stk'; const String kAppMobileTemplatePubspecYamlStkContent = ''' name: {{packageName}} @@ -3051,6 +3116,7 @@ flutter: // -------------------------------------------------- + // -------- SettingsJsonStk Template Data ---------- const String kAppMobileTemplateSettingsJsonStkPath = @@ -3068,6 +3134,99 @@ const String kAppMobileTemplateSettingsJsonStkContent = ''' // -------------------------------------------------- + +// -------- GenericModelTest Template Data ---------- + +const String kWidgetEmptyTemplateGenericModelTestPath = + 'test/widget_models/generic_model_test.dart.stk'; + +const String kWidgetEmptyTemplateGenericModelTestContent = ''' +import 'package:flutter_test/flutter_test.dart'; +import 'package:{{packageName}}/{{{relativeLocatorFilePath}}}'; + +import '{{{widgetTestHelpersImport}}}'; + +void main() { + group('{{widgetModelName}} Tests -', () { + setUp(() => registerServices()); + tearDown(() => locator.reset()); + }); +} + +'''; + +// -------------------------------------------------- + + +// -------- GenericUseModel Template Data ---------- + +const String kWidgetEmptyTemplateGenericUseModelPath = + 'lib/ui/widgets/common/generic/generic_use_model.dart.stk'; + +const String kWidgetEmptyTemplateGenericUseModelContent = ''' +import 'package:flutter/material.dart'; +import 'package:stacked/stacked.dart'; + +import '{{widgetModelFileName}}'; + +class {{widgetName}} extends StackedView<{{widgetModelName}}> { + const {{widgetName}}({super.key}); + + @override + Widget builder( + BuildContext context, + {{widgetModelName}} viewModel, + Widget? child, + ) { + return const SizedBox.shrink(); + } + + @override + {{widgetModelName}} viewModelBuilder( + BuildContext context, + ) => {{widgetModelName}}(); +} +'''; + +// -------------------------------------------------- + + +// -------- Generic Template Data ---------- + +const String kWidgetEmptyTemplateGenericPath = + 'lib/ui/widgets/common/generic/generic.dart.stk'; + +const String kWidgetEmptyTemplateGenericContent = ''' +import 'package:flutter/material.dart'; + +class {{widgetName}} extends StatelessWidget { + const {{widgetName}}({super.key}); + + @override + Widget build(BuildContext context) { + return const SizedBox.shrink(); + } +} + +'''; + +// -------------------------------------------------- + + +// -------- GenericModel Template Data ---------- + +const String kWidgetEmptyTemplateGenericModelPath = + 'lib/ui/widgets/common/generic/generic_model.dart.stk'; + +const String kWidgetEmptyTemplateGenericModelContent = ''' +import 'package:stacked/stacked.dart'; + +class {{widgetModelName}} extends BaseViewModel {} +'''; + +// -------------------------------------------------- + + // -------- GenericDialogModelTest Template Data ---------- const String kDialogEmptyTemplateGenericDialogModelTestPath = @@ -3090,6 +3249,7 @@ void main() { // -------------------------------------------------- + // -------- GenericDialogModel Template Data ---------- const String kDialogEmptyTemplateGenericDialogModelPath = @@ -3104,6 +3264,7 @@ class {{dialogModelName}} extends BaseViewModel {} // -------------------------------------------------- + // -------- GenericDialogUseModel Template Data ---------- const String kDialogEmptyTemplateGenericDialogUseModelPath = @@ -3224,6 +3385,7 @@ class {{dialogName}} extends StackedView<{{dialogModelName}}> { // -------------------------------------------------- + // -------- GenericDialog Template Data ---------- const String kDialogEmptyTemplateGenericDialogPath = @@ -3333,6 +3495,7 @@ class {{dialogName}} extends StatelessWidget { // -------------------------------------------------- + // -------- GenericViewmodelTest Template Data ---------- const String kViewEmptyTemplateGenericViewmodelTestPath = @@ -3355,6 +3518,7 @@ void main() { // -------------------------------------------------- + // -------- GenericViewmodel Template Data ---------- const String kViewEmptyTemplateGenericViewmodelPath = @@ -3363,12 +3527,12 @@ const String kViewEmptyTemplateGenericViewmodelPath = const String kViewEmptyTemplateGenericViewmodelContent = ''' import 'package:stacked/stacked.dart'; -class {{viewModelName}} extends BaseViewModel { -} +class {{viewModelName}} extends BaseViewModel {} '''; // -------------------------------------------------- + // -------- GenericView Template Data ---------- const String kViewEmptyTemplateGenericViewPath = @@ -3406,6 +3570,7 @@ class {{viewName}} extends StackedView<{{viewModelName}}> { // -------------------------------------------------- + // -------- GenericViewV1 Template Data ---------- const String kViewEmptyTemplateGenericViewV1Path = @@ -3437,6 +3602,7 @@ class {{viewName}} extends StatelessWidget { // -------------------------------------------------- + // -------- GenericViewmodelTest Template Data ---------- const String kViewWebTemplateGenericViewmodelTestPath = @@ -3459,6 +3625,7 @@ void main() { // -------------------------------------------------- + // -------- GenericViewmodel Template Data ---------- const String kViewWebTemplateGenericViewmodelPath = @@ -3473,6 +3640,7 @@ class {{viewModelName}} extends BaseViewModel { // -------------------------------------------------- + // -------- GenericViewMobile Template Data ---------- const String kViewWebTemplateGenericViewMobilePath = @@ -3507,6 +3675,7 @@ class {{viewName}}Mobile extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- + // -------- GenericViewTablet Template Data ---------- const String kViewWebTemplateGenericViewTabletPath = @@ -3541,6 +3710,7 @@ class {{viewName}}Tablet extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- + // -------- GenericView Template Data ---------- const String kViewWebTemplateGenericViewPath = @@ -3583,6 +3753,7 @@ class {{viewName}} extends StackedView<{{viewModelName}}> { // -------------------------------------------------- + // -------- GenericViewDesktop Template Data ---------- const String kViewWebTemplateGenericViewDesktopPath = @@ -3617,6 +3788,7 @@ class {{viewName}}Desktop extends ViewModelWidget<{{viewModelName}}> { // -------------------------------------------------- + // -------- GenericServiceTest Template Data ---------- const String kServiceEmptyTemplateGenericServiceTestPath = @@ -3639,6 +3811,7 @@ void main() { // -------------------------------------------------- + // -------- GenericService Template Data ---------- const String kServiceEmptyTemplateGenericServicePath = @@ -3652,6 +3825,7 @@ class {{serviceName}} { // -------------------------------------------------- + // -------- GenericSheetModelTest Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetModelTestPath = @@ -3674,6 +3848,7 @@ void main() { // -------------------------------------------------- + // -------- GenericSheetModel Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetModelPath = @@ -3688,6 +3863,7 @@ class {{sheetModelName}} extends BaseViewModel {} // -------------------------------------------------- + // -------- GenericSheetUseModel Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetUseModelPath = @@ -3758,6 +3934,7 @@ class {{sheetName}} extends StackedView<{{sheetModelName}}> { // -------------------------------------------------- + // -------- GenericSheet Template Data ---------- const String kBottomSheetEmptyTemplateGenericSheetPath = @@ -3816,3 +3993,4 @@ class {{sheetName}} extends StatelessWidget { '''; // -------------------------------------------------- + diff --git a/lib/src/templates/template_constants.dart b/lib/src/templates/template_constants.dart index 720a3a0..4a5ef47 100644 --- a/lib/src/templates/template_constants.dart +++ b/lib/src/templates/template_constants.dart @@ -5,6 +5,8 @@ const String kTemplateNameApp = 'app'; const String kTemplateNameBottomSheet = 'bottom_sheet'; const String kTemplateNameDialog = 'dialog'; const String kTemplateNameGenerate = 'generate'; +const String kTemplateNameUpdate = 'update'; +const String kTemplateNameWidget = 'widget'; // ------- Template Types -------- const String kTemplateTypeEmpty = 'empty'; @@ -114,6 +116,19 @@ const String kTemplatePropertyDialogTypeFilePath = 'dialogTypeFilePath'; const String kTemplatePropertyDialogBuilderFilePath = 'dialogBuilderFilePath'; +const String kTemplatePropertyWidgetName = 'widgetName'; + +const String kTemplatePropertyWidgetFileName = 'widgetFileName'; + +const String kTemplatePropertyWidgetModelName = 'widgetModelName'; + +const String kTemplatePropertyWidgetModelFileName = 'widgetModelFileName'; + +const String kTemplatePropertyWidgetFolderName = 'widgetFolderName'; + +const String kTemplatePropertyWidgetTestHelpersImport = + 'widgetTestHelpersImport'; + // -------- Compiled Template Structure --------- const String kTemplateDataStructure = ''' diff --git a/lib/src/templates/template_render_functions.dart b/lib/src/templates/template_render_functions.dart index 88163d3..05e4f84 100644 --- a/lib/src/templates/template_render_functions.dart +++ b/lib/src/templates/template_render_functions.dart @@ -64,6 +64,16 @@ Map renderFunctions = { kTemplatePropertyRelativeLocatorFilePath: getFilePath(builder: 'locator'), }; }, + kTemplateNameWidget: (ReCase value) { + return { + kTemplatePropertyWidgetName: value.pascalCase, + kTemplatePropertyWidgetFileName: '${value.snakeCase}.dart', + kTemplatePropertyWidgetModelName: '${value.pascalCase}Model', + kTemplatePropertyWidgetModelFileName: '${value.snakeCase}_model.dart', + kTemplatePropertyWidgetFolderName: value.snakeCase, + kTemplatePropertyRelativeLocatorFilePath: getFilePath(builder: 'locator'), + }; + }, }; /// Returns file path of the [builder] diff --git a/lib/src/templates/view/empty/lib/ui/views/generic/generic_viewmodel.dart.stk b/lib/src/templates/view/empty/lib/ui/views/generic/generic_viewmodel.dart.stk index f0c21c6..24894f6 100644 --- a/lib/src/templates/view/empty/lib/ui/views/generic/generic_viewmodel.dart.stk +++ b/lib/src/templates/view/empty/lib/ui/views/generic/generic_viewmodel.dart.stk @@ -1,4 +1,3 @@ import 'package:stacked/stacked.dart'; -class {{viewModelName}} extends BaseViewModel { -} \ No newline at end of file +class {{viewModelName}} extends BaseViewModel {} \ No newline at end of file diff --git a/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic.dart.stk b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic.dart.stk new file mode 100644 index 0000000..81a7dcd --- /dev/null +++ b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic.dart.stk @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class {{widgetName}} extends StatelessWidget { + const {{widgetName}}({super.key}); + + @override + Widget build(BuildContext context) { + return const SizedBox.shrink(); + } +} diff --git a/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_model.dart.stk b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_model.dart.stk new file mode 100644 index 0000000..a8c7ccd --- /dev/null +++ b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_model.dart.stk @@ -0,0 +1,3 @@ +import 'package:stacked/stacked.dart'; + +class {{widgetModelName}} extends BaseViewModel {} \ No newline at end of file diff --git a/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_use_model.dart.stk b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_use_model.dart.stk new file mode 100644 index 0000000..79ba3b5 --- /dev/null +++ b/lib/src/templates/widget/empty/lib/ui/widgets/common/generic/generic_use_model.dart.stk @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:stacked/stacked.dart'; + +import '{{widgetModelFileName}}'; + +class {{widgetName}} extends StackedView<{{widgetModelName}}> { + const {{widgetName}}({super.key}); + + @override + Widget builder( + BuildContext context, + {{widgetModelName}} viewModel, + Widget? child, + ) { + return const SizedBox.shrink(); + } + + @override + {{widgetModelName}} viewModelBuilder( + BuildContext context, + ) => {{widgetModelName}}(); +} \ No newline at end of file diff --git a/lib/src/templates/widget/empty/test/widget_models/generic_model_test.dart.stk b/lib/src/templates/widget/empty/test/widget_models/generic_model_test.dart.stk new file mode 100644 index 0000000..9ff3336 --- /dev/null +++ b/lib/src/templates/widget/empty/test/widget_models/generic_model_test.dart.stk @@ -0,0 +1,11 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:{{packageName}}/{{{relativeLocatorFilePath}}}'; + +import '{{{widgetTestHelpersImport}}}'; + +void main() { + group('{{widgetModelName}} Tests -', () { + setUp(() => registerServices()); + tearDown(() => locator.reset()); + }); +} diff --git a/test/helpers/test_helpers.dart b/test/helpers/test_helpers.dart index 67ab8fc..96b5af5 100644 --- a/test/helpers/test_helpers.dart +++ b/test/helpers/test_helpers.dart @@ -39,7 +39,6 @@ MockFileService getAndRegisterFileService({ int retryUntilFileExists = 0, String readFileResult = 'file_content', List getFilesInDirectoryResult = const [], - bool throwStateError = false, bool throwConfigFileNotFoundException = false, }) { _removeRegistrationIfExists(); @@ -53,10 +52,6 @@ MockFileService getAndRegisterFileService({ return Future.value(false); } - if (throwStateError) { - throw StateError; - } - return Future.value(fileExistsResult); }); diff --git a/test/helpers/test_helpers.mocks.dart b/test/helpers/test_helpers.mocks.dart index 94192a5..feefa8a 100644 --- a/test/helpers/test_helpers.mocks.dart +++ b/test/helpers/test_helpers.mocks.dart @@ -984,6 +984,18 @@ class MockConfigService extends _i1.Mock implements _i15.ConfigService { returnValueForMissingStub: '', ) as String); @override + String get widgetPath => (super.noSuchMethod( + Invocation.getter(#widgetPath), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + String get widgetTestHelpersImport => (super.noSuchMethod( + Invocation.getter(#widgetTestHelpersImport), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override bool get v1 => (super.noSuchMethod( Invocation.getter(#v1), returnValue: false, @@ -1136,7 +1148,7 @@ class MockProcessService extends _i1.Mock implements _i16.ProcessService { ) as _i6.Future); @override _i6.Future runBuildRunner({ - String? appName, + String? workingDirectory, bool? shouldWatch = false, bool? shouldDeleteConflictingOutputs = true, }) => @@ -1145,7 +1157,7 @@ class MockProcessService extends _i1.Mock implements _i16.ProcessService { #runBuildRunner, [], { - #appName: appName, + #workingDirectory: workingDirectory, #shouldWatch: shouldWatch, #shouldDeleteConflictingOutputs: shouldDeleteConflictingOutputs, }, @@ -1298,6 +1310,17 @@ class MockAnalyticsService extends _i1.Mock implements _i17.AnalyticsService { returnValueForMissingStub: _i6.Future.value(), ) as _i6.Future); @override + _i6.Future createWidgetEvent({required String? name}) => + (super.noSuchMethod( + Invocation.method( + #createWidgetEvent, + [], + {#name: name}, + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override _i6.Future deleteServiceEvent({required String? name}) => (super.noSuchMethod( Invocation.method( diff --git a/test/services/config_service_test.dart b/test/services/config_service_test.dart index c1538c8..3243612 100644 --- a/test/services/config_service_test.dart +++ b/test/services/config_service_test.dart @@ -1,8 +1,11 @@ +import 'dart:convert'; + import 'package:mockito/mockito.dart'; import 'package:stacked_cli/src/constants/config_constants.dart'; import 'package:stacked_cli/src/constants/message_constants.dart'; import 'package:stacked_cli/src/exceptions/config_file_not_found_exception.dart'; import 'package:stacked_cli/src/locator.dart'; +import 'package:stacked_cli/src/models/config_model.dart'; import 'package:stacked_cli/src/services/config_service.dart'; import 'package:test/test.dart'; @@ -15,26 +18,32 @@ void main() { setUp(() => registerServices()); tearDown(() => locator.reset()); - const customConfigFilePath = '/Users/filledstacks/Desktop/stacked.json'; - const xdgConfigFilePath = + const String customConfigFilePath = + '/Users/filledstacks/Desktop/stacked.json'; + const String xdgConfigFilePath = '/Users/filledstacks/.config/stacked/stacked.json'; - const stackedAppFilePath = 'src/app/core.dart'; - const testHelpersFilePath = 'lib/src/test/helpers/core_test.helpers.dart'; - - const String customConfig = ''' - { - "stacked_app_file_path": "$stackedAppFilePath", - "services_path": "my/personal/path/to/services", - "views_path": "my/personal/path/to/views", - "test_helpers_file_path": "$testHelpersFilePath", - "test_services_path": "my/personal/path/to/tests/service", - "test_views_path": "my/personal/path/to/tests/viewmodel", - "locator_name": "locator", - "register_mocks_function": "registerServices", - "v1": false, - "line_length": 80 - } - '''; + + final Config customConfig = Config.fromJson({ + "bottom_sheet_builder_file_path": "ui/setup/setup_bottom_sheet_ui.dart", + "bottom_sheet_type_file_path": "enums/bottom_sheet_type.dart", + "bottom_sheets_path": "ui/bottom_sheets", + "dialog_builder_file_path": "ui/setup/setup_dialog_ui.dart", + "dialog_type_file_path": "enums/dialog_type.dart", + "dialogs_path": "ui/dialogs", + "line_length": 80, + "locator_name": "locator", + "prefer_web": true, + "register_mocks_function": "registerServices", + "services_path": "my/personal/path/to/services", + "stacked_app_file_path": "src/app/core.dart", + "test_helpers_file_path": "lib/src/test/helpers/core_test.helpers.dart", + "test_services_path": "my/personal/path/to/tests/service", + "test_views_path": "my/personal/path/to/tests/viewmodel", + "test_widgets_path": "my/personal/path/to/tests/widget_models", + "v1": false, + "views_path": "my/personal/path/to/views", + "widgets_path": "ui/widgets/common" + }); group('resolveConfigFile -', () { test('when called with configFilePath should return configFilePath', @@ -92,7 +101,7 @@ void main() { test( 'when called without configFilePath and Home environment variable is not set should throw ConfigFileNotFoundException with message equal kConfigFileNotFound and shouldHaltCommand equal false', () async { - getAndRegisterFileService(throwStateError: true); + getAndRegisterPathService(throwStateError: true); final service = _getService(); expect( () => service.resolveConfigFile(), @@ -104,8 +113,6 @@ void main() { )), ); }, - skip: - 'Should throw ConfigFileNotFoundException because StateError exception is catched', ); test( @@ -245,7 +252,9 @@ void main() { test('when called with custom config should return custom path', () async { final path = 'test/services/generic_service_test.dart.stk'; - getAndRegisterFileService(readFileResult: customConfig); + getAndRegisterFileService( + readFileResult: jsonEncode(customConfig.toJson()), + ); final service = _getService(); await service.loadConfig(customConfigFilePath); final customPath = service.replaceCustomPaths(path); @@ -260,24 +269,28 @@ void main() { 'when called with custom stacked app file path should return full stacked_app file path from config', () async { final path = 'app/app.dart'; - getAndRegisterFileService(readFileResult: customConfig); + getAndRegisterFileService( + readFileResult: jsonEncode(customConfig.toJson()), + ); final service = _getService(); await service.loadConfig(customConfigFilePath); final customPath = service.replaceCustomPaths(path); expect(customPath, isNot(path)); - expect(customPath, stackedAppFilePath); + expect(customPath, 'src/app/core.dart'); }); test( 'when called with custom test_helpers file path should return full test_helpers file path from config', () async { final path = 'helpers/test_helpers.dart'; - getAndRegisterFileService(readFileResult: customConfig); + getAndRegisterFileService( + readFileResult: jsonEncode(customConfig.toJson()), + ); final service = _getService(); await service.loadConfig(customConfigFilePath); final customPath = service.replaceCustomPaths(path); expect(customPath, isNot(path)); - expect(customPath, testHelpersFilePath); + expect(customPath, 'lib/src/test/helpers/core_test.helpers.dart'); }); });