Skip to content

Commit

Permalink
fix: update HoverExtensions (#9)
Browse files Browse the repository at this point in the history
* Update HoverExtensions

* Compile templates
  • Loading branch information
ferrarafer authored Apr 10, 2023
1 parent ad50af2 commit 20955c9
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 177 deletions.
27 changes: 20 additions & 7 deletions lib/src/templates/app/web/lib/extensions/hover_extensions.dart.stk
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import 'package:{{packageName}}/ui/widgets/mouse_transforms/scale_on_hover.dart';
import 'package:{{packageName}}/ui/widgets/mouse_transforms/translate_on_hover.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

extension HoverExtensions on Widget {
Widget get showCursorOnHover {
return MouseRegion(
return _returnUnalteredOnMobile(MouseRegion(
child: this,
cursor: SystemMouseCursors.click,
);
));
}

/// Moves the widget by x,y pixels on hover
///
/// to move up use -y values, to move left use -x values
Widget moveOnHover({double? x, double? y}) {
return TranslateOnHover(
return _returnUnalteredOnMobile(TranslateOnHover(
x: x,
y: y,
child: this,
);
));
}

/// Scales the widget by [scale] on hover
Widget scaleOnHover({double scale = 1.1}) {
return ScaleOnHover(
return _returnUnalteredOnMobile(ScaleOnHover(
child: this,
scale: scale,
);
));
}
}

/// Takes in the alteredWidget and if we detect we're on Android or iOS
/// we return the unaltered widget.
///
/// The reason we can do this is because all altered widgets require mouse
/// functionality to work.
Widget _returnUnalteredOnMobile(Widget alteredWidget) {
if (kIsWeb) {
return alteredWidget;
}
return this;
}
}
121 changes: 73 additions & 48 deletions lib/src/templates/compiled_template_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,21 @@ Map<String, Map<String, StackedTemplate>> 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': {
Expand Down Expand Up @@ -320,18 +323,22 @@ Map<String, Map<String, StackedTemplate>> 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: [
Expand Down Expand Up @@ -365,18 +372,22 @@ Map<String, Map<String, StackedTemplate>> 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': {
Expand All @@ -395,71 +406,81 @@ Map<String, Map<String, StackedTemplate>> 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(
relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetModelPath,
content: kBottomSheetEmptyTemplateGenericSheetModelContent,
fileType: FileType.text),
TemplateFile(
relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetUseModelPath,
relativeOutputPath:
kBottomSheetEmptyTemplateGenericSheetUseModelPath,
content: kBottomSheetEmptyTemplateGenericSheetUseModelContent,
fileType: FileType.text),
TemplateFile(
Expand All @@ -471,19 +492,23 @@ 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',
),
],
],
),
},
};
Loading

0 comments on commit 20955c9

Please sign in to comment.