Flutter 如何解决flatter中的小部件溢出问题?
我有一张17像素的图片。 &我无法解决它? 首先,我所做的 我拿了一个Flutter 如何解决flatter中的小部件溢出问题?,flutter,dart,overflow,flutter-layout,Flutter,Dart,Overflow,Flutter Layout,我有一张17像素的图片。 &我无法解决它? 首先,我所做的 我拿了一个Row()小部件,用Container()包装,在Row()中拿了两个Expanded()小部件。一个用于TextField(),另一个用于CountryPickerDropdown() 我用过插件 代码: 新容器( 宽度:MediaQuery.of(context).size.width, 填充:仅限常量边集(左:10.0), 装饰:盒子装饰( borderRadius:borderRadius.all(半径.圆形(5.0
Row()
小部件,用Container()
包装,在Row()
中拿了两个Expanded()
小部件。一个用于TextField()
,另一个用于CountryPickerDropdown()
我用过插件
代码:
新容器(
宽度:MediaQuery.of(context).size.width,
填充:仅限常量边集(左:10.0),
装饰:盒子装饰(
borderRadius:borderRadius.all(半径.圆形(5.0)),
边框:边框。全部(颜色:Colors.blue)
),
孩子:排(
儿童:[
扩大(
孩子:乡下扒手(
initialValue:'在',
itemBuilder:\u buildDropdownItem,
onValuePicked:(国家/地区){
isCountryCodeSelected=true;
打印(${country.name});
打印(${country.phoneCode});
打印(${country.isoCode});
打印(“+${country.phoneCode}(${country.isoCode})”;
设置状态(){
countryCode=country.phoneCode;
});
},
),
),
扩大(
孩子:TextField(
键盘类型:TextInputType.phone,
装饰:输入装饰(
边框:InputBorder.none,
hintText:“电话号码”,
),
一旦更改:(值){
设置状态(){
phoneValue=值;
});
打印(“电话号码:$phoneNo”);
this.phoneNo=isCountryCodeSelected?+“+countryCode+值:“+91”+值;
打印(“phoneNo=“+phoneNo”);
},
),
)
],
)
),
控件代码及其国旗图像:
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
Widget\u buildDropdownItem(国家)=>容器(
孩子:排(
儿童:[
CountryPickerUtils.getDefaultFlagImage(国家),
大小盒子(
宽度:8.0,
),
文本(“+${country.phoneCode}(${country.isoCode})”),
],
),
);
怀疑您的countryselector小部件需要扩展child和文本溢出
Widget _buildDropdownItem(Country country) => Row(
children: <Widget>[
Expanded(child: Container(
margin: EdgeInsets.only(right: 8),
child: CountryPickerUtils.getDefaultFlagImage(country)),),
Expanded(child: Text(
"+${country.phoneCode}(${country.isoCode})",
overflow: Overflow.Eclipse
),)
],
);
Widget\u buildDropdownItem(国家)=>行(
儿童:[
扩展(子:容器)(
页边距:仅限边集(右:8),
子项:CountryPickerUtils.getDefaultFlagImage(国家)),
扩展(子:文本)(
“+${country.phoneCode}(${country.isoCode})”,
溢出:溢出
),)
],
);
换行符被行替换,文本字段的宽度减小,希望这有帮助。如果出了什么问题,请告诉我
new Container(
padding: EdgeInsets.only(left:10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.blue)
),
child: Row(
children: <Widget>[
Container(
child: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
isCountryCodeSelected=true;
print("${country.name}");
print("${country.phoneCode}");
print("${country.isoCode}");
print("+${country.phoneCode}(${country.isoCode})");
setState(() {
countryCode= country.phoneCode;
});
},
),
width: MediaQuery.of(context).size.width/2-30.0,
),
Container(
width: MediaQuery.of(context).size.width/2-30.0,
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Telephone Number",
),
onChanged: (value){
setState(() {
phoneValue=value;
});
print("phoneNumbe:$phoneNo");
this.phoneNo = isCountryCodeSelected ? "+" + countryCode + value : "+91" + value ;
print("phoneNo="+phoneNo);
},
),
),
],
)
)
新容器(
填充:仅限边缘设置(左:10.0),
装饰:盒子装饰(
borderRadius:borderRadius.all(半径.圆形(5.0)),
边框:边框。全部(颜色:Colors.blue)
),
孩子:排(
儿童:[
容器(
孩子:乡下扒手(
initialValue:'在',
itemBuilder:\u buildDropdownItem,
onValuePicked:(国家/地区){
isCountryCodeSelected=true;
打印(${country.name});
打印(${country.phoneCode});
打印(${country.isoCode});
打印(“+${country.phoneCode}(${country.isoCode})”;
设置状态(){
countryCode=country.phoneCode;
});
},
),
宽度:MediaQuery.of(context).size.width/2-30.0,
),
容器(
宽度:MediaQuery.of(context).size.width/2-30.0,
孩子:TextField(
键盘类型:TextInputType.phone,
装饰:输入装饰(
边框:InputBorder.none,
hintText:“电话号码”,
),
一旦更改:(值){
设置状态(){
phoneValue=值;
});
打印(“电话号码:$phoneNo”);
this.phoneNo=isCountryCodeSelected?+“+countryCode+值:“+91”+值;
打印(“phoneNo=“+phoneNo”);
},
),
),
],
)
)
换行被行替换,文本字段的宽度减小,希望这有帮助。请让
Expanded(
flex:1
child: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
isCountryCodeSelected=true;
print("${country.name}");
print("${country.phoneCode}");
print("${country.isoCode}");
print("+${country.phoneCode}(${country.isoCode})");
setState(() {
countryCode= country.phoneCode;
});
},
),
),
Expanded(
flex:2
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Telephone Number",
),
onChanged: (value){
setState(() {
phoneValue=value;
});
print("phoneNumbe:$phoneNo");
this.phoneNo = isCountryCodeSelected ? "+" + countryCode + value : "+91" + value ;
print("phoneNo="+phoneNo);
},
),)
new Container(
padding: EdgeInsets.only(left:10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.blue)
),
child: Row(
children: <Widget>[
Container(
child: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
isCountryCodeSelected=true;
print("${country.name}");
print("${country.phoneCode}");
print("${country.isoCode}");
print("+${country.phoneCode}(${country.isoCode})");
setState(() {
countryCode= country.phoneCode;
});
},
),
width: MediaQuery.of(context).size.width/2-30.0,
),
Container(
width: MediaQuery.of(context).size.width/2-30.0,
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Telephone Number",
),
onChanged: (value){
setState(() {
phoneValue=value;
});
print("phoneNumbe:$phoneNo");
this.phoneNo = isCountryCodeSelected ? "+" + countryCode + value : "+91" + value ;
print("phoneNo="+phoneNo);
},
),
),
],
)
)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
resizeToAvoidBottomPadding: false,
body: SafeArea(
child: Center(
child: Column(children: [
Expanded(
flex: 25,
child: Column(children: [
Expanded(
flex: 1,
child: Container(
color: Colors.red,
),
),
Expanded(
flex: 2,
child: Column(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.blue,
),
),
Expanded(
flex: 1,
child: Row(
children: [
Expanded(
flex: 1,
child: Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.orange,
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.cyan,
),
),
],
)),
Expanded(
flex: 1,
child: TextField(
style: TextStyle(color: Colors.black),
),
),
],
)),
Expanded(
flex: 1,
child: Container(
color: Colors.blue,
),
),
],
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.pink,
),
)
])),
Expanded(
flex: 3,
child: Container(
color: Colors.blue,
),
)
])))));
}
}