Skip to content

Commit b5d4dba

Browse files
committed
feat: 脚手架
1 parent 904e0c5 commit b5d4dba

File tree

85 files changed

+2687
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2687
-2
lines changed

.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release

.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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: 18116933e77adc82f80866c928266a5b4f1ed645
8+
channel: stable
9+
10+
project_type: app

README.md

+131-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,131 @@
1-
# flutter-template-simple
2-
flutter template simple
1+
## 简介
2+
3+
一个 APP 项目 mini 模板,提供 HTTP、路由、本地缓存等常用功能的封装
4+
5+
## 功能
6+
7+
```text
8+
- 身份认证
9+
- 登录
10+
- 登出
11+
12+
- HTTP
13+
- 基于三方库 Dio 封装
14+
- 响应拦截
15+
16+
- 路由
17+
- 封装 Navigator 1.0
18+
- 路由拦截
19+
20+
- 状态管理
21+
- 基于三方库 provider
22+
- 黑暗模式
23+
24+
- 本地缓存
25+
- 基于三方库 shared_preferences 的封装
26+
27+
- 其他
28+
- 项目预初始化
29+
- 两次返回确认
30+
```
31+
32+
## 目录结构
33+
34+
```
35+
# flutter_template_mini
36+
├─ assets # 静态资源
37+
│ ├─ icons # 字体图标
38+
│ ├─ images # 图片
39+
│ ├─ jsons # json 文件
40+
├─ lib
41+
│ ├─ common # 全局公共类、方法、变量等
42+
│ ├─ db # 本地缓存
43+
│ ├─ http # http
44+
│ │ ├─ api
45+
│ │ └─ request
46+
│ ├─ models # model 层
47+
│ ├─ navigator # Navigator 1.0
48+
│ ├─ pages # 所有页面
49+
│ ├─ utils # 工具类
50+
├─ └─ main.dart # 入口
51+
└─ pubspec.yaml # 包管理
52+
```
53+
54+
## 开发
55+
56+
```bash
57+
# 安装依赖
58+
flutter packages get 或 flutter pub get
59+
60+
# 分析代码
61+
flutter analyze
62+
63+
# 运行项目
64+
flutter run
65+
66+
# 如果遇到着色器渲染错误(Shader compilation error),可以运行 clean 后再 run
67+
flutter clean
68+
69+
# 安卓真机调试
70+
flutter devices
71+
flutter run
72+
73+
# 安卓打包
74+
flutter build apk
75+
```
76+
77+
## 开发环境
78+
79+
1. Flutter version 2.8.0
80+
2. Dart version 2.15.0
81+
3. Android SDK version 31.0.0
82+
83+
## 开发工具
84+
85+
1. 编辑器 Visual Studio Code
86+
2. 插件 Dart
87+
3. 插件 Flutter
88+
4. 插件 Flutter Widget Snippets
89+
90+
## Git 提交规范
91+
92+
- `feat` 增加新功能
93+
- `fix` 修复问题/BUG
94+
- `style` 代码风格相关无影响运行结果的
95+
- `perf` 优化/性能提升
96+
- `refactor` 重构
97+
- `revert` 撤销修改
98+
- `test` 测试相关
99+
- `docs` 文档/注释
100+
- `chore` 依赖更新/脚手架配置修改等
101+
- `workflow` 工作流改进
102+
- `ci` 持续集成
103+
- `types` 类型定义文件更改
104+
- `wip` 开发中
105+
- `mod` 不确定分类的修改
106+
107+
## ❓ 关于 JSON 转 Dart Model 类
108+
109+
1. 纯手写实体类(不推荐)
110+
2. 用网页自动生成工具: 根据 JSON 自动生成实体类,并 copy 到项目中(所有项目都通用)
111+
3. 使用插件 json_serializable(更适合大型项目)
112+
113+
**该脚手架采用第二种方案**
114+
115+
*JSON <——> Map <——> Dart Model 三者之间的转化是常用的技巧*
116+
117+
## ❓ 关于路由
118+
119+
1. 官方的 Navigator 1.0
120+
2. 官方的 Navigator 2.0 (Flutter 1.22 推出)
121+
3. 三方插件 fluro
122+
123+
**该脚手架采用第一种方案,并对其封装**
124+
125+
*Navigator 2.0 的概念有一定的难度*
126+
127+
## 📄 License
128+
129+
[MIT](https://github.com/un-pany/flutter-template/blob/main/LICENSE)
130+
131+
Copyright (c) 2021 UNPany

android/.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks

android/app/build.gradle

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
compileSdkVersion 31
30+
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = '1.8'
38+
}
39+
40+
sourceSets {
41+
main.java.srcDirs += 'src/main/kotlin'
42+
}
43+
44+
defaultConfig {
45+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
46+
applicationId "com.example.flutter_template_mini"
47+
minSdkVersion 22
48+
targetSdkVersion 31
49+
versionCode flutterVersionCode.toInteger()
50+
versionName flutterVersionName
51+
}
52+
53+
buildTypes {
54+
release {
55+
// TODO: Add your own signing config for the release build.
56+
// Signing with the debug keys for now, so `flutter run --release` works.
57+
signingConfig signingConfigs.debug
58+
}
59+
}
60+
}
61+
62+
flutter {
63+
source '../..'
64+
}
65+
66+
dependencies {
67+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.flutter_template_mini">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.flutter_template_mini">
3+
<application
4+
android:label="flutter_template_mini"
5+
android:icon="@mipmap/ic_launcher">
6+
<activity
7+
android:name=".MainActivity"
8+
android:launchMode="singleTop"
9+
android:theme="@style/LaunchTheme"
10+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
11+
android:hardwareAccelerated="true"
12+
android:windowSoftInputMode="adjustResize">
13+
<!-- Specifies an Android theme to apply to this Activity as soon as
14+
the Android process has started. This theme is visible to the user
15+
while the Flutter UI initializes. After that, this theme continues
16+
to determine the Window background behind the Flutter UI. -->
17+
<meta-data
18+
android:name="io.flutter.embedding.android.NormalTheme"
19+
android:resource="@style/NormalTheme"
20+
/>
21+
<!-- Displays an Android View that continues showing the launch screen
22+
Drawable until Flutter paints its first frame, then this splash
23+
screen fades out. A splash screen is useful to avoid any visual
24+
gap between the end of Android's launch screen and the painting of
25+
Flutter's first frame. -->
26+
<meta-data
27+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28+
android:resource="@drawable/launch_background"
29+
/>
30+
<intent-filter>
31+
<action android:name="android.intent.action.MAIN"/>
32+
<category android:name="android.intent.category.LAUNCHER"/>
33+
</intent-filter>
34+
</activity>
35+
<!-- Don't delete the meta-data below.
36+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
37+
<meta-data
38+
android:name="flutterEmbedding"
39+
android:value="2" />
40+
</application>
41+
<!--允许程序打开网络套接字-->
42+
<uses-permission android:name="android.permission.INTERNET" />
43+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.example.flutter_template_mini
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity: FlutterActivity() {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>

0 commit comments

Comments
 (0)