From e2be0d15e1d6b2850d7b12800a316acd7931aa72 Mon Sep 17 00:00:00 2001 From: moohammed-gaber Date: Thu, 24 Feb 2022 23:26:29 +0200 Subject: [PATCH 1/4] Add remote & local data sources in created module by create command. --- lib/commands/impl/create/page/page.dart | 28 +++++++++++++++++++++++- lib/samples/impl/local_data_source.dart | 17 ++++++++++++++ lib/samples/impl/remote_data_source.dart | 19 ++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lib/samples/impl/local_data_source.dart create mode 100644 lib/samples/impl/remote_data_source.dart diff --git a/lib/commands/impl/create/page/page.dart b/lib/commands/impl/create/page/page.dart index 9ad5f014..3c75382c 100644 --- a/lib/commands/impl/create/page/page.dart +++ b/lib/commands/impl/create/page/page.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:cli_dialog/cli_dialog.dart'; +import 'package:get_cli/samples/impl/remote_data_source.dart'; import 'package:recase/recase.dart'; import '../../../../common/menu/menu.dart'; @@ -24,6 +25,7 @@ class CreatePageCommand extends Command { @override List get alias => ['module', '-p', '-m']; + @override Future execute() async { var isProject = false; @@ -109,6 +111,7 @@ class CreatePageCommand extends Command { ), 'views', ); + var bindingFile = handleFileCreate( name, 'binding', @@ -124,7 +127,30 @@ class CreatePageCommand extends Command { ), 'bindings', ); - + var remoteDataSourceFile = handleFileCreate( + name, + 'remote_data_source', + path, + extraFolder, + RemoteDataSourceSample( + '', + '${name.pascalCase}RemoteDataSource', + overwrite: overwrite, + ), + 'data_sources', + ); + var localDataSourceFile = handleFileCreate( + name, + 'local_data_source', + path, + extraFolder, + RemoteDataSourceSample( + '', + '${name.pascalCase}LocalDataSource', + overwrite: overwrite, + ), + 'data_sources', + ); addRoute( name, Structure.pathToDirImport(bindingFile.path), diff --git a/lib/samples/impl/local_data_source.dart b/lib/samples/impl/local_data_source.dart new file mode 100644 index 00000000..76c3d07b --- /dev/null +++ b/lib/samples/impl/local_data_source.dart @@ -0,0 +1,17 @@ +import 'package:get_cli/samples/interface/sample_interface.dart'; + +/// [Sample] file from Module_View file creation. +class LocalDataSourceSample extends Sample { + final String _name; + + LocalDataSourceSample(String path, this._name, {bool overwrite = false}) + : super(path, overwrite: overwrite); + + @override + String get content => ''' + +class $_name { + +} + '''; +} diff --git a/lib/samples/impl/remote_data_source.dart b/lib/samples/impl/remote_data_source.dart new file mode 100644 index 00000000..8a3df87a --- /dev/null +++ b/lib/samples/impl/remote_data_source.dart @@ -0,0 +1,19 @@ +import '../../common/utils/pubspec/pubspec_utils.dart'; +import '../interface/sample_interface.dart'; + +/// [Sample] file from Module_View file creation. +class RemoteDataSourceSample extends Sample { + final String _name; + + RemoteDataSourceSample(String path, this._name, {bool overwrite = false}) + : super(path, overwrite: overwrite); + + @override + String get content => ''' + +class $_name { + + +} + '''; +} From 7e614e86439fc4e0ce75fed10df5e0a8a6aec07b Mon Sep 17 00:00:00 2001 From: moohammed-gaber Date: Thu, 24 Feb 2022 23:46:56 +0200 Subject: [PATCH 2/4] Add remote & local data sources in created module by create command. --- lib/commands/impl/create/page/page.dart | 3 ++- lib/samples/impl/local_data_source.dart | 2 +- lib/samples/impl/remote_data_source.dart | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/commands/impl/create/page/page.dart b/lib/commands/impl/create/page/page.dart index 3c75382c..917eafff 100644 --- a/lib/commands/impl/create/page/page.dart +++ b/lib/commands/impl/create/page/page.dart @@ -16,6 +16,7 @@ import '../../../../functions/routes/get_add_route.dart'; import '../../../../samples/impl/get_binding.dart'; import '../../../../samples/impl/get_controller.dart'; import '../../../../samples/impl/get_view.dart'; +import '../../../../samples/impl/local_data_source.dart'; import '../../../interface/command.dart'; /// The command create a Binding and Controller page and view @@ -144,7 +145,7 @@ class CreatePageCommand extends Command { 'local_data_source', path, extraFolder, - RemoteDataSourceSample( + LocalDataSourceSample( '', '${name.pascalCase}LocalDataSource', overwrite: overwrite, diff --git a/lib/samples/impl/local_data_source.dart b/lib/samples/impl/local_data_source.dart index 76c3d07b..043d5cd0 100644 --- a/lib/samples/impl/local_data_source.dart +++ b/lib/samples/impl/local_data_source.dart @@ -11,7 +11,7 @@ class LocalDataSourceSample extends Sample { String get content => ''' class $_name { - + } '''; } diff --git a/lib/samples/impl/remote_data_source.dart b/lib/samples/impl/remote_data_source.dart index 8a3df87a..292f82f4 100644 --- a/lib/samples/impl/remote_data_source.dart +++ b/lib/samples/impl/remote_data_source.dart @@ -12,8 +12,6 @@ class RemoteDataSourceSample extends Sample { String get content => ''' class $_name { - - } '''; } From fa59703c67fd5b92ff28946b3cff87b9494eeace Mon Sep 17 00:00:00 2001 From: moohammed-gaber Date: Sat, 26 Feb 2022 01:09:55 +0200 Subject: [PATCH 3/4] Support hot reload on GetMaterialApp by extracting it from main() function to separate class. --- lib/samples/impl/getx_pattern/get_main.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/samples/impl/getx_pattern/get_main.dart b/lib/samples/impl/getx_pattern/get_main.dart index 233c6616..fe403ae9 100644 --- a/lib/samples/impl/getx_pattern/get_main.dart +++ b/lib/samples/impl/getx_pattern/get_main.dart @@ -10,14 +10,22 @@ import 'package:get/get.dart'; import 'app/routes/app_pages.dart'; void main() { - runApp( - GetMaterialApp( + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GetMaterialApp( title: "Application", initialRoute: AppPages.INITIAL, getPages: AppPages.routes, - ), - ); + ); + } } + '''; String get _serverMain => '''import 'package:get_server/get_server.dart'; From a58aadfe98e25a2fdd7ab2784c2ae3ad70382558 Mon Sep 17 00:00:00 2001 From: moohammed-gaber Date: Sat, 26 Feb 2022 01:13:05 +0200 Subject: [PATCH 4/4] Support hot reload on GetMaterialApp by extracting it from main() function to separate class. --- lib/samples/impl/getx_pattern/get_main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/samples/impl/getx_pattern/get_main.dart b/lib/samples/impl/getx_pattern/get_main.dart index fe403ae9..85257be3 100644 --- a/lib/samples/impl/getx_pattern/get_main.dart +++ b/lib/samples/impl/getx_pattern/get_main.dart @@ -10,7 +10,7 @@ import 'package:get/get.dart'; import 'app/routes/app_pages.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget {