Flutter:Row 在 Wrap 内跨行

假设我们有:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        Row(
          children: [
            Text('a'),],),Row(
          children: [
            Text('b'),);
  }
}

输出结果为:

Flutter:Row 在 Wrap 内跨行

注意每个 Row 是如何占据整行的

我怎样才能解决这个问题并使它们并排?

megeter 回答:Flutter:Row 在 Wrap 内跨行

你应该用Row包裹你的FittedBox,这会让它们只消耗它们需要的空间,所以你的代码应该是这样的:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        FittedBox(
          child: Row(
            children: [
              Text('a'),],),FittedBox(
          child: Row(
            children: [
              Text('b'),);
  }
}

你的输出将是这样的: and your output will be like this

本文链接:https://www.f2er.com/36820.html

大家都在问