preface

A few days ago a friend consult can climb website data, and make a Windows program. As the development of iOS/Android/MacOS WatchOS /… I am not familiar with C++/C#, and it is not practical to develop in Java. It is still time-consuming to re-understand Windows components, network, and resource management, so I am going to recommend crowdsourcing platform to publish tasks. On second thought, isn’t great Flutter the right choice? “Write once, Run anywhere” can avoid many problems such as platform compatibility difficulties and high learning costs. In the end, I became more sure that Flutter is the future of mobile.

This paper is the author’s experience of learning and doing a project during off-work and weekends, hoping to be helpful to those who start Flutter. Most of these are development suggestions, recommendations, and ideas, not code level guidance. This article takes about 20 minutes to read.

First, preparation

1. Flutter development environment, development tools and learning materials

1.To do a good job, he must sharpen his tools.Developing Flutter If you want to pack ios and Android simultaneously, you must have a Mac. What if you don’t have one? Use your programmer strengths,Install the MacOS VMDownload it from apple’s websiteXcode installation package. You are advised to use Android Studio(AS) for development. Download the Flutter and Dart plug-ins to make them more compatible with Android emulators. The author has Xcode and AS installed on his computer, so just install the Flutter SDK. After installation, use the universal command, Flutter Doctor, to find problems and solve them.Note: The warning of Android license Status unknown is because my local Java version is too high, which does not affect development and can be ignored. Of course, you can also use Visual Studio development, development of Windows programs must be. And when compiling package EXE file, must run in Windows10 computer environment. (so the author installed the Windows10 virtual machine at the end of the project and installed VS before packing, occupying 40gb of storage on my computer. 🤣 🤣 🤣)

â‘¡ Recommend some websites for learning Flutter:

  • Flutter Chinese website: FlutterChina. Club

Bytedance – Happiness in FE team produced by a god, the best choice for entry, nanny level information.

  • Dev, 官网 英 æ–‡ : Flutter. Cn

Official website information, the most reliable. Version new, full resources, hand – in – hand video teaching and online practice experience.

  • Unknown Old Man: Laomengit.com

The most complete Chinese control library, use and demand more appropriate conscience of the official controls, save time, worry and effort. Poking fun at once written in Android UI, Android (ListView, RecycleView) lost in iOS (UITableView, UICollectionView), basic don’t need a custom adapter is iOS. But Android uses XML to write UI, which is very convenient and better than Xib.

  • Third party control library: pub.flutter- IO

It’s like Cocoapods for iOS and JCenter for Android. Commonly used third-party libraries can be obtained in Chinese language materials, here is not a list. It is important to note that superimposed dependencies on third-party libraries will cause compatibility failures. In general, use the any version and pub will automatically download the non-conflicting version. In special cases, you need to download the offline library for configuration. Some libraries need to be commented out during compilation, such as hive_generator, which needs to be added for automatically generating the model attribute conversion method. Dart Error: Error: import of dart:mirrors is not supported in the current Dart runtime

  • Ali Jet-go: github.com/alibaba/flu…

It is recommended to introduce components in finished products. Unfortunately, Alibaba’s internal enthusiasm for Flutter was lost, possibly due to performance problems with the Idle Fish App, and its maintenance was suspended 2 years ago. Flutter2.2 already has significant performance improvements and ecosystem support.

  • Recommend a high copy project: my.oschina.net/u/4493374/b…

Contains high imitation Douyin, Douyu, douban, open source China. It basically contains all the functional sections of the market App.

  • GSY personal website: [guoshuyu.cn/home/index/]
  • FlutterUnit: [github.com/toly1994328…].

Compared to Flutter-GO, it is much fresher.

2. Understand and analyze requirements, climb demand data, and determine the development process

(1) demand

  • Table shows professional list, operable, pageable.
  • Multi-dimensional and multi-condition query
  • Scheme list, edit, switch scheme
  • Export Excel tables on demand
  • Registration, login, Token

â‘¡ Climb the website data

It is unethical/illegal to crawl sites without allowing data to be crawled.

In fact, companies have a lot of data crawling on each other. But that doesn’t offset my guilt. Besides, all the interfaces that this website needs to climb have dynamic tokens encrypted by MD5, so I recommend it to use crowdsourcing platform again.

In the JS debug window, there is a preview page in addition to the header. Surprisingly, the site’s data is displayed in the preview at 500 pages per page, meaning we only need to copy 50 pages of data. 😂😂😂 touch data{0.. 49}. Json creates 50 files and pastes the text in turn. Make a little tool and merge 50 JSON files to get a 20 MB JSON file, so we get the raw data. Of course, in the subsequent process of data search and performance optimization, five JSON files were divided according to the types of undergraduate, junior college, sports, art and advance, and the search speed was increased from the original 600ms to less than 400ms.

Why don’t I just paste it into a JSON file? Interested friends can try any editor to open the 20M JSON file.

