[Part 53 of the Flutter Problem Series] The solution to Overflow is deprecated and shouldn't be used. Use clipBehavior instead

This is the [53rd part of the Flutter problem series]. If you find it useful, please pay attention to the column.

The Flutter version currently used by the blogger: 2.2.3, Dart version: 2.13.4, Android Studio version: Arctic Fox 2020.3.1 Pathc 3

One: problem description

Display a picture in the specified area, as shown in the following code

return Container(
  color: Colors.red,
  width: 300,
  height: 200,
  child: Stack(
    children: [
      Positioned(
        top: 100,
        child: Image.asset("assets/images/lufei.jpeg"),
      ),
    ],
  ),
);

The effect diagram is as follows

It can be seen that pictures beyond this area are no longer displayed.

This problem is easy to solve, you only need to Stackset the properties overflowof the component Overflow.visibleto , as shown in the following figure,
insert image description here
after setting, the picture can be displayed beyond the area, but at this time it will prompt

Overflow is deprecated and shouldn't be used. Use clipBehavior insteadThe warning message is to tell us that the overflow property has been deprecated and replaced by the clipBehavior property.

Two: Solutions

If you want the sub-components in the Stack component to be displayed even after they exceed the area, set the clipBehavior property of the Stack component to Clip.none.

As shown in the picture below The
insert image description here
effect picture is as follows

suggestion

Looking at the source code of the Stackcomponent , we can see that the overflow attribute has been deprecated after Flutter version 1.22. Since it has been deprecated, this attribute will be removed sooner or later with the update iteration of the Flutter version.

In order not to affect the project code, the components or properties that have been deprecated are still used less or not in the project.

Has your problem been resolved? Welcome to leave a message in the comment area.

Give someone a rose, and there is a lingering fragrance in your hand. If you think the article is good, I hope you can give a one-click three-link, thank you.


concluding remarks

Google's Flutter is getting more and more popular. As of January 6, 2022, the GitHub star has reached 134K. Flutter is resolutely a trend, so as a front-end developer, there is no reason not to learn as soon as possible.

Whether you are a Flutter novice or have already started, you might as well pay attention first. I will write the common components in Flutter (including source code analysis, component usage and precautions) and possible problems in the CSDN blog. I hope While learning by yourself, you can also help more people.

Guess you like

Origin blog.csdn.net/qq_42351033/article/details/122346787