Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

dart - Set horizontal alignment in MaterialBanner in Flutter

I'm trying to set a layout inside MaterialBanner. I need to set the red-colored widget in the bottom to the left. However, I cannot figure it out how and the square widgets are always right-aligned.

Here is my sample code. If you know how to implement it, I would like to know the tip. Thank you.

MaterialBanner(
  forceActionsBelow: true,
  actions: <Widget>[
    RaisedButton( // Tried Row, Expanded Widget but neither works
      child: Text('Red'),
      color: Color(0xff49A9EF),
    ),
    RaisedButton(
      child: Text('Blue 1'),
      color: Color(0xff49A9EF),
    ),
    RaisedButton(
      child: Text('Blue 2'),
      color: Color(0xff49A9EF),
    ),
  ],
  content: Text(
    'text text text text text text text text text text text text text text text text text text ',
    overflow: TextOverflow.ellipsis,
    maxLines: 2,
  ),
  ...
)

enter image description here

question from:https://stackoverflow.com/questions/65933560/set-horizontal-alignment-in-materialbanner-in-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've tried this and I can answer why the Red Box doesn't move to the left. The actions list of Widgets is always set to AlignmentDirectional.centerEnd so there is no way you can place a Widget in the actions list and expect it to be elsewhere.

What if the red box was passed to the leading property of the MaterialBanner Widget. Then we see that the box aligns on the top left with the provided content. Even when the padding is stripped off completely from the leading Widget it sticks to the top left. Any reason why you wouldn't write a custom Widget to accomplish this ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...