â‘¢ Development process

  • Create a new Flutter App. By default, iOS, Android, MacOS and Windows have been selected. If not,flutter config --enable-macos-desktopandflutter config --enable-windows-desktopTo create a new one. All development can be done on the Mac, and then seamlessly ported to Windows when it comes time to pack.
  • UI, database, interaction, logic, tools, etc.
  • Platform compatibility, native development, Flutter interaction with native communications.
  • Improve application information, standardize permissions, submit for review.
  • The application has been launched on Mac App Store, and the application address is School Selection Solution. The Windows version will be released on cloud disk later.

2. Functional modules

Walk through the function modules of School Choice Solutions, analyze the knowledge of Flutter used in it, and explain it from the perspective of iOS and Android developers.

1. UI: Everything basedWidget.

In layman’s terms, a StatefulWidget is a mutable control and a StatelessWidget is an immutable control. In terms of UI creation alone, Android Dev has an advantage because XML is also a nested schema. IOS Dev contact SwiftUI or Rx series or RAC is easier to understand, nested UI is the iOS all constraints, attributes, controls, parameters, interaction, animation fusion together, not to control as the main object, the formation of declarative UI. Android native development has a relatively robust pipeline. In terms of ease of development, I feel declarative UIs (+Hot Reload) and responsive programming are trending across all mobile devices.

What is declarative UI? For iOS, For Android

(1) Avoid nesting, in order to encapsulate the governance hell set of dolls

  • If you add a single custom Widget endlessly, a complex page can run to thousands of lines, whether it’s solo or multiplayer development. For the later maintainer, the structure adjustment is difficult, the logical interaction entrance is mixed and difficult to distinguish, it is extremely uncomfortable.
  • Commonly used UI modules are encapsulated to reduce the amount of code and make the structure clear.
  • Bloc mode (understood as MVP) is recommended here, and StatefulWidget is the dominant widget for simple pages, which is ideal for business scenarios where multiple pages share the same data.
  • The entire UI layout is wrapped in only 25 lines of code in Bulid.
@override
Widget build(BuildContext context) {
  passValue = ModalRoute.of(context).settings.arguments;
  return Scaffold(
    body: Column(
      children: [
        _getTopSearchView(context), // Top search bar
        Container(
          height: 40.child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemBuilder: (BuildContext context, int position) {
              return getTitleColumn(position, Global.titles[position]);
            },
            itemCount: Global.titles.length,
            controller: firstRowController,
          ),
        ),// Data header
        Expanded(child: Container(child: _getCoreListView())),// Data core area
        _getPageView()getPageView()/ / paging area],),); }Copy the code
  • Take part of the UI for example, encapsulating the width, border attributes, centered data, and background color. The code is long, instead of showing with pictures.

â‘¡ The overall layout of the idea

  • The Wrap is nested outside the title search bar, and the streaming layout allows the control to be centered and set the row/column spacing, automatically matching the overall window width. Dropdown, TextFiled and Button are similar controls in iOS and Android. The only difference is that the dynamic value of the control is not directly obtained by the property value of the control, but by TextEditingController monitoring and dynamic string variables.
Wrap(
alignment: WrapAlignment.center,
spacing: 20,
runSpacing: 10,
children: []
)
Copy the code
  • Set the data table header to a horizontal ListView, add a ScrollController, and listen to the ScrollController in the data display area to complete synchronous scrolling.
/ / to monitor changes in the first row firstRowController. AddListener (() {double offset = secondedRowController. Offset; double offset1 = firstRowController.offset; if (offset1 ! = offset) { secondedRowController.jumpTo(offset1); }}); / / to monitor changes in the second row secondedRowController. AddListener (() {double offset = secondedRowController. Offset; double offset1 = firstRowController.offset; if (offset ! = offset1) { firstRowController.jumpTo(offset); }});Copy the code
  • The UI of the data display area is quite complex. It needs to ensure scrolling in both vertical and horizontal directions, consider the scrolling performance, and show {500 data/page} lazy loading.

It took me two full days to figure this out, starting with the official control DataTable and finding that a lot of code was needed to match the agent method when the custom cell presented different UIs; Poor rolling performance; Not lazy load, then all the code abandoned, re-layout. Benefiting from the flexible processing of iOS UI construction, the author came up with the idea of using horizontal SingleChildScrollView to nest a vertical ListView inside, and ListView was built using itemBuilder. In this way, horizontal and vertical scrolling, performance, lazy loading all have. The operation of “Add/remove” button at the end of a single item can refresh the UI almost without delay.

  • Paging area: If the length of Flutter is fixed, it will cause the classic Overflow screen of Flutter UI to Overflow. The yellow and black diagonal stripes display area is UI warning (elevation mark in the test guide book, usually at tunnel mouth 🤣), so the outer layer is nested with SingleChildScrollView. This warning will not appear when the window is small.

When 100 pages/page or other page numbers are changed, the instance variable is used to mark the number of pages, and the array’s getRange method resplits the data, refreshing the ListView and page numbers.

2. Database

Hive, 1.8kLike on Pub, 2.3kstar on GitHub, is relatively popular on Flutter.

  • Used together with hive_generator, it can store models and is easy to use.
  • You do not need to write SQL statements, and can directly store data in the form of array /Map
  • CURD is extremely fast

