【问题标题】:how can i delete space between Expanded widgets in Column?如何删除列中展开的小部件之间的空间?
【发布时间】:2021-04-05 09:42:39
【问题描述】:

我试图通过高度属性减少行(文本字段)之间的空间,但它不起作用,Sizedbox 也不能正常工作,由于我的 filterList 不能省略扩展小部件(它显示“A RenderFlex 溢出像素”错误),我尝试使用 flex Value 修复它,但它也不起作用。 任何想法我该如何解决?!

my emulator screenshot

import 'package:flutter/material.dart';
import 'package:filter_list/filter_list.dart';
class FilterPage extends StatefulWidget {
  const FilterPage({Key key, this.allTextList}) : super(key: key);
  final List<String> allTextList;
  @override
  _FilterPageState createState() => _FilterPageState();
}
class _FilterPageState extends State<FilterPage> {
  @override
  Widget build(BuildContext context) {
    List<String> countList = [
      "Art",
      "Mt",
      "P",
      "Pl"
   
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text("Filter list Page"),
      ),
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: FilterListWidget(
                allTextList: countList,
                height: MediaQuery.of(context).size.height,
                hideheaderText: true,
                selectedTextBackgroundColor: Colors.red,
                applyButonTextBackgroundColor: Colors.red,
                allResetButonColor: Colors.grey,
                onApplyButtonClick: (list) {
                  //Navigator.pop(context, list);
                },
              ),
            ),
            Expanded(
              child: Row(
                children: [
                  Container(
                    width: 180,
                    child: TexstInput(lable: 'min-Upvote',icons: Icons.favorite,),
                  ),
                  Container(
                    width: 180,
                    child: TexstInput(lable: 'max-Upvote'),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                children: [
                  Container(
                    width: 180,
                    child: TexstInput(lable: 'min',icons: Icons.person_rounded,),
                  ),
                  Container(
                    width: 180,
                    child: TexstInput(lable: 'max'),
                  ),
                ],
              ),
            ),
            Container(
                child: RaisedButton(child:Text(
                  'apply'
                ),),
              ),
          ],
        ),
      ),
    );
  }
}
class TexstInput extends StatelessWidget {
   TexstInput({
@required this.lable,this.icons
  }) ;
   IconData icons;
   String lable;
  @override
  Widget build(BuildContext context) {
    return TextField(
      keyboardType: TextInputType.number,
      decoration: InputDecoration(
          icon: Icon(icons),
          contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
          labelText: lable,
          focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.red, width: 5.0),
          ),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.grey, width: 0.8),
          )
      ),
    );
  }
}

主要

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



void main() async{
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      debugShowCheckedModeBanner: false,
      home:FilterPage(),


    );
  }
}

【问题讨论】:

    标签: flutter resize rows space flutter-container


    【解决方案1】:

    试试下面几行

            Expanded(
              child: Row(
                children: [
               Container(width: 2 ),
                  Expanded( 
                    child: TexstInput(lable: 'min-Upvote',icons: Icons.favorite,),
                  ),
               Container(width: 2 ),
                  Expanded( 
                    child: TexstInput(lable: 'max-Upvote'),
                  ),
               Container(width: 2 ),
                ],
              ),
            ),
            Expanded(
              child: Row(
                children: [
               Container(width: 2 ),
                  Expanded( 
                    child: TexstInput(lable: 'min',icons: Icons.person_rounded,),
                  ),
               Container(width: 2 ),
                  Expanded( 
                    child: TexstInput(lable: 'max'),
                  ),
               Container(width: 2 ),
                ],
              ),
            ),
    

    【讨论】:

    • 它没有改变:/
    【解决方案2】:

    不是 100% 确定您如何想象您的布局。 您打算添加更多搜索标签吗?如果您愿意,可以更改 flex 值。 如果您想让您的行位于 FilterListWidget 的正下方,请将 mainAxisAlignment: MainAxisAlignment.start 添加到第二列。

    SafeArea(
        child: Column(
          children: [
            Flexible(
              flex: 2,
              child: FilterListWidget(
                allTextList: countList,
                hideheaderText: true,
                selectedTextBackgroundColor: Colors.red,
                applyButonTextBackgroundColor: Colors.red,
                allResetButonColor: Colors.grey,
                onApplyButtonClick: (list) {
                  //Navigator.pop(context, list);
                },
              ),
            ),
            Flexible(
              flex: 3,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Row(
                    children: [
                      Container(
                        width: 180,
                        child: TexstInput(lable: 'min-Upvote',icons: Icons.favorite,),
                      ),
                      Container(
                        width: 180,
                        child: TexstInput(lable: 'max-Upvote'),
                      ),
                    ],
                  ),
                  Row(
                    children: [
                      Container(
                        width: 180,
                        child: TexstInput(lable: 'min',icons: Icons.person,),
                      ),
                      Container(
                        width: 180,
                        child: TexstInput(lable: 'max'),
                      ),
                    ],
                  ),
                  Container(
                    child: RaisedButton(child:Text(
                        'apply'
                    ),),
                  ),
                ],
              ),
            ),
          ],
        ),
      )
    

    【讨论】:

    • 我很高兴能帮上忙!如果你这么好,请支持我的回答。我需要业力才能最终能够评论一些帖子:)。
    • 是的,我做到了,我也将您的答案标记为解决方案! ^^
    • 我写了另一个问题,你有什么想法吗? :D [链接] (stackoverflow.com/questions/65483783/…)