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' }上面

相关文章
|
1月前
|
Android开发 iOS开发 容器
鸿蒙harmonyos next flutter混合开发之开发FFI plugin
鸿蒙harmonyos next flutter混合开发之开发FFI plugin
|
2天前
|
传感器 前端开发 Android开发
在 Flutter 开发中,插件开发与集成至关重要,它能扩展应用功能,满足复杂业务需求
在 Flutter 开发中,插件开发与集成至关重要,它能扩展应用功能,满足复杂业务需求。本文深入探讨了插件开发的基本概念、流程、集成方法、常见类型及开发实例,如相机插件的开发步骤,同时强调了版本兼容性、性能优化等注意事项,并展望了插件开发的未来趋势。
12 2
|
8天前
|
JSON 安全 Go
Go语言中使用JWT鉴权、Token刷新完整示例,拿去直接用!
本文介绍了如何在 Go 语言中使用 Gin 框架实现 JWT 用户认证和安全保护。JWT(JSON Web Token)是一种轻量、高效的认证与授权解决方案,特别适合微服务架构。文章详细讲解了 JWT 的基本概念、结构以及如何在 Gin 中生成、解析和刷新 JWT。通过示例代码,展示了如何在实际项目中应用 JWT,确保用户身份验证和数据安全。完整代码可在 GitHub 仓库中查看。
39 1
|
20天前
|
Go 数据安全/隐私保护 开发者
Go语言开发
【10月更文挑战第26天】Go语言开发
33 3
|
22天前
|
Java 程序员 Go
Go语言的开发
【10月更文挑战第25天】Go语言的开发
29 3
|
1月前
|
开发者
鸿蒙Flutter实战:07-混合开发
鸿蒙Flutter混合开发支持两种模式:1) 基于har包,便于主项目开发者无需关心Flutter细节,但不支持热重载;2) 基于源码依赖,利于代码维护与热重载,需配置Flutter环境。项目结构包括AppScope、flutter_module等目录,适用于不同开发需求。
77 3
|
19天前
|
传感器 开发框架 物联网
鸿蒙next选择 Flutter 开发跨平台应用的原因
鸿蒙(HarmonyOS)是华为推出的一款旨在实现多设备无缝连接的操作系统。为了实现这一目标,鸿蒙选择了 Flutter 作为主要的跨平台应用开发框架。Flutter 的跨平台能力、高性能、丰富的生态支持和与鸿蒙系统的良好兼容性,使其成为理想的选择。通过 Flutter,开发者可以高效地构建和部署多平台应用,推动鸿蒙生态的快速发展。
139 0
|
21天前
|
Dart 安全 UED
Flutter&鸿蒙next中的表单封装:提升开发效率与用户体验
在移动应用开发中,表单是用户与应用交互的重要界面。本文介绍了如何在Flutter中封装表单,以提升开发效率和用户体验。通过代码复用、集中管理和一致性的优势,封装表单组件可以简化开发流程。文章详细讲解了Flutter表单的基础、封装方法和表单验证技巧,帮助开发者构建健壮且用户友好的应用。
61 0
|
1月前
|
开发框架 移动开发 Android开发
安卓与iOS开发中的跨平台解决方案:Flutter入门
【9月更文挑战第30天】在移动应用开发的广阔舞台上,安卓和iOS两大操作系统各自占据半壁江山。开发者们常常面临着选择:是专注于单一平台深耕细作,还是寻找一种能够横跨两大系统的开发方案?Flutter,作为一种新兴的跨平台UI工具包,正以其现代、响应式的特点赢得开发者的青睐。本文将带你一探究竟,从Flutter的基础概念到实战应用,深入浅出地介绍这一技术的魅力所在。
80 7
|
2月前
|
JSON Go API
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
使用Go语言和Gin框架构建RESTful API:GET与POST请求示例
下一篇
无影云桌面