4、Flutter开发-导入并升级flutter-go示例

简介: 因Flutter升级,FlutterGo暂停维护,这里导入的项目只能切回到旧版本,这里为了适应新版本的Flutter和Dart,我们新建项目,升级flutter-go,并记录学习。1、按照之前章节,新建一个flutter_go的Flutter项目,修改build.gradle文件

  因Flutter升级,FlutterGo暂停维护,这里导入的项目只能切回到旧版本,这里为了适应新版本的Flutter和Dart,我们新建项目,升级flutter-go,并记录学习。


1、按照之前章节,新建一个flutter_go的Flutter项目,修改build.gradle文件


buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
//        google()
//        jcenter()
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
        maven { url 'https://storage.googleapis.com/download.flutter.io' }
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
allprojects {
    repositories {
//        google()
//        jcenter()
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
        maven { url 'https://storage.googleapis.com/download.flutter.io' }
        maven { url 'https://maven.fabric.io/public' }
    }
}
rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
    delete rootProject.buildDir
}


2、首先修改pubspec.yaml文件,将依赖库dependencies升级到最新版本,将静态文件和widgets添加到配置中。


name: flutter_go
description: Flutter GO application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
  sdk: ">=2.7.0 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.0
dev_dependencies:
  flutter_test:
    sdk: flutter
  bloc: ^2.0.0
  flutter_bloc: ^2.0.0
  dio: ^3.0.10
  dio_cookie_manager: 1.0.0
  html: ^0.14.0+4
  event_bus: ^1.1.0
  sqflite: ^1.3.1+2
  pull_to_refresh: ^1.6.2
  fluro: ^1.7.3
  firebase_analytics: ^6.0.2
  #firebase_auth: ^0.8.3 #auth
  firebase_core: ^0.5.0+1 # add dependency for Firebase Core
  package_info: ^0.4.3
  url_launcher: ^5.7.5
  cookie_jar: ^1.0.1
  path_provider: ^1.6.21
  # 本地存储、收藏功能
  shared_preferences: ^0.5.12+2
  share: ^0.6.5+3
  flutter_spinkit: ^4.1.2
  zefyr: ^0.12.0
  fluttertoast: ^7.1.1
  flutter_webview_plugin: ^0.3.11
  city_pickers: ^0.2.0
  image_picker: ^0.5.0
  flutter_jpush: ^0.0.4
  markdown: ^3.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - lib/widgets/elements/Form/Input/TextField/text_field_demo.dart
    - lib/widgets/elements/Form/CheckBox/Checkbox/demo.dart
    - lib/widgets/components/Bar/AppBar/demo.dart
    - lib/widgets/components/Bar/BottomAppBar/demo.dart
    - lib/widgets/components/Bar/ButtonBar/demo.dart
    - lib/widgets/components/Bar/FlexibleSpaceBar/demo.dart
    - lib/widgets/components/Bar/SliverAppBar/demo.dart
    - lib/widgets/components/Bar/SnackBar/demo.dart
    - lib/widgets/components/Bar/SnackBarAction/demo.dart
    - lib/widgets/components/Bar/TabBar/demo.dart
    - lib/widgets/components/Card/Card/demo.dart
    - lib/widgets/components/Chip/Chip/demo.dart
    - lib/widgets/components/Chip/ChipTheme/demo.dart
    - lib/widgets/components/Chip/ChipThemeData/demo.dart
    - lib/widgets/components/Chip/ChoiceChip/demo.dart
    - lib/widgets/components/Chip/FilterChip/demo.dart
    - lib/widgets/components/Chip/InputChip/demo.dart
    - lib/widgets/components/Chip/RawChip/demo.dart
    - lib/widgets/components/Dialog/AboutDialog/demo.dart
    - lib/widgets/components/Dialog/AlertDialog/demo.dart
    - lib/widgets/components/Dialog/Dialog/demo.dart
    - lib/widgets/components/Dialog/SimpleDialog/demo.dart
    - lib/widgets/components/Grid/GridTile/demo.dart
    - lib/widgets/components/Grid/GridTileBar/demo.dart
    - lib/widgets/components/Grid/GridView/demo.dart
    - lib/widgets/components/Grid/GridPaper/demo.dart
    - lib/widgets/components/Grid/SliverGrid/demo.dart
    - lib/widgets/components/List/AnimatedList/demo.dart
    - lib/widgets/components/List/ListBody/demo.dart
    - lib/widgets/components/List/ListView/demo.dart
    - lib/widgets/components/Menu/CheckedPopupMenuItem/demo.dart
    - lib/widgets/components/Menu/DropdownMenuItem/demo.dart
    - lib/widgets/components/Menu/PopupMenuButton/demo.dart
    - lib/widgets/components/Menu/PopupMenuDivider/demo.dart
    - lib/widgets/components/Navigation/BottomNavigationBar/demo.dart
    - lib/widgets/components/Navigation/BottomNavigationBarItem/demo.dart
    - lib/widgets/components/Panel/ExpansionPanel/demo.dart
    - lib/widgets/components/Panel/ExpansionPanelList/demo.dart
    - lib/widgets/components/Pick/DayPicker/demo.dart
    - lib/widgets/components/Pick/MonthPicker/demo.dart
    - lib/widgets/components/Pick/ShowdatePicker/demo.dart
    - lib/widgets/components/Pick/YearPicker/demo.dart
    - lib/widgets/components/Progress/CircularProgressIndicator/demo.dart
    - lib/widgets/components/Progress/LinearProgressIndicator/demo.dart
    - lib/widgets/components/Progress/RefreshProgressIndicator/demo.dart
    - lib/widgets/components/Scaffold/Scaffold/demo.dart
    - lib/widgets/components/Scaffold/ScaffoldState/demo.dart
    - lib/widgets/components/Scroll/BoxScrollView/demo.dart
    - lib/widgets/components/Scroll/CustomScrollView/demo.dart
    - lib/widgets/components/Scroll/NestedScrollView/demo.dart
    - lib/widgets/components/Scroll/Scrollable/demo.dart
    - lib/widgets/components/Scroll/ScrollbarPainter/demo.dart
    - lib/widgets/components/Scroll/ScrollMetrics/demo.dart
    - lib/widgets/components/Scroll/ScrollPhysics/demo.dart
    - lib/widgets/components/Scroll/ScrollView/demo.dart
    - lib/widgets/components/Tab/Tab/demo.dart
    - lib/widgets/elements/Form/Button/DropdownButton/demo.dart
    - lib/widgets/elements/Form/Button/FlatButton/demo.dart
    - lib/widgets/elements/Form/Button/FloatingActionButton/demo.dart
    - lib/widgets/elements/Form/Button/IconButton/demo.dart
    - lib/widgets/elements/Form/Button/OutlineButton/demo.dart
    - lib/widgets/elements/Form/Button/PopupMenuButton/demo.dart
    - lib/widgets/elements/Form/Button/RaisedButton/demo.dart
    - lib/widgets/elements/Form/Button/RawMaterialButton/demo.dart
    - lib/widgets/elements/Form/CheckBox/Checkbox/demo.dart
    - lib/widgets/elements/Form/CheckBox/CheckboxListTile/demo.dart
    - lib/widgets/elements/Form/Radio/Radio/demo.dart
    - lib/widgets/elements/Form/Radio/RadioListTile/demo.dart
    - lib/widgets/elements/Form/Slider/Slider/demo.dart
    - lib/widgets/elements/Form/Slider/SliderTheme/demo.dart
    - lib/widgets/elements/Form/Slider/SliderThemeData/demo.dart
    - lib/widgets/elements/Form/Switch/AnimatedSwitcher/demo.dart
    - lib/widgets/elements/Form/Switch/Switch/demo.dart
    - lib/widgets/elements/Form/Switch/SwitchListTile/demo.dart
    - lib/widgets/elements/Frame/Align/Align/demo.dart
    - lib/widgets/elements/Frame/Box/ConstrainedBox/demo.dart
    - lib/widgets/elements/Frame/Box/DecoratedBox/demo.dart
    - lib/widgets/elements/Frame/Box/FittedBox/demo.dart
    - lib/widgets/elements/Frame/Box/LimitedBox/demo.dart
    - lib/widgets/elements/Frame/Box/OverflowBox/demo.dart
    - lib/widgets/elements/Frame/Box/RotatedBox/demo.dart
    - lib/widgets/elements/Frame/Box/SizeBox/demo.dart
    - lib/widgets/elements/Frame/Box/SizedOverflowBox/demo.dart
    - lib/widgets/elements/Form/Text/Text/demo.dart
    - lib/widgets/elements/Form/Text/RichText/index.dart
    - lib/widgets/elements/Frame/Box/UnconstrainedBox/demo.dart
    - lib/widgets/elements/Frame/Expanded/Expanded/expanded_demo.dart
    - lib/widgets/elements/Frame/Layout/Center/demo.dart
    - lib/widgets/elements/Frame/Layout/Column/demo.dart
    - lib/widgets/elements/Frame/Layout/Container/demo.dart
    - lib/widgets/elements/Frame/Layout/Row/demo.dart
    - lib/widgets/elements/Frame/Spacing/AnimatedPadding/animatedPadding_demo.dart
    - lib/widgets/elements/Frame/Spacing/Padding/padding_demo.dart
    - lib/widgets/elements/Frame/Spacing/SliverPadding/sliverpadding_demo.dart
    - lib/widgets/elements/Frame/Stack/IndexedStack/demo.dart
    - lib/widgets/elements/Frame/Stack/Stack/demo.dart
    - lib/widgets/elements/Frame/Table/Table/table_demo.dart
    - lib/widgets/elements/Media/Icon/Icon/demo.dart
    - lib/widgets/elements/Media/Icon/IconData/demo.dart
    - lib/widgets/elements/Media/Icon/IconTheme/demo.dart
    - lib/widgets/elements/Media/Icon/IconThemeData/demo.dart
    - lib/widgets/elements/Media/Icon/ImageIcon/demo.dart
    - lib/widgets/elements/Media/Image/AssetImage/assetImage_demo.dart
    - lib/widgets/elements/Media/Image/DecorationImage/decorationImage_demo.dart
    - lib/widgets/elements/Media/Image/DecorationImagePainter/decoration_image_painter_demo.dart
    - lib/widgets/elements/Media/Image/ExactAssetImage/exact_asset_image_demo.dart
    - lib/widgets/elements/Media/Image/FadeInImage/fade_in_image_demo.dart
    - lib/widgets/elements/Media/Image/FileImage/file_image_demo.dart
    - lib/widgets/elements/Media/Image/Image/demo.dart
    - lib/widgets/elements/Media/Image/MemoryImage/memory_image_demo.dart
    - lib/widgets/elements/Media/Image/NetworkImage/network_image_demo.dart
    - lib/widgets/elements/Media/Image/paintImage/paint_image_demo.dart
    - lib/widgets/elements/Media/Image/precacheImage/precache_image_demo.dart
    - lib/widgets/elements/Media/Image/RawImage/raw_image_demo.dart
    - lib/widgets/elements/Media/Canvas/Canvas/demo.dart
    - lib/widgets/elements/Media/Canvas/CircleProgressBarPainter/demo.dart
    - lib/widgets/elements/Media/Canvas/PainterPath/demo.dart
    - lib/widgets/elements/Media/Canvas/PainterSketch/demo.dart
    - lib/widgets/themes/Material/MaterialApp/demo.dart
    - lib/widgets/themes/Material/MaterialButton/demo.dart
    - lib/widgets/themes/Material/MaterialColor/demo.dart
    - lib/widgets/themes/Material/MaterialPageRoute/demo.dart
    - lib/widgets/themes/Material/MergeableMaterialItem/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoApp/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoButton/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoColors/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoIcons/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoNavigationBar/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoPageRoute/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoPageScaffold/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoPicker/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoPopupSurface/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoScrollbar/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoSegmentedControl/demo.dart
    - lib/widgets/elements/Form/Switch/Switch/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoSlider/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoSliverNavigationBar/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoSwitch/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoTabBar/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoTabScaffold/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoTabView/demo.dart
    - lib/widgets/themes/Cupertino/CupertinoTimerPicker/demo.dart
    - lib/page_demo_package/.demo.json
    - lib/standard_pages/.pages.json
    - assets/app.db
    - assets/images/
    - assets/fonts/
  fonts:
    - family: FlamanteRoma
      fonts:
        - asset: assets/fonts/Flamante-Roma-Medium.ttf
        - asset: assets/fonts/Flamante-Roma-MediumItalic.ttf
    - family: LatoBold
      fonts:
        - asset: assets/fonts/Lato-Bold.ttf
  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages


3、将下载下来的FlutterGo项目中main.dart代码复制到我们新建的main.dart中,点击Android Studio右上角的Get Dependencies,下载依赖包,下载完成之后,代码中有很多报错,我们一步一步修改,先将不需要的代码注释掉,只保留首页需要用到的代码。


4、复制FlutterGo项目中lib/api,lib/blocs,lib/components,lib/event,lib/model,lib/page_demo_package,lib/resources,lib/routers,lib/standard_pages,lib/utils,lib/widgets文件夹下所有代码到新建的项目中,将FlutterGo项目中assets文件夹复制到新建项目的根目录下。


5、修改main.dart,application.dart,routers.dart文件中的Router为FluroRouter,因fluro最新版本升级,Router命名有修改。


6、修改net_utils.dart文件,引入import

'package:dio_cookie_manager/dio_cookie_manager.dart';


7、修改search_input.dart文件,将isInitialRoute: false,修改为arguments: {'isInitialRoute': false}


8、注释掉报错的导入,暂时只保留views里面首页相关页面。


9、修改flutter_go\android\app\src\main\AndroidManifest.xml文件,添加


<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MODE_WORLD_READABLE" />
    <uses-permission android:name="android.permission.MODE_WORLD_WRITEABLE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


10、修改flutter_go\android\app\build.gradle文件,将以下代码复制到defaultConfig标签里。


