Flutter is a brand new cross-platform development language. I had the honor to use Flutter for the complete development of my actual project. During the development process, I also experimented step by step and encountered various pitfalls. Some problems have been solved, but there are still some problems that cannot be solved in time. Therefore, I am trying to find some solutions myself. So HERE I will share them with you for learning and discussion.

Waiting for another flutter command to release the startup lock…

Problem description

This occurs when a Flutter Packages GET is used in a project or when a Flutter build is executed on the command line: Waiting for another flutter command to release the startup lock…

Solution:

Find the lockfile in\ bin\cache and delete it. If this does not work, restart the IDE and try again.

2, call setState or markNeedsBuild error

Problem description

There is no way to use context or setState directly in initState, build, or page returns

The solution

use

/ / method a WidgetsBinding. Instance. AddPostFrameCallback ((_)} {/ / jump page); Future.delayed(duration.zero).then((e) {.... });Copy the code

3, PageView save status error

Problem description

Build functions must never return null. To return an empty space that causes the building widget to fill available room, return “new Container()”. To return an empty space that takes as little room as possible, return “new Container(width: 0.0, height: 0.0)”

The solution

Super.build must be added to the build method

@override Widget build(BuildContext context) { super.build(context); // Save state must be appended with [...] }Copy the code

4. Problems with using EventManager

Post: sends a message. On: listens for a message. Destroy: destroys a messageCopy the code

Problem description

Using DeStory incorrectly prevents the entire application from listening for messages

The solution

Dispose in BaseWidget cannot destory EventManager. EventManager is a singleton, and cancels the base class altogether.

5, IOS up camera/album click event penetration

Problem description

Clicking on the camera area and image selection area will respond to click events on the underlying Flutter interface when the camera is activated and the photo album is selected

Specific participation: github.com/flutter/flu…

The solution

The current solution is to display a masked popover when the camera and album are turned on, and to cancel the masked popover when the camera and album are folded up.

6, official Webview_flutter usage issues

Problem description

In Android input box to get focus, click twice will flash back.

On IOS, the IO. Flutter. Embedded_views_preview property needs to be configured, which will cause the keyboard to get jammed.

Github.com/flutter/flu… Github.com/flutter/flu…

The solution

Pending official solution, the third-party flutter_webview_plugin will be used temporarily

7. Problems in using flutter_webview_plugin

Problem description

Flutter_webview_plugin is a call to a native Webview. And added to the native home page. Therefore, this WebView is the topmost and cannot display a flutter view on it

The solution

To display popovers and other views, first determine whether there is a WebView page, and call FlutterWebviewPlugin().show() when entering the WebView page; Call FlutterWebviewPlugin().hide() to exit the WebViewd page;

8. The specified page cannot be closed for named routes

Problem description

Pop (context, result), there is no way to specify a specific page route or popover, for example, page 1, page 2, page 3, page 4, page 4 close page 2 in page 4, There is no way to specify a specific page route or popover in named Routes

Github.com/flutter/flu…

The solution

Modify the source code to free up the underlying history, or to avoid the need to close a specific page.

9. There is no event response when you click the control area

Problem description

The click event of the control is set correctly, but the click does not respond

The solution

  • Sets the background for the control
  • Setting the Behavior Property
return GestureDetector(
                    behavior: HitTestBehavior.translucent,
                    child: Text("Test${index}"),
                    onTap: () {},
                  );


enum HitTestBehavior {
  /// Targets that defer to their children receive events within their bounds
  /// only ifone of their children is hit by the hit test. deferToChild, // Opaque targets can be hit by hit tests, causing them to both receive /// events within their bounds and prevent targets visually behind them from /// also Receiving events. Opaque,// The entire area of the GestureDetector, /// Targets both receive events within their bounds and permit /// Targets visually behind them Also receive events. Always,// The whole region of the GestureDetector and the region below it}Copy the code

10, Appbar/Tabbar/ height setting problem

Problem description

Appbar and Tabbar have fixed heights by default. How do I change the heights

The solution

Use the PreferredSize.

The last

If you encounter problems in the process of using, please leave a comment below.

Learning materials

  • Flutter Github
  • Because Chinese website
  • Flutter Packages
  • Flutter ebook
  • Flutter Community Chinese resource website

Please give a thumbs up! Because your likes are the biggest encouragement to me, thank you!