Table construction method in the project:

  • Create a schema list library associated with a professional database. Include a list of majors in each program.
  • Add isCurrentPlan attribute to scheme model, and assign positive and negative values when switching existing scheme.
  • Create a user property database to store a user’s mobile phone number, password, nickname, role permissions (a common role can view only 1000 pieces of data), and login status

Shared_preferences, similar to NSUserDefaults for iOS and SharedPreferences for Android, can be used for local small data storage.

Third party library, global file and resource library

  • Although the sparrow has all the five organs and small projects, it has full functions. When adding third-party libraries, use commands such as flutter pub get/upgrade. The third-party libraries integrated with this App include:

4, and native communication, native adaptation.

  • Use Xcode/AS to independently open projects in their respective platform folders. Application names, ICONS and startup images need native adaptation. Add permissions in the info.plist file for iOS and configure permissions in the manifest.xml file for Android. If there are features that Flutter cannot implement or because of platform specific requirements, native development should be done. As for the Theme, there are corresponding style components for iOS and Android, and you can set the global Theme uniformly. The only need now is for a Flutter community to help each other and solve the platform developers’ native iOS/Android adaptation problems at any time. We hope that a worthy one can start one.
  • The principle of interaction with JS native is basically the same, nothing more than to create the same named channel, A sends the method name and parameters, B receives through the callback. There is a lot of information on the Internet, baidu, there is no need to repeat the wheel here.

This App needs to export Excel files (MacOS and iOS communicate in the same way). In this case, Platform compatibility (platform.isandroid or platform.isios etc.) is required. For Windows platforms, there is no mandatory requirement to request permission from the user, so save directly to any normal file address and invoke the native SavePanel method after the Flutter event is triggered. For MacOS, request User Selected File-read /Write instead of the Folder permissions below, and start the native File save window. This is also an important reason why the audit was rejected.

5, macOS App Store launch process (Due to the strict review mechanism of the App Store, you must control the permission, consecutive 5 days of several versions of the rejection, you know. Android Dev can be skipped.)

  • During Debug, it is necessary to enable Incoming Connections(Server) because Hot Reload is enabled with this permission, but must be turned off on Release because App does not have a Server type and will be rejected.
  • Avoid showing anywhere “Android, Android, Samsung, Huawei, Microsoft” and other apple in all aspects of the opponent’s name, once found, will definitely refuse to review. In particular, the IT news App developed by the author needs to add multiple filtering keywords of “Apple competitors” when IT goes online. When filling in the application introduction, THE author wrote in his technical development experience, “two years of Android development experience” was directly rejected, can only write “two years of zhuo Zhuo experience” 🤣🤣🤣.
  • Due to the confidentiality of data, in order to ensure the approval of the App, fake registration mode is adopted, and local registration storage simulates login. The permission after successful registration is the same as that after visitors log in.
  • With the author for many years to refuse trial 🤣 trial experience, sum up a principle. Don’t fight it out with Apple. Change whatever you’re told. It’s just a distraction. For example, we tried our best to avoid apple’s internal purchase, and finally only used Alipay to pay. Wechat payment was unavoidable. In those days, MOOC App can be completely circumvented. There is no big man to guide how to do it.

Iii. Simple thoughts on Flutter, SwiftUI and Android

The author intends to introduce and analyze the future development of Flutter, iOS, Android, Hongmeng, Mini program, Kuaiya, RN and other mobile development separately. However, there is not enough space, so I will only give a brief introduction now. Later, another article will be published for detailed analysis.

  • Flutter: Mixed development, I would like to call you the strongest! From the performance improvement of Flutter2.2, if the performance is further improved, it will definitely become the mainstream of mobile terminal development and the future can be expected. Dart is a little more fun than Swift.
  • IOS: SwiftUI, fast, beautiful and awesome X. The results are amazing, and Apple is a leader in mobile products and technology. Two disadvantages: (1) Support iOS 13 or above, for domestic development environment, there is still some way to go. (2) Lack of maturity. Although Swift is stable and easy to write, who knows whether SwiftUI will be the next SwiftUI. I started with Swift2.2, and the pain of each new language is still there.
  • Android: the biggest pie cutter in the mobile market. Not only phones, but the hottest smart car market right now is dominated by Android, which is definitely the right choice. The fluency of foreign Android is close to iOS, but you know domestic Android, hope that the domestic push unified alliance as soon as possible to implement practical standards and mechanisms, to avoid the waste of social resources.
  • Fuchsia is not here. Fuchsia is here. In view of OPPO pr comment hongmeng incident yesterday, I can only 🤫. A while ago when chatting with colleagues, talked about hongmeng, I just speak out some practical things, but he said I insulted domestic 🤣, so big charges, I can not afford to wait. After all, with domestic clothes, shoes, tables, chairs, food and water, I dare not make blind comments. Still hope hongmeng can rise, brag less, increase technical intensity and enhance product experience.