aboutsummaryrefslogtreecommitdiff
path: root/createFlutter
blob: 09f1c7c29e78858d64015602979f29a467669ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/bin/bash

if [ "$#" -ne 2 ]; then
  echo "USAGE: $0 APP_NAME DESCRIPTION"
  exit 1
fi

PROJECT_HOME=~/AndroidStudioProjects
ORG_PATH="$PROJECT_HOME/defaultOrg"
KEY_PROPERTIES_PATH="$PROJECT_HOME/defaultKeyProperties"

appName="$1"
packageName=`echo "$appName" | tr ' ' '_' | tr '[:upper:]' '[:lower:]'`
description="$2"

echo "App Name: $appName"
echo "Package Name: $packageName"
echo "Description: $description"


if [[ -f "$ORG_PATH" ]]; then
  org=`cat "$PROJECT_HOME/defaultOrg"`
else
  echo "Could not find file with default org in $ORG_PATH"
  exit 1
fi

if [[ -f "$KEY_PROPERTIES_PATH" ]]; then
  keyProperties=`cat "$PROJECT_HOME/defaultKeyProperties"`
else
  echo "Could not find file with default key properties in $KEY_PROPERTIES_PATH"
  exit 1
fi

flutter create --android-language java --org "$org" "$packageName" || exit 1

cd "$packageName"

##########################
## append to .gitignore ##
##########################

echo "android/key.properties" >> .gitignore

git init

##################################
## generate empty launcher icon ##
##################################

convert -size 2048x2048 xc:white launcherIcon.png



############################
## overwrite pubspec.yaml ##
############################

cat > pubspec.yaml <<EOF
name: $packageName
description: $description

version: 1.0.0+1

environment:
  sdk: ">=2.2.2 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  intl: ^0.15.7
  shared_preferences: ^0.5.4+8
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.7.3"

flutter_icons:
  image_path: "launcherIcon.png"
  android: true
  ios: true

flutter:
  uses-material-design: true

EOF



#########################################
## generate key.properties for signing ##
#########################################

cat > android/key.properties <<EOF
$keyProperties
EOF


############################
## overwrite build.gradle ##
############################

cat > android/app/build.gradle <<EOF
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "\$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}


android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "$org.$packageName"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

EOF

#######################
## set android label ##
#######################

sed -i "s/android:label=\"$packageName\"/android:label=\"$appName\"/" android/app/src/main/AndroidManifest.xml

#####################
## empty README.md ##
#####################
cat > README.md <<EOF
# $appName

$description

EOF


#########################
## overwrite main.dart ##
#########################
cat > lib/main.dart <<EOF
import 'package:flutter/material.dart';
import 'screens/loading.dart';

void main() {
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: Loading(),
  ));
}

EOF

####################################
## create loading and home screen ##
####################################

mkdir lib/screens

cat > lib/screens/home.dart <<EOF
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);
  static const title = '$appName';

  static void loadInitial(BuildContext context) async {
    await Future.delayed(Duration.zero, () {});
    // load some stuff here and await results
    Navigator.pushReplacement(context,
        MaterialPageRoute(builder: (context) => Home()));
  }

  static void save(BuildContext context) async {
    showDialog(context: context, barrierDismissible: false,
        builder: (BuildContext context) { return AlertDialog(content: Text("Saving...")); });
    await Future.delayed(Duration.zero, () {});
    Navigator.of(context, rootNavigator: true).pop();
  }

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int state = 1;

  void _changeState(int s) {
    setState(() {
      state = s;
    });
  }

  List<String> popupMenuItems = ["About"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(Home.title),
        actions: <Widget>[
          PopupMenuButton<String>(
            onSelected: (String value) => handleClick(context, value),
            itemBuilder: (BuildContext context) {
              return popupMenuItems.map((String choice) {
                return PopupMenuItem<String>(
                  value: choice,
                  child: Text(choice),
                );
              }).toList();
            },
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: ListView(children: [
          Text("Lorem ipsum dolor sit amet"),
        ]),
      ),
    );
  }

  void handleClick(BuildContext context, String value) {
    switch (value) {
      case 'About':
        showLicensePage(context: context, applicationName: Home.title);
    }
  }
}

EOF


cat > lib/screens/loading.dart <<EOF
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'home.dart';

class Loading extends StatefulWidget {
  @override
  _LoadingState createState() => _LoadingState();
}

class _LoadingState extends State<Loading> {
  @override
  void initState() {
    super.initState();
    Home.loadInitial(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Text("Loading..."),
        alignment: Alignment.center,
      ),
    );
  }
}

EOF


#####################
## create Makefile ##
#####################

cat > Makefile <<EOF
.PHONY: clean all launcherIcon

all: launcherIcon
	flutter pub get
	flutter build appbundle

clean:
	flutter clean

launcherIcon:
	flutter pub get
	flutter pub run "flutter_launcher_icons:main"

EOF


################
## test build ##
################

make clean launcherIcon all
make clean