Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/samples/impl/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ linter:
rules:

''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/arctekko/arc_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ class Main extends StatelessWidget {

}
}''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/arctekko/arc_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ class Nav {
static List<GetPage> routes = [
];
}''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/arctekko/arc_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class Routes {
}
}
''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/arctekko/arc_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ class CounterScreen extends GetView<CounterController> {
}
}
''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/arctekko/config_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ class ConfigEnvironments {
);
}
}''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/generate_locales.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ class Locales {
\t$_locales
}
''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class AppPages {
];
}
''';

@override
String? get getX5Content => null;
}
16 changes: 16 additions & 0 deletions lib/samples/impl/get_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,21 @@ class $_bindingName extends Bindings {
);
}
}
''';

@override
String? get getX5Content => '''$_import
import 'package:${PubspecUtils.projectName}/$_controllerDir';

class $_bindingName extends Binding {
@override
List<Bind> dependencies() {
return [
Bind.lazyPut<${_fileName.pascalCase}Controller>(
() => ${_fileName.pascalCase}Controller(),
),
];
}
}
''';
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ class ${_fileName.pascalCase}Controller extends GetxController {
void increment() => count.value++;
}
''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ if(map is Map<String, dynamic>) return $_namePascal.fromJson(map);
if(map is List) return map.map((item)=> $_namePascal.fromJson(item)).toList();
};\n'''
: '\n';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ abstract class _Paths {
}

''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_server/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ dependencies:
dev_dependencies:

''';

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/get_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ class $_viewName extends $_controllerName {

@override
String get content => _isServer ? _serverView : _flutterView;

@override
String? get getX5Content => null;
}
3 changes: 3 additions & 0 deletions lib/samples/impl/getx_pattern/get_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ void main() {

@override
String get content => isServer! ? _serverMain : _flutterMain;

@override
String? get getX5Content => null;
}
24 changes: 21 additions & 3 deletions lib/samples/interface/sample_interface.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'package:pubspec_parse/pubspec_parse.dart';

import '../../functions/create/create_single_file.dart';

Expand All @@ -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 <String> 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,
);
}
}
}