Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Xiao CAI as a beginner, the foundation is weak, continue to sort out small daily problems;

Problem 1: Dependency versions conflict

Updates to Flutter are frequent. Our local environment may have a lower stable version, while the plugin we use may have a higher version. Conflicts may occur during integration.

Try one:

Find the problem plug-in in pub.dev, try the lower version one by one according to the update list, pay attention to replace with the fixed version (no ^), until the normal use of the version, although reliable but may try many times;

Try 2:

  1. Replace the offending plug-in version with any, as in json_annotation: any;
  2. Package GET update plug-in, automatic matching;
  3. If you find the problem plug-in in the pubspec.lock file, the system will automatically match the security version (the side dish test may not be the same as the version of each check);
  4. In pubspec.yaml, you can replace the security version. Note: Any is only used to help you find the security version.

Try to 3:

The most fundamental solution is to upgrade the local SDK version, which costs a lot and may cause compatibility problems of other plug-ins, which need to be dealt with as a whole.

Problem 2: The new page initialization dialog fails

When preparing to open a new page, a dialog box will pop up for users to choose. The small dish is initialized in initState method, but the message is always displayed that the page is not initialized, and the location of the pop-up box is wrong.

Try one:

< span style = “box-sizing: border-box; color: RGB (74, 74, 74); line-height: 22px; font-size: 14px! Important; word-break: inherit! Important;”

Try 2:

WidgetsBinding is a bridge that binds the Widget framework to the Flutter engine. AddPostFrameCallback listens for Frame to draw the last Frame and gets the size of the element; And the entire life cycle is executed only once;

WidgetsBinding widgetsBinding = WidgetsBinding.instance; @override void didChangeDependencies() { super.didChangeDependencies(); widgetsBinding.addPostFrameCallback((callback) { showDialog( context: context, barrierDismissible: false, builder: (BuildContext Context) {return GenderChooseDialog(title: 'onBoyChooseEvent ', onBoyChooseEvent: () => Navigator.pop(context), onGirlChooseEvent: () => Navigator.pop(context)); }); }); }Copy the code

Problem 3: The list is centered

While chatting with a friend, Xiao CAI was discussing how to Center a list on the screen. Xiao CAI tried the nested ListView Center but couldn’t Center it.

ShrinkWrap =true ShrinkWrap sets ListView to take up only as much space as you want;

Widget _listItemWid(values) { return Center( child: ListView.builder( shrinkWrap: true, scrollDirection: Axis horizontal, physics: const AlwaysScrollableScrollPhysics (), padding: const EdgeInsets. All (6.0), itemCount: values == null ? 0: values. Length, itemBuilder: (context, I) {return Padding(Padding: EdgeInsets. Symmetric (horizontal: 10.0), child: symmetric Icon(values[i])); })); }Copy the code


Xiao CAI is still in the basic learning stage, there are many problems to be studied; If there are mistakes, please guide!

Little Monk Aze