Flutter 开发从 0 到 1(五)源码
Flutter 开发从 0 到 1
明天开始又要上班了,你的假期任务完成如何啊?由于平时加班太多了,实在挤不出更多时间,从开始想用 Flutter 《Flutter 开发从 0 到 1(一)需求与准备》写一个完整的 APP 已经过去三个月了,但是我没有忘记,这个国庆时间我终于完成了。Flutter 确实强大,不止跨平台,还支持桌面应用,包括 Window、macOS、Linux,以及 Web 应用,真正一套代码,全平台支持,野心可见一斑。
以上我尝试过了,打包成了 APK、macOS 桌面应用、Web 应用没问题,只能用两个字形容 Flutter:牛皮,今天先分享这个 APP 源码。
大体功能如下:
页面 | 知识点 | 效果预览 |
---|---|---|
框架 | 1、右滑菜单;2、我的收藏 | |
博客列表 | 1、布局;2、ListView 下拉刷新好和加载更多 | |
博客详情 | 1、Markdown 渲染;2、代码高亮、3、收缩 FloatingActionButton、4、收藏 | |
评论列表 | 1、布局;2、评论 | |
账户 | 1、登录、2、注册 |
如何运行
拿到源码,可以以 Web Server (web) 或 Chrome (web)运行代码, 如果你是 MacBook Pro,你还可以以 iPhone 11 Pro Max (mobile)或 macOS (desktop)运行,运行到 Android 手机,开发的时候卡在了 Running Gradle task ‘assembleDebug’…或者‘assembleRelease’,这里记录下,这时候一般在下载 Gradle 并配置项目,所以可能出现的问题一般有两种:
报错一:
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.1.1. Current version is 5.6.2. If using the gradle wrapper, try editing the distributionUrl in /Users/wuxiaolong/AndroidStudioProjects/flutter_andblog/android/gradle/wrapper/gradle-wrapper.properties to gradle-6.1.1-all.zip
Gradle 目录 windows 一般在C:\Users\用户名\.gradle\
下,macOS 一般在/Users/用户名/.gradle
下。
如果 Android Studio 开发,该路径可以在"File | Settings | Build, Execution, Deployment | Build Tools | Gradle"中修改。
我使用的是 “gradle-6.1.1” ,可以在官网 https://gradle.org/releases/ 页面下载对应的 “complete” 安装包,放在 /Users/wuxiaolong/.gradle/wrapper/dists/gradle-6.1.1-all/cfmwm155h49vnt3hynmlrsdst
目录下即可。
报错二:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:desugarDebugFileDependencies'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not download arm64_v8a_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar (io.flutter:arm64_v8a_debug:1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7)
> Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7/arm64_v8a_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar'.
> Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7/arm64_v8a_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar'.
> Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.16, storage.googleapis.com/34.64.4.112, storage.googleapis.com/34.64.4.80] failed: connect timed out
> Could not download x86_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar (io.flutter:x86_debug:1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7)
> Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7/x86_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar'.
> Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7/x86_debug-1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.jar'.
> Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.16, storage.googleapis.com/34.64.4.112, storage.googleapis.com/34.64.4.80] failed: connect timed out
解决如下:
打开项目中 build.gradle 文件
buildscript {
repositories {
//google()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
maven { url "http://download.flutter.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
allprojects {
repositories {
//google()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
maven { url "http://download.flutter.io" }
}
}
源码
对这个项目有兴趣的,不妨请我喝杯咖啡,谢谢,源码链接如下: