├── .github └── workflows │ └── pub_workflow.yml ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin └── flutter_automation.dart ├── example ├── README.md └── example.dart ├── lib ├── android_signing.dart ├── commons.dart ├── flutter_automation.dart ├── gen │ └── helper.dart ├── google_maps.dart └── pubspec_api.dart ├── pubspec.lock └── pubspec.yaml /.github/workflows/pub_workflow.yml: -------------------------------------------------------------------------------- 1 | name: Publish to pub.dev 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | container: 10 | image: google/dart:latest 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Setup credentials 14 | run: | 15 | mkdir -p ~/.pub-cache 16 | cat < ~/.pub-cache/credentials.json 17 | { 18 | "accessToken":"${{ secrets.OAUTH_ACCESS_TOKEN }}", 19 | "refreshToken":"${{ secrets.OAUTH_REFRESH_TOKEN }}", 20 | "tokenEndpoint":"https://accounts.google.com/o/oauth2/token", 21 | "scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ], 22 | "expiration": 1584628470088 23 | } 24 | EOF 25 | - name: Publish package 26 | run: pub publish -f 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # Visual Studio Code related 19 | .vscode/ 20 | 21 | # Flutter/Dart/Pub related 22 | **/doc/api/ 23 | .dart_tool/ 24 | .flutter-plugins 25 | .packages 26 | .pub-cache/ 27 | .pub/ 28 | build/ 29 | 30 | # Android related 31 | **/android/**/gradle-wrapper.jar 32 | **/android/.gradle 33 | **/android/captures/ 34 | **/android/gradlew 35 | **/android/gradlew.bat 36 | **/android/local.properties 37 | **/android/**/GeneratedPluginRegistrant.java 38 | 39 | # iOS/XCode related 40 | **/ios/**/*.mode1v3 41 | **/ios/**/*.mode2v3 42 | **/ios/**/*.moved-aside 43 | **/ios/**/*.pbxuser 44 | **/ios/**/*.perspectivev3 45 | **/ios/**/*sync/ 46 | **/ios/**/.sconsign.dblite 47 | **/ios/**/.tags* 48 | **/ios/**/.vagrant/ 49 | **/ios/**/DerivedData/ 50 | **/ios/**/Icon? 51 | **/ios/**/Pods/ 52 | **/ios/**/.symlinks/ 53 | **/ios/**/profile 54 | **/ios/**/xcuserdata 55 | **/ios/.generated/ 56 | **/ios/Flutter/App.framework 57 | **/ios/Flutter/Flutter.framework 58 | **/ios/Flutter/Generated.xcconfig 59 | **/ios/Flutter/app.flx 60 | **/ios/Flutter/app.zip 61 | **/ios/Flutter/flutter_assets/ 62 | **/ios/ServiceDefinitions.json 63 | **/ios/Runner/GeneratedPluginRegistrant.* 64 | 65 | # Exceptions to above rules. 66 | !**/ios/**/default.mode1v3 67 | !**/ios/**/default.mode2v3 68 | !**/ios/**/default.pbxuser 69 | !**/ios/**/default.perspectivev3 70 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 71 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 7a4c33425ddd78c54aba07d86f3f9a4a0051769b 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2.0.0 2 | * Dropping firebase auth and firestore CRUD setup scripts in favor of [flutter_firebase_starter](https://github.com/lohanidamodar/flutter_firebase_starter) project 3 | * Null safety support 4 | 5 | ## 1.4.0 6 | * Have added `gen` command to generate directory and common files for a modified tdd structure 7 | * Fixed adding multiple instance of plugins if already exists 8 | * Made all functions private 9 | 10 | ## 1.3.3 11 | * Google services version upgraded 12 | 13 | ## [1.3.2] 14 | * Auth mock files updated to work with latest version of provider library 15 | 16 | ## [1.1.4] - Changes in stock files 17 | * Bug fixing 18 | * Certain validations 19 | * Stock files updated, renamed .temp to prevent analysis of while publishing 20 | 21 | ## [1.2.0] - Firestore CRUD boilerplate 22 | * Firestore CRUD boilerplate automation 23 | 24 | ## [1.2.1] 25 | * fixing bugs 26 | 27 | ## [1.2.2] 28 | * Upgrading plugins to latest versions 29 | * Adding api documentation 30 | 31 | ## [1.3.0] 32 | * Always get the latest version of plugin using the pub.dev API 33 | * If the http request fails, it still adds the preset default version of the plugins 34 | 35 | ## [1.3.1] 36 | * Authentication now supports Signup 37 | * Authentication UIs updated 38 | * Authentication now properly displays auth errors in snackbar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Damodar Lohani 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter Automation 2 | This package contains various automation scripts that will help you automate various aspects of your flutter project. 3 | 4 | [![Pub Package](https://img.shields.io/pub/v/flutter_automation.svg?style=flat-square)](https://pub.dartlang.org/packages/flutter_automation) 5 | 6 | 7 | ## Usage 8 | To use this plugin, add `flutter_automation` as a [dependency in your pubspec.yaml file](https://flutter.io/docs/development/packages-and-plugins/using-packages). 9 | 10 | ## Running scripts 11 | From terminal in your flutter project run, 12 | ``` 13 | flutter pub pub run flutter_automation --firebase-auth --google-maps --android-sign --firestore-crud 14 | ``` 15 | ### 1. Firebase Auth 16 | This sets up firebase authentication with google and email based login automatically in your flutter project. Also copies boilerplate login ui flow using `provider` package for state management 17 | 18 | ``` 19 | flutter pub pub run flutter_automation --firebase-auth 20 | ``` 21 | 22 | ### 2. Google Maps 23 | sets up google maps flutter plugin on android platform in a flutter project. 24 | 25 | After you run the script in your flutter project you need to modify `android/app/src/main/res/values/strings.xml` file changing the text `YOUR_API_KEY` to your actual google maps Api key. 26 | 27 | ``` 28 | flutter pub pub run flutter_automation --google-maps 29 | ``` 30 | 31 | ### 3. Android Signing 32 | Generates keystore and sets up android signing config in your flutter project. 33 | 34 | It uses `keytool` to generate keystore so, for this script to work `keytool` must be in path. 35 | 36 | ``` 37 | flutter pub pub run flutter_automation --android-sign 38 | ``` 39 | 40 | ### 4. Firestore CRUD 41 | Provides a simple firestore CRUD operation boilerplate 42 | 43 | ``` 44 | flutter pub pub run flutter_automation --firestore-crud 45 | ``` -------------------------------------------------------------------------------- /bin/flutter_automation.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_automation/flutter_automation.dart'; 2 | 3 | void main(List arguments) { 4 | decipherScript(arguments); 5 | } 6 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Flutter Automation 2 | This package contains various automation scripts that will help you automate various aspects of your flutter project. 3 | 4 | ## Usage 5 | To use this plugin, add `flutter_automation` as a [dependency in your pubspec.yaml file](https://flutter.io/docs/development/packages-and-plugins/using-packages). 6 | 7 | ## Running scripts 8 | From terminal in your flutter project run, 9 | ``` 10 | flutter pub pub run flutter_automation --firebase-auth --google-maps --android-sign --firestore-crud 11 | ``` 12 | ### 1. Firebase Auth 13 | This sets up firebase authentication with google and email based login automatically in your flutter project. Also copies boilerplate login ui flow using `provider` package for state management 14 | 15 | ``` 16 | flutter pub pub run flutter_automation --firebase-auth 17 | ``` 18 | 19 | ### 2. Google Maps 20 | sets up google maps flutter plugin on android platform in a flutter project. 21 | 22 | After you run the script in your flutter project you need to modify `android/app/src/main/res/values/strings.xml` file changing the text `YOUR_API_KEY` to your actual google maps Api key. 23 | 24 | ``` 25 | flutter pub pub run flutter_automation --google-maps 26 | ``` 27 | 28 | ### 3. Android Signing 29 | Generates keystore and sets up android signing config in your flutter project. 30 | 31 | It uses `keytool` to generate keystore so, for this script to work `keytool` must be in path. 32 | 33 | ``` 34 | flutter pub pub run flutter_automation --android-sign 35 | ``` 36 | 37 | ### 4. Firestore CRUD 38 | Provides a simple firestore CRUD operation boilerplate 39 | 40 | ``` 41 | flutter pub pub run flutter_automation --firestore-crud 42 | ``` -------------------------------------------------------------------------------- /example/example.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | print("Just run flutter pub pub run flutter_automation -f -s from terminal in your project directory after flutter_automation package as dev dependency"); 3 | } -------------------------------------------------------------------------------- /lib/android_signing.dart: -------------------------------------------------------------------------------- 1 | part of flutter_automation; 2 | 3 | String? alias; 4 | String keystorePath = "keys/keystore.jks"; 5 | String? keyPass; 6 | String? keystorePass; 7 | const String keyPropertiesPath = "./android/key.properties"; 8 | 9 | /// Main function that uses other helper functions to setup android signing 10 | void _androidSign() { 11 | _generateKeystore(); 12 | _createKeyProperties(); 13 | _configureBuildConfig(); 14 | } 15 | 16 | /// Generates the keystore with the given settings 17 | void _generateKeystore() { 18 | String defDname = 19 | "CN=popupbits.com, OU=DD, O=Popup Bits Ltd., L=Kathmandu, S=Bagmati, C=NP"; 20 | 21 | stdout.write("enter key alias: "); 22 | alias = stdin.readLineSync(); 23 | 24 | stdout.write( 25 | "enter dname as (CN=popupbits.com, OU=DD, O=Popup Bits Ltd., L=Kathmandu, S=Bagmati, C=NP): "); 26 | String? dname = stdin.readLineSync(); 27 | if (dname == null || dname.isEmpty) dname = defDname; 28 | stdout.write("key password: "); 29 | keyPass = stdin.readLineSync(); 30 | stdout.write("keystore password: "); 31 | keystorePass = stdin.readLineSync(); 32 | if (alias == null || alias!.isEmpty || 33 | dname.isEmpty || 34 | keyPass == null || keyPass!.isEmpty || 35 | keystorePass == null || keystorePass!.isEmpty) { 36 | stderr.writeln("All inputs that don't have default mentioned are required"); 37 | return; 38 | } 39 | 40 | Directory keys = Directory("keys"); 41 | if (!keys.existsSync()) { 42 | keys.createSync(); 43 | } 44 | 45 | ProcessResult res = Process.runSync("keytool", [ 46 | "-genkey", 47 | "-noprompt", 48 | "-alias", 49 | alias!, 50 | "-dname", 51 | dname, 52 | "-keystore", 53 | keystorePath, 54 | "-storepass", 55 | keystorePass!, 56 | "-keypass", 57 | keyPass!, 58 | "-keyalg", 59 | "RSA", 60 | "-keysize", 61 | "2048", 62 | "-validity", 63 | "10000" 64 | ]); 65 | stdout.write(res.stdout); 66 | stderr.write(res.stderr); 67 | stdout.writeln("generated keystore with provided input"); 68 | } 69 | 70 | /// Creates key.properties file required by signing config in build.gradle file 71 | void _createKeyProperties() { 72 | _Commons.writeStringToFile(keyPropertiesPath, """storePassword=$keystorePass 73 | keyPassword=$keyPass 74 | keyAlias=$alias 75 | storeFile=../../$keystorePath 76 | """); 77 | stdout.writeln("key properties file created"); 78 | } 79 | 80 | /// configures build.gradle with release config with the generated key details 81 | void _configureBuildConfig() { 82 | String bfString = _Commons.getFileAsString(_Commons.appBuildPath); 83 | List buildfile = _Commons.getFileAsLines(_Commons.appBuildPath); 84 | if (!bfString.contains("deft keystoreProperties") && 85 | !bfString.contains("keystoreProperties['keyAlias']")) { 86 | buildfile = buildfile.map((line) { 87 | if (line.contains(RegExp("android.*{"))) { 88 | return """ 89 | def keystoreProperties = new Properties() 90 | def keystorePropertiesFile = rootProject.file('key.properties') 91 | if (keystorePropertiesFile.exists()) { 92 | keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) 93 | } 94 | 95 | android { 96 | """; 97 | } else if (line.contains(RegExp("buildTypes.*{"))) { 98 | return """ 99 | signingConfigs { 100 | release { 101 | keyAlias keystoreProperties['keyAlias'] 102 | keyPassword keystoreProperties['keyPassword'] 103 | storeFile file(keystoreProperties['storeFile']) 104 | storePassword keystoreProperties['storePassword'] 105 | } 106 | } 107 | buildTypes { 108 | """; 109 | } else if (line.contains("signingConfig signingConfigs.debug")) { 110 | return " signingConfig signingConfigs.release"; 111 | } else { 112 | return line; 113 | } 114 | }).toList(); 115 | 116 | _Commons.writeStringToFile(_Commons.appBuildPath, buildfile.join("\n")); 117 | stdout.writeln("configured release configs"); 118 | } else { 119 | stdout.writeln("release configs already configured"); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /lib/commons.dart: -------------------------------------------------------------------------------- 1 | part of flutter_automation; 2 | 3 | class _Commons { 4 | static final String basePath = "./lib"; 5 | static final String pubspecPath = './pubspec.yaml'; 6 | static final String stringsPath = 7 | "./android/app/src/main/res/values/strings.xml"; 8 | static final String manifestPath = 9 | "./android/app/src/main/AndroidManifest.xml"; 10 | static final String appBuildPath = "./android/app/build.gradle"; 11 | 12 | /// Default plugin versions 13 | static Map defaultConfig = { 14 | "plugins": { 15 | "firebase_auth": "^0.14.0+5", 16 | "google_sign_in": "^4.0.7", 17 | "provider": "^3.1.0", 18 | "google_maps": "^0.5.21+2", 19 | "firestore": "^0.12.9+4" 20 | }, 21 | "google_services": "4.3.3" 22 | }; 23 | 24 | /// Loads config either from the flutter_automation.yaml config file or default config 25 | static Map loadConfig() { 26 | if (!File("./flutter_automation.yaml").existsSync()) return defaultConfig; 27 | String configcontent = File("./flutter_automation.yaml").readAsStringSync(); 28 | var configFile = loadYaml(configcontent); 29 | return Map.from(configFile); 30 | } 31 | 32 | static bool fileContainsString(String path, String pattern) { 33 | String file = getFileAsString(path); 34 | return file.contains(pattern); 35 | } 36 | 37 | static bool pluginExists(String plugin) { 38 | return fileContainsString(pubspecPath, plugin); 39 | } 40 | 41 | /// Adds provided dependencies to pubspec.yaml file 42 | static void addDependencise(String dependencies) { 43 | replaceFirstStringInfile( 44 | pubspecPath, "dev_dependencies:", "$dependencies\ndev_dependencies:"); 45 | } 46 | 47 | /// replace string in a file at [path] from [from] to [to] 48 | static void replaceFirstStringInfile(String path, Pattern from, String to) { 49 | String contents = getFileAsString(path); 50 | contents = contents.replaceFirst(from, to); 51 | writeStringToFile(path, contents); 52 | } 53 | 54 | /// Reads a file at [path] as string 55 | static String getFileAsString(String path) { 56 | return File(path).readAsStringSync(); 57 | } 58 | 59 | /// writes a string [contents] to a file at [path] 60 | static void writeStringToFile(String path, String contents) { 61 | File(path).writeAsStringSync(contents); 62 | } 63 | 64 | /// Reads a file at [path] as a list of lines 65 | static List getFileAsLines(String path) { 66 | return File(path).readAsLinesSync(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/flutter_automation.dart: -------------------------------------------------------------------------------- 1 | library flutter_automation; 2 | 3 | import 'dart:convert'; 4 | import 'dart:io'; 5 | 6 | import 'package:args/args.dart'; 7 | import 'package:http/http.dart' as http; 8 | import 'package:yaml/yaml.dart'; 9 | 10 | part './google_maps.dart'; 11 | part './android_signing.dart'; 12 | part './pubspec_api.dart'; 13 | part './commons.dart'; 14 | part './gen/helper.dart'; 15 | 16 | /// Deciphers which scripts to run based on the arguments provided by the user 17 | /// Use `flutter pub pub run flutter_automation -h` to get help 18 | void decipherScript(List arguments) async { 19 | var parser = ArgParser(allowTrailingOptions: true); 20 | parser.addFlag('help', abbr: 'h', negatable: false, help: "Usage help"); 21 | 22 | parser.addFlag('google-maps', 23 | abbr: 'g', help: "Adds google maps", negatable: false); 24 | 25 | parser.addFlag("android-sign", 26 | abbr: 's', help: "Setups android signing config", negatable: false); 27 | 28 | var genParser = ArgParser(allowTrailingOptions: true); 29 | parser.addCommand("gen", genParser); 30 | genParser.addOption("path", 31 | abbr: "p", 32 | help: "Base path, defaults to ${_Commons.basePath}", 33 | defaultsTo: _Commons.basePath); 34 | genParser.addFlag( 35 | "core", 36 | abbr: "c", 37 | help: "Generates core directory instead of feature directory", 38 | negatable: false, 39 | ); 40 | 41 | var argResults = parser.parse(arguments); 42 | if (argResults.command?.name == "gen") { 43 | final genArgResults = genParser.parse(argResults.command!.arguments); 44 | if (genArgResults["core"]) { 45 | _genCore(path: genArgResults["path"]); 46 | } else { 47 | _genFeatureDirectory( 48 | path: genArgResults["path"], 49 | feature: argResults.command!.arguments.first); 50 | } 51 | return; 52 | } 53 | if (argResults['help'] || argResults.arguments.length < 1) { 54 | stdout.write('Automation scripts for flutter'); 55 | stdout.write(parser.usage); 56 | stdout.writeln("\n"); 57 | stdout.writeln( 58 | "[Command: gen] - flutter pub run flutter_automation gen "); 59 | stdout.writeln("Options:"); 60 | stdout.writeln(genParser.usage); 61 | return; 62 | } 63 | 64 | if (argResults['google-maps']) { 65 | await googleMaps(); 66 | } 67 | 68 | if (argResults['android-sign']) { 69 | _androidSign(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/gen/helper.dart: -------------------------------------------------------------------------------- 1 | part of flutter_automation; 2 | 3 | void _genFeatureDirectory({String path = '', String? feature}) { 4 | _genBaseDirs("$path/features/$feature"); 5 | } 6 | 7 | void _genBaseDirs(String path) { 8 | Directory("$path/data/models").createSync(recursive: true); 9 | stdout.writeln("models directory created"); 10 | Directory("$path/data/services").createSync(recursive: true); 11 | stdout.writeln("services directory created"); 12 | Directory("$path/presentation/pages").createSync(recursive: true); 13 | stdout.writeln("pages directory created"); 14 | Directory("$path/presentation/widgets").createSync(recursive: true); 15 | stdout.writeln("widgets directory created"); 16 | Directory("$path/res").createSync(recursive: true); 17 | stdout.writeln("resource directory created"); 18 | } 19 | 20 | void _genCore({String path = ''}) { 21 | final core = "$path/core"; 22 | _genBaseDirs(core); 23 | final dbConstants = File("$core/res/db_constants.dart"); 24 | if (!dbConstants.existsSync()) { 25 | dbConstants.writeAsStringSync(""" 26 | class DBConstants { 27 | 28 | } 29 | """); 30 | stdout.writeln("db constants file created"); 31 | } 32 | 33 | final appConstants = File("$core/res/app_constants.dart"); 34 | if (!appConstants.existsSync()) { 35 | appConstants.writeAsStringSync(""" 36 | class AppConstants { 37 | static const String appName = "Flutter Automation App"; 38 | } 39 | """); 40 | stdout.writeln("app constants file created"); 41 | } 42 | 43 | final assets = File("$core/res/assets.dart"); 44 | if (!assets.existsSync()) { 45 | assets.writeAsStringSync(""" 46 | class AppAssets { 47 | static const String appIcon = "assets/icon.png"; 48 | } 49 | """); 50 | 51 | stdout.writeln("assets file created"); 52 | } 53 | 54 | final colors = File("$core/res/colors.dart"); 55 | if (!colors.existsSync()) { 56 | colors.writeAsStringSync(""" 57 | import 'package:flutter/material.dart'; 58 | 59 | class AppColors { 60 | static final Color primaryColor = Colors.red; 61 | } 62 | """); 63 | stdout.writeln("colors file created"); 64 | } 65 | 66 | final routes = File("$core/res/routes.dart"); 67 | if (!routes.existsSync()) { 68 | routes.writeAsStringSync(""" 69 | import 'package:flutter/material.dart'; 70 | 71 | class AppRoutes { 72 | static const String home = "home"; 73 | 74 | static Route generateRoute(RouteSettings settings) { 75 | switch (settings.name) { 76 | case home: 77 | default: 78 | return _buildRoute( 79 | settings, 80 | Scaffold( 81 | body: Center( 82 | child: Text("Page for route \${settings.name} is not found"), 83 | ), 84 | ), 85 | ); 86 | } 87 | } 88 | 89 | static Route _buildRoute(RouteSettings settings, Widget builder, 90 | [bool fullScreenDialog = false]) { 91 | return MaterialPageRoute( 92 | fullscreenDialog: fullScreenDialog, 93 | settings: settings, 94 | builder: (_) => builder, 95 | ); 96 | } 97 | } 98 | """); 99 | stdout.writeln("routes file created"); 100 | } 101 | 102 | final sizes = File("$core/res/sizes.dart"); 103 | if (!sizes.existsSync()) { 104 | sizes.writeAsStringSync(""" 105 | class AppSizes { 106 | static const double borderRadius=10.0; 107 | } 108 | """); 109 | stdout.writeln("sizes file created"); 110 | } 111 | 112 | final themes = File("$core/res/themes.dart"); 113 | if (!themes.existsSync()) { 114 | themes.writeAsStringSync(""" 115 | import 'package:flutter/material.dart'; 116 | 117 | class AppThemes { 118 | static final ThemeData defaultTheme = ThemeData( 119 | primarySwatch: Colors.red, 120 | appBarTheme: AppBarTheme(), 121 | buttonTheme: ButtonThemeData(), 122 | ); 123 | } 124 | """); 125 | stdout.writeln("themes file created"); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /lib/google_maps.dart: -------------------------------------------------------------------------------- 1 | part of flutter_automation; 2 | 3 | /// Main google maps setup plugin 4 | Future googleMaps() async { 5 | await addGoogleMap(); 6 | setupApiKey(); 7 | addKeyToManifest(); 8 | stdout.writeln("google maps successfully setup"); 9 | } 10 | 11 | /// adds google maps dependency to pubspec.yaml file 12 | Future addGoogleMap() async { 13 | if (_Commons.pluginExists("google_maps_flutter")) return; 14 | String? plugin = await _PubspecAPI().getPackage('google_maps_flutter'); 15 | if (plugin == null) 16 | plugin = 17 | "google_maps_flutter: ${_Commons.loadConfig()['plugins']['google_maps']}"; 18 | _Commons.addDependencise(" $plugin"); 19 | stdout.writeln("added google maps plugin to pubspec"); 20 | } 21 | 22 | /// setups a map api key configuration. Please replace YOUR_API_KEY with your actual api key 23 | void setupApiKey() { 24 | _Commons.writeStringToFile( 25 | _Commons.stringsPath, """ 26 | 27 | YOUR_API_KEY 28 | 29 | """); 30 | stdout.writeln( 31 | "created strings.xml with map api key. Open ${_Commons.stringsPath} and replace YOUR_API_KEY with your google maps api key"); 32 | } 33 | 34 | /// writes api key meta data to app manifest file 35 | void addKeyToManifest() { 36 | if (_Commons.fileContainsString( 37 | _Commons.manifestPath, 38 | "com.google.android.geo.API_KEY", 39 | )) return; 40 | String apiKey = 41 | ""; 42 | _Commons.replaceFirstStringInfile( 43 | _Commons.manifestPath, " getPackage(String package) async { 7 | http.Response res = await http.get(Uri.parse(baseUrl + package)); 8 | if (res.statusCode == 200) { 9 | Map resJson = json.decode(res.body); 10 | _PubPackage package = _PubPackage.fromMap(resJson); 11 | return "${package.name}: ^${package.latest.version}"; 12 | } else { 13 | return null; 14 | } 15 | } 16 | } 17 | 18 | class _PubPackage { 19 | final String? name; 20 | final _Version latest; 21 | 22 | _PubPackage(this.name, this.latest); 23 | 24 | _PubPackage.fromMap(Map data) 25 | : name = data["name"], 26 | latest = _Version.fromMap(data["latest"]); 27 | } 28 | 29 | class _Version { 30 | final String? version; 31 | final String? archiveUrl; 32 | 33 | _Version(this.version, this.archiveUrl); 34 | 35 | _Version.fromMap(Map data) 36 | : version = data["version"], 37 | archiveUrl = data["archive_url"]; 38 | } 39 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | args: 5 | dependency: "direct main" 6 | description: 7 | name: args 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.1.1" 11 | async: 12 | dependency: transitive 13 | description: 14 | name: async 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.6.1" 18 | boolean_selector: 19 | dependency: transitive 20 | description: 21 | name: boolean_selector 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.1.0" 25 | characters: 26 | dependency: transitive 27 | description: 28 | name: characters 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.1.0" 32 | charcode: 33 | dependency: transitive 34 | description: 35 | name: charcode 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.2.0" 39 | clock: 40 | dependency: transitive 41 | description: 42 | name: clock 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.1.0" 46 | collection: 47 | dependency: transitive 48 | description: 49 | name: collection 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.15.0" 53 | fake_async: 54 | dependency: transitive 55 | description: 56 | name: fake_async 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.2.0" 60 | flutter: 61 | dependency: "direct main" 62 | description: flutter 63 | source: sdk 64 | version: "0.0.0" 65 | flutter_test: 66 | dependency: "direct dev" 67 | description: flutter 68 | source: sdk 69 | version: "0.0.0" 70 | http: 71 | dependency: "direct main" 72 | description: 73 | name: http 74 | url: "https://pub.dartlang.org" 75 | source: hosted 76 | version: "0.13.3" 77 | http_parser: 78 | dependency: transitive 79 | description: 80 | name: http_parser 81 | url: "https://pub.dartlang.org" 82 | source: hosted 83 | version: "4.0.0" 84 | matcher: 85 | dependency: transitive 86 | description: 87 | name: matcher 88 | url: "https://pub.dartlang.org" 89 | source: hosted 90 | version: "0.12.10" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "1.3.0" 98 | path: 99 | dependency: transitive 100 | description: 101 | name: path 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "1.8.0" 105 | pedantic: 106 | dependency: transitive 107 | description: 108 | name: pedantic 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "1.11.1" 112 | sky_engine: 113 | dependency: transitive 114 | description: flutter 115 | source: sdk 116 | version: "0.0.99" 117 | source_span: 118 | dependency: transitive 119 | description: 120 | name: source_span 121 | url: "https://pub.dartlang.org" 122 | source: hosted 123 | version: "1.8.1" 124 | stack_trace: 125 | dependency: transitive 126 | description: 127 | name: stack_trace 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "1.10.0" 131 | stream_channel: 132 | dependency: transitive 133 | description: 134 | name: stream_channel 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "2.1.0" 138 | string_scanner: 139 | dependency: transitive 140 | description: 141 | name: string_scanner 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "1.1.0" 145 | term_glyph: 146 | dependency: transitive 147 | description: 148 | name: term_glyph 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "1.2.0" 152 | test_api: 153 | dependency: transitive 154 | description: 155 | name: test_api 156 | url: "https://pub.dartlang.org" 157 | source: hosted 158 | version: "0.3.0" 159 | typed_data: 160 | dependency: transitive 161 | description: 162 | name: typed_data 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "1.3.0" 166 | vector_math: 167 | dependency: transitive 168 | description: 169 | name: vector_math 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "2.1.0" 173 | yaml: 174 | dependency: "direct main" 175 | description: 176 | name: yaml 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "3.1.0" 180 | sdks: 181 | dart: ">=2.12.0 <3.0.0" 182 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_automation 2 | description: A flutter package that provides various automation scripts to help 3 | you with your flutter project. 4 | version: 2.0.0 5 | author: Damodar Lohani 6 | homepage: https://github.com/lohanidamodar/flutter_automation 7 | 8 | environment: 9 | sdk: '>=2.12.0 <3.0.0' 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | args: ^2.1.1 15 | yaml: ^3.1.0 16 | http: ^0.13.3 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | 22 | --------------------------------------------------------------------------------