manifestPlaceholders = [
                JPUSH_PKGNAME : "com.alibaba.fluttergo",
                JPUSH_APPKEY : "62eb07d227d1f11dd7fa6239", //JPush上注册的包名对应的appkey.
                JPUSH_CHANNEL : "developer-default",
        ]


11、在lib下新建views目录,将FlutterGo项目中login_page,first_page目录和home.dart文件复制进去,然后修改login_page.dart中的timeInSecForIos为timeInSecForIosWeb。


12、修改search_page.dart文件中的suggestion.dispatch为suggestion.add


13、将FlutterGo中的welcome_page和fourth_page目录复制到我们新建的项目中。修改fourth_page.dart文件中的import 'package:flutter/material.dart'; 改为import 'package:flutter/material.dart' hide Page;


14、将FlutterGo中的lib/views下的widget_page,collection_page,issuse_message_page,standard_demo_page目录复制到我们新建的项目中。修改issuse_message_page.dart文件,将timeInSecForIos改为timeInSecForIosWeb,将ZefyrToolbarTheme改为ToolbarTheme


15、将FlutterGo下的lib/widgets目录复制到我们新建的项目中。


注意事项:


1、将classpath 'io.fabric.tools:gradle:1.26.1'改为classpath 'io.fabric.tools:gradle:1.25.4'


