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

相关文章
|
18天前
|
缓存 监控 前端开发
【Flutter 前端技术开发专栏】Flutter 应用的启动优化策略
【4月更文挑战第30天】本文探讨了Flutter应用启动优化策略,包括理解启动过程、资源加载优化、减少初始化工作、界面布局简化、异步初始化、预加载关键数据、性能监控分析以及案例和未来优化方向。通过这些方法,可以缩短启动时间,提升用户体验。使用Flutter DevTools等工具可助于识别和解决性能瓶颈,实现持续优化。
【Flutter 前端技术开发专栏】Flutter 应用的启动优化策略
|
16天前
|
前端开发 C++ 容器
Flutter-完整开发实战详解(一、Dart-语言和-Flutter-基础)(1)
Flutter-完整开发实战详解(一、Dart-语言和-Flutter-基础)(1)
|
18天前
|
开发框架 Dart 前端开发
【Flutter前端技术开发专栏】Flutter与React Native的对比与选择
【4月更文挑战第30天】对比 Flutter(Dart,强类型,Google支持,快速热重载,高性能渲染)与 React Native(JavaScript,庞大生态,热重载,依赖原生渲染),文章讨论了开发语言、生态系统、性能、开发体验、学习曲线、社区支持及项目选择因素。两者各有优势,选择取决于项目需求、团队技能和长期维护考虑。参考文献包括官方文档和性能比较文章。
【Flutter前端技术开发专栏】Flutter与React Native的对比与选择
|
6天前
|
Dart 安全
简化代码、提高效率:Dart和Flutter开发小技巧
在日常开发中,我们常常会使用一些常用的技巧或语法糖,以简化代码、提高开发效率。本文将分享一些在Dart和Flutter中常用的小贴士,帮助你更轻松地编写优雅高效的代码。
简化代码、提高效率:Dart和Flutter开发小技巧
|
12天前
|
缓存 负载均衡 网络协议
使用Go语言开发高性能服务的深度解析
【5月更文挑战第21天】本文深入探讨了使用Go语言开发高性能服务的技巧,强调了Go的并发性能、内存管理和网络编程优势。关键点包括:1) 利用goroutine和channel进行并发处理,通过goroutine池优化资源;2) 注意内存管理,减少不必要的分配和释放,使用pprof分析;3) 使用非阻塞I/O和连接池提升网络性能,结合HTTP/2和负载均衡技术;4) 通过性能分析、代码优化、缓存和压缩等手段进一步提升服务性能。掌握这些技术能帮助开发者构建更高效稳定的服务。
|
17天前
|
Android开发
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
Flutter完整开发实战详解(六、 深入Widget原理),2024百度Android岗面试真题收录解析
|
17天前
|
XML Dart Java
Flutter插件开发之APK自动安装,字节跳动Android岗面试题
Flutter插件开发之APK自动安装,字节跳动Android岗面试题
|
17天前
|
Java Android开发 设计模式
flutter音视频开发,Android开发需要学什么
flutter音视频开发,Android开发需要学什么
|
18天前
|
Kubernetes Cloud Native Go
Golang深入浅出之-Go语言中的云原生开发:Kubernetes与Docker
【5月更文挑战第5天】本文探讨了Go语言在云原生开发中的应用,特别是在Kubernetes和Docker中的使用。Docker利用Go语言的性能和跨平台能力编写Dockerfile和构建镜像。Kubernetes,主要由Go语言编写,提供了方便的客户端库与集群交互。文章列举了Dockerfile编写、Kubernetes资源定义和服务发现的常见问题及解决方案,并给出了Go语言构建Docker镜像和与Kubernetes交互的代码示例。通过掌握这些技巧,开发者能更高效地进行云原生应用开发。
65 1
|
18天前
|
Dart 前端开发 测试技术
【Flutter前端技术开发专栏】Flutter开发中的代码质量与重构实践
【4月更文挑战第30天】随着Flutter在跨平台开发的普及,保证代码质量成为开发者关注的重点。优质代码能确保应用性能与稳定性,提高开发效率。关键策略包括遵循最佳实践,编写可读性强的代码,实施代码审查和自动化测试。重构实践在项目扩展时尤为重要,适时重构能优化结构,降低维护成本。开发者应重视代码质量和重构,以促进项目成功。
【Flutter前端技术开发专栏】Flutter开发中的代码质量与重构实践