flutter 问题记录

2020-07-24  本文已影响0人  wwq2020

文本溢出

class MyWidget extends StatelessWidget {
  final text = 'long text..................';

  @override
  Widget build(BuildContext context) {
    return Row(
    children: [
      Icon(Icons.add),
      Text(text),
      Icon(Icons.add),
    ]);
  }
}

解决

class MyWidget extends StatelessWidget {
  final text = 'long text..................';

  @override
  Widget build(BuildContext context) {
    return Row(
    children: [
      Icon(Icons.add),
      Expanded(
        child: Text(
        text,
        ),
      ),
      Icon(Icons.add),
    ]);
  }
}

widget 超出屏幕

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
    children: [
      Chip(label: Text('a')),
      Chip(label: Text('b')),
      Chip(label: Text('c')),
      Chip(label: Text('d')),
      Chip(label: Text('e')),
      Chip(label: Text('f')),
      Chip(label: Text('g')),
      Chip(label: Text('h')),
      Chip(label: Text('i')),
      Chip(label: Text('j')),
    ]);
  }
}

解决

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
    children: [
      Chip(label: Text('a')),
      Chip(label: Text('b')),
      Chip(label: Text('c')),
      Chip(label: Text('d')),
      Chip(label: Text('e')),
      Chip(label: Text('f')),
      Chip(label: Text('g')),
      Chip(label: Text('h')),
      Chip(label: Text('i')),
      Chip(label: Text('j')),
    ]);
  }
}
上一篇下一篇

猜你喜欢

热点阅读