diff --git a/lib/samples/impl/analysis_options.dart b/lib/samples/impl/analysis_options.dart index 51f2169e..3c1d787e 100644 --- a/lib/samples/impl/analysis_options.dart +++ b/lib/samples/impl/analysis_options.dart @@ -13,4 +13,7 @@ linter: rules: '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/arctekko/arc_main.dart b/lib/samples/impl/arctekko/arc_main.dart index 4e8b6400..ea115da9 100644 --- a/lib/samples/impl/arctekko/arc_main.dart +++ b/lib/samples/impl/arctekko/arc_main.dart @@ -28,4 +28,7 @@ class Main extends StatelessWidget { } }'''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/arctekko/arc_navigation.dart b/lib/samples/impl/arctekko/arc_navigation.dart index a68f0637..a950e4dd 100644 --- a/lib/samples/impl/arctekko/arc_navigation.dart +++ b/lib/samples/impl/arctekko/arc_navigation.dart @@ -35,4 +35,7 @@ class Nav { static List routes = [ ]; }'''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/arctekko/arc_routes.dart b/lib/samples/impl/arctekko/arc_routes.dart index 2a8e4416..b4816c23 100644 --- a/lib/samples/impl/arctekko/arc_routes.dart +++ b/lib/samples/impl/arctekko/arc_routes.dart @@ -14,4 +14,7 @@ class Routes { } } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/arctekko/arc_screen.dart b/lib/samples/impl/arctekko/arc_screen.dart index 5f5307ef..e6a0b01c 100644 --- a/lib/samples/impl/arctekko/arc_screen.dart +++ b/lib/samples/impl/arctekko/arc_screen.dart @@ -70,4 +70,7 @@ class CounterScreen extends GetView { } } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/arctekko/config_example.dart b/lib/samples/impl/arctekko/config_example.dart index b057786f..9a885234 100644 --- a/lib/samples/impl/arctekko/config_example.dart +++ b/lib/samples/impl/arctekko/config_example.dart @@ -39,4 +39,7 @@ class ConfigEnvironments { ); } }'''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/generate_locales.dart b/lib/samples/impl/generate_locales.dart index 1599e4d7..56a0220a 100644 --- a/lib/samples/impl/generate_locales.dart +++ b/lib/samples/impl/generate_locales.dart @@ -31,4 +31,7 @@ class Locales { \t$_locales } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_app_pages.dart b/lib/samples/impl/get_app_pages.dart index 972a2fcb..10a33e83 100644 --- a/lib/samples/impl/get_app_pages.dart +++ b/lib/samples/impl/get_app_pages.dart @@ -23,4 +23,7 @@ class AppPages { ]; } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_binding.dart b/lib/samples/impl/get_binding.dart index fe2fcd1a..77f2d0f0 100644 --- a/lib/samples/impl/get_binding.dart +++ b/lib/samples/impl/get_binding.dart @@ -30,5 +30,21 @@ class $_bindingName extends Bindings { ); } } +'''; + + @override + String? get getX5Content => '''$_import +import 'package:${PubspecUtils.projectName}/$_controllerDir'; + +class $_bindingName extends Binding { + @override + List dependencies() { + return [ + Bind.lazyPut<${_fileName.pascalCase}Controller>( + () => ${_fileName.pascalCase}Controller(), + ), + ]; + } +} '''; } diff --git a/lib/samples/impl/get_controller.dart b/lib/samples/impl/get_controller.dart index 1a454720..2e40327a 100644 --- a/lib/samples/impl/get_controller.dart +++ b/lib/samples/impl/get_controller.dart @@ -54,4 +54,7 @@ class ${_fileName.pascalCase}Controller extends GetxController { void increment() => count.value++; } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_provider.dart b/lib/samples/impl/get_provider.dart index f1e8d3d6..64e303a5 100644 --- a/lib/samples/impl/get_provider.dart +++ b/lib/samples/impl/get_provider.dart @@ -60,4 +60,7 @@ if(map is Map) return $_namePascal.fromJson(map); if(map is List) return map.map((item)=> $_namePascal.fromJson(item)).toList(); };\n''' : '\n'; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_route.dart b/lib/samples/impl/get_route.dart index 171fdc95..df66970a 100644 --- a/lib/samples/impl/get_route.dart +++ b/lib/samples/impl/get_route.dart @@ -19,4 +19,7 @@ abstract class _Paths { } '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_server/pubspec.dart b/lib/samples/impl/get_server/pubspec.dart index 7b66c8c3..9c9a2fa2 100644 --- a/lib/samples/impl/get_server/pubspec.dart +++ b/lib/samples/impl/get_server/pubspec.dart @@ -18,4 +18,7 @@ dependencies: dev_dependencies: '''; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/get_view.dart b/lib/samples/impl/get_view.dart index 5d966fdc..2f36ada3 100644 --- a/lib/samples/impl/get_view.dart +++ b/lib/samples/impl/get_view.dart @@ -56,4 +56,7 @@ class $_viewName extends $_controllerName { @override String get content => _isServer ? _serverView : _flutterView; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/impl/getx_pattern/get_main.dart b/lib/samples/impl/getx_pattern/get_main.dart index 233c6616..1718a428 100644 --- a/lib/samples/impl/getx_pattern/get_main.dart +++ b/lib/samples/impl/getx_pattern/get_main.dart @@ -32,4 +32,7 @@ void main() { @override String get content => isServer! ? _serverMain : _flutterMain; + + @override + String? get getX5Content => null; } diff --git a/lib/samples/interface/sample_interface.dart b/lib/samples/interface/sample_interface.dart index 28344d1a..eaf791c0 100644 --- a/lib/samples/interface/sample_interface.dart +++ b/lib/samples/interface/sample_interface.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'package:pubspec_parse/pubspec_parse.dart'; import '../../functions/create/create_single_file.dart'; @@ -20,17 +21,34 @@ abstract class Sample { /// by path. String get content; + /// Store the (GetX 5 content) that will be written to the file in a String or + /// Future in that variable. It is used to fill the file created + /// by path. + String? get getX5Content; + + /// check if project using GetX 5 + bool isUsingGetX5() { + final pubspecFile = File('pubspec.yaml'); + final pubSpec = Pubspec.parse(pubspecFile.readAsStringSync()); + + if(pubSpec.dependencies['get'] == null ) return false; + + return pubSpec.dependencies['get'].toString().contains('^5') || + pubSpec.dependencies['get'].toString().contains(': 5'); + } + Sample(this.path, {this.overwrite = false}); /// This function will create the file in [path] with the - /// content of [content]. + /// content of [content] or [getX5Content] according to he used get version. File create({bool skipFormatter = false}) { return writeFile( path, - customContent.isNotEmpty ? customContent : content, + customContent.isNotEmpty ? customContent : isUsingGetX5() && getX5Content + != null ? getX5Content! : content, overwrite: overwrite, skipFormatter: skipFormatter, useRelativeImport: true, ); } -} +} \ No newline at end of file