2、A problem occurred configuring project ':city_pickers'.


3、将Router改为FluroRouter


4、欢迎页不展示,以及图标不展示,打开注释掉的welcome page


5、如果jar包不能下载,将maven { url 'https://storage.googleapis.com/download.flutter.io' }放到maven { url 'https://maven.fabric.io/public' }上面

相关文章
|
2月前
|
缓存 弹性计算 API
用 Go 快速开发一个 RESTful API 服务
用 Go 快速开发一个 RESTful API 服务
|
8天前
|
开发框架 移动开发 Android开发
安卓与iOS开发中的跨平台解决方案:Flutter入门
【9月更文挑战第30天】在移动应用开发的广阔舞台上,安卓和iOS两大操作系统各自占据半壁江山。开发者们常常面临着选择:是专注于单一平台深耕细作,还是寻找一种能够横跨两大系统的开发方案?Flutter,作为一种新兴的跨平台UI工具包,正以其现代、响应式的特点赢得开发者的青睐。本文将带你一探究竟,从Flutter的基础概念到实战应用,深入浅出地介绍这一技术的魅力所在。
28 7
|
11天前
|
JSON Go API
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
|
26天前
|
JSON Dart Java
flutter开发多端平台应用的探索
flutter开发多端平台应用的探索
29 6
|
26天前
|
JSON Dart Java
flutter开发多端平台应用的探索 下 (跨模块、跨语言通信之平台通道)
flutter开发多端平台应用的探索 下 (跨模块、跨语言通信之平台通道)
|
29天前
|
安全 Android开发 开发者
探索安卓开发的未来:Kotlin的崛起与Flutter的挑战
在移动开发的广阔天地中,安卓平台始终占据着举足轻重的地位。随着技术的不断进步和开发者需求的多样化,Kotlin和Flutter成为了改变游戏规则的新玩家。本文将深入探讨Kotlin如何以其现代化的特性赢得开发者的青睐,以及Flutter凭借跨平台的能力如何挑战传统的安卓开发模式。通过实际案例分析,我们将揭示这两种技术如何塑造未来的安卓应用开发。
57 6
|
1月前
|
编解码 Dart 网络协议
Flutter如何玩转超低延迟RTSP/RTMP播放,跨平台视频流体验大升级,让你的应用秒变直播神器!
【9月更文挑战第3天】Flutter作为谷歌推出的跨平台移动UI框架,凭借高性能和丰富的生态系统广受好评。本文详细介绍如何在Flutter应用中实现低延迟的跨平台RTSP/RTMP播放,并提供具体示例代码。首先介绍了如何使用`flutter_vlc_player`播放RTSP流,然后讨论了优化视频播放以降低延迟的方法,包括调整播放器配置等。通过选用合适的播放器插件并进行优化,Flutter可在视频流播放领域提供卓越的用户体验。随着生态的发展,Flutter有望成为视频流媒体开发的首选框架。
145 6
|
2月前
|
开发框架 Android开发 iOS开发
Flutter相关痛点解决问题之淘特选择桌面端开发框架如何解决
Flutter相关痛点解决问题之淘特选择桌面端开发框架如何解决
|
2月前
|
算法 NoSQL 中间件
go语言后端开发学习(六) ——基于雪花算法生成用户ID
本文介绍了分布式ID生成中的Snowflake(雪花)算法。为解决用户ID安全性与唯一性问题,Snowflake算法生成的ID具备全局唯一性、递增性、高可用性和高性能性等特点。64位ID由符号位(固定为0)、41位时间戳、10位标识位(含数据中心与机器ID)及12位序列号组成。面对ID重复风险,可通过预分配、动态或统一分配标识位解决。Go语言实现示例展示了如何使用第三方包`sonyflake`生成ID,确保不同节点产生的ID始终唯一。
go语言后端开发学习(六) ——基于雪花算法生成用户ID
|
2月前
|
JSON 编解码 中间件
go-zero代码生成器助你高效开发
go-zero代码生成器助你高效开发