«Справа RenderFlex переполнен на 97 пикселей». в флаттер AlertDialog - PullRequest
0 голосов
/ 29 августа 2018

У меня эта проблема с действиями AlertDialog

AlertDialog(
        title: ...,
        content: ...,
        actions: <Widget>[
          FlatButton(onPressed: ...,
              child: Text(btn_download)),
          FlatButton(onPressed: ...,
              child: Text('btn_select')),
          FlatButton(onPressed: ...,
              child: Text(btn_qr)),
          FlatButton(onPressed: ...,
              child: Text(btn_cancel)),
        ],
      );

Когда я показываю этот диалог, я получаю это: enter image description here

Я пытался использовать Wrap или другие скролл-и многодетные, но ничего не помогает. Нашел такую ​​же проблему здесь , но ответа пока нет Кто-нибудь знает, как это можно исправить?

Ответы [ 2 ]

0 голосов
/ 29 августа 2018

ButtonBar не предназначен для стольких кнопок.

Поместите свои кнопки в виджет Wrap или Column.

0 голосов
/ 29 августа 2018

У меня нет доступа к AndroidStudio для проверки моей гипотезы, но я бы попробовал что-то вроде этого:

AlertDialog(
    title: ...,
    content: ...,
    actions: <Widget>[
       new Container (
          child: new Column (
              children: <Widget>[
                  FlatButton(onPressed: ...,
                  child: Text(btn_download)),
                  FlatButton(onPressed: ...,
                  child: Text('btn_select'))
          ),
       new Container (
          child: new Column (
              children: <Widget>[
                  FlatButton(onPressed: ...,
                  child: Text(btn_gr)),
                  FlatButton(onPressed: ...,
                  child: Text('btn_cancel'))
          ),
      ),
    ],
  );

Редактировать : этот код работает , но вы должны использовать ограниченную по ширине Container, даже если кажется, что ширина экрана 75% является чем-то приятным , поскольку он работает как в портретном и ландшафтном режиме.

import 'package:flutter/material.dart';
import 'dart:async';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
    return new MaterialApp(
    title: 'Flutter Demo',
    theme: new ThemeData(
        primarySwatch: Colors.blue,
    ),
    home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

Future<Null> _neverSatisfied() async {
    double c_width = MediaQuery.of(context).size.width*0.75;
    return showDialog<Null>(
    context: context,
    barrierDismissible: false, // user must tap button!
    builder: (BuildContext context) {
        return new AlertDialog(
        title: new Text('Rewind and remember'),
        content: new SingleChildScrollView(
            child: new ListBody(
            children: <Widget>[
                new Text('You will never be satisfied.'),
                new Text('You\’re like me. I’m never satisfied.'),
            ],
            ),
        ),
        actions: <Widget>[
            new Container(
            width: c_width,
            child: new Wrap(
                spacing: 4.0,
                runSpacing: 4.0,
                children: <Widget>[
                    new FlatButton(
                    child: new Text('The Lamb'),
                    onPressed: () {
                        Navigator.of(context).pop();
                    },
                    ),
                    new FlatButton(
                    child: new Text('Lies Down'),
                    onPressed: () {
                        Navigator.of(context).pop();
                    },
                    ),
                    new FlatButton(
                    child: new Text('On'),
                    onPressed: () {
                        Navigator.of(context).pop();
                    },
                    ),
                    new FlatButton(
                    child: new Text('Broadway'),
                    onPressed: () {
                        Navigator.of(context).pop();
                    },
                    ),

                ],
            )
            )
        ],
        );
    },
    );
}

void _doNeverSatisfied() {
    _neverSatisfied()
    .then( (Null) {
    print("Satisfied, at last. ");
    });
}



@override
Widget build(BuildContext context) {
    return new Scaffold(
    appBar: new AppBar(
        title: new Text(widget.title),
    ),
    body: new Center(
        child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
            new Text(
            'You have pushed the button this many times:',
            ),
            new Text(
            '$_counter',
            style: Theme.of(context).textTheme.display1,
            ),
        ],
        ),
    ),
    floatingActionButton: new FloatingActionButton(
        onPressed: _doNeverSatisfied,
        tooltip: 'Call dialog',
        child: new Icon(Icons.add),
    ), // This trailing comma makes auto-formatting nicer for build methods.
    );
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...