最近 Flutter 的更新似乎改变了 BottomNavigationBar 的行为。以前,当键盘出现时,键盘会覆盖BottomNavigationBar。但是,现在,BottomNavigationBar 出现时会粘在键盘的顶部并且始终可见。
当键盘出现时,如何将BottomNavigationBar 设置为保留在键盘下方?
bottomNavigationBar: new BottomNavigationBar(
type: BottomNavigationBarType.fixed,
fixedColor: Colors.blue,
onTap: _navigationTapped,
currentIndex: _pageIndex,
items: [
new BottomNavigationBarItem(icon: new Icon(Icons.apps), title: new Text("Manage")),
new BottomNavigationBarItem(icon: new Icon(Icons.multiline_chart), title: new Text("A")),
new BottomNavigationBarItem(icon: new Icon(Icons.check_box), title: new Text("B")),
new BottomNavigationBarItem(icon: new Icon(Icons.person_add), title: new Text("C")),
new BottomNavigationBarItem(icon: new Icon(Icons.border_color), title: new Text("D")),
]
),
Run Code Online (Sandbox Code Playgroud) 我来自 Web 开发背景,并且习惯于能够创建一个同时具有 x 和 y 溢出的元素(允许向任何方向滚动)。我正在努力使用 Flutter 实现相同的功能。
查看文档,我找到了 SingleChildScrollView,但它只允许 Axis.horizontal 或 Axis.vertical,而不是两者。
所以我尝试了以下方法:
return SingleChildScrollView( // horizontal scroll widget
scrollDirection: Axis.horizontal,
child: SingleChildScrollView( // vertical scroll widget
scrollDirection: Axis.vertical,
child: ...content of the container etc...
)
);
Run Code Online (Sandbox Code Playgroud)
这适用于 x 和 y,但它不允许对角滚动。
有没有办法实现对角滚动,或者有没有更好的材料小部件,我完全没有?
谢谢
我有一个带有一组扩展小部件的列。
有没有办法控制它们扩展的范围?我希望一个小部件仅扩展到特定大小,并使其余小部件可用于其他小部件。
编辑:
因为我得到了两个可能具有误导性的答案,所以我想澄清一下。我想要这样的东西:
Expanded(flex: 1, minSize: 50, maxSize: 200, child: ...)
Run Code Online (Sandbox Code Playgroud)
这意味着这个展开的小部件的 flex 为 1,但不应小于 50 和大于 200。
如何删除TextFormField验证器创建的错误消息?我只想要红色边框,因为我没有空间来显示错误。
bool error = false;
TextFormField (
hintText:error?'please input productName':'',
hintStyle:TextStyle(color: Colors.red),
validator:(v){
v.trim().length>0?error=false:error=true; return null;
}
)
Run Code Online (Sandbox Code Playgroud) 我正在尝试自定义颤动时 RaisedButton 阴影的颜色,例如绿色而不是灰色,我不想像互联网上的所有解决方案一样将按钮放在容器中,所以我希望有一个使用高程和“android材料”不可能做到这一点的旧答案不再是问题。
已编辑:使用 ShadowBox 解决方案的容器的问题是,由于偏移量只有两个值,垂直和水平,因此将向所有侧面展开,如果我们推动 ShadowBox 使其仅在一侧,则在一侧但它是会很大(按钮高度的一半)!
因此,如果有一种方法可以使 child(RaisedButton) 大于容器,那么这将是一个解决方案。
我正在尝试使用 Stack(..Positioned(..)) 但到目前为止没有运气。
顺便说一句,这是我需要一个原生但彩色阴影的按钮。
RaisedButton(
padding: EdgeInsets.symmetric(vertical: 15.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)
),
color: Theme.of(context).primaryColor,
onPressed: () => print('Hello'),
child: Center(Text(...)),
),
Run Code Online (Sandbox Code Playgroud)
但到目前为止我得到了什么:
谢谢
我怎样才能画这样的半圆?
代码:
class DrawHalfCircleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final Path path = new Path();
...
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
Run Code Online (Sandbox Code Playgroud) 我在构建 navigationDrawer 时遇到错误,其中 tootlip 小部件需要 MaterialApp 作为祖先。
这是错误的内容:
I/flutter ( 5780): _TooltipState#bc79e(ticker inactive)):
I/flutter ( 5780): No Overlay widget found.
I/flutter ( 5780): Tooltip widgets require an Overlay widget ancestor for correct operation.
I/flutter ( 5780): The most common way to add an Overlay to an application is to include a MaterialApp or Navigator
I/flutter ( 5780): widget in the runApp() call.
I/flutter ( 5780): The specific widget that failed to find an overlay was:
I/flutter ( 5780): Tooltip
I/flutter …Run Code Online (Sandbox Code Playgroud) 我有小货币表.我没有使用网格.我使用列和行.问题是行中的项目没有显示在中心,如下面的excel示例所示.我必须使用什么小部件才能使项目居中?有什么帮助吗?
The Example codes:
return new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Padding(
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
child: new Icon(
Icons.crop_rotate,
color: Colors.white,
),
),
new Padding(
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
child: new Text("STG", style: mainHeadTextStyle),
),
new Padding(
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
child: new Text("EUR", style: mainHeadTextStyle),
),
new Padding(
padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
child: new Text("USD", style: mainHeadTextStyle),
),
],
), …Run Code Online (Sandbox Code Playgroud) 我正在使用 TextFormField 来接受密码。我已将后缀图标设置为让 IconButton 子项检测单击事件并切换 TextFormField 的模糊文本属性。iconButton 的回调函数被调用,但 TextFormField 不会被重新绘制。关于如何解决这个问题的任何想法?
static Widget buildTextFormField(String id,
FormFieldValidator<String> validateField,
FormFieldSetter<String> saveField,
InputDecoration decoration,
EdgeInsetsGeometry paddingInfo,
EdgeInsetsGeometry marginInfo,
TextInputType keyboardType,
{bool obscureField:false, double width:328.0,
TextEditingController controller}
){
return Container(
padding: paddingInfo,
margin: marginInfo,
width: width,
child: TextFormField(
key: Key(id),
obscureText: obscureField,
validator: validateField,
onSaved: saveField,
keyboardType: keyboardType,
decoration: decoration,
controller: controller,
),
);
Run Code Online (Sandbox Code Playgroud)
}
InputDecoration passwordDecoration = InputDecoration(
hintText: 'Password',
labelText: 'Enter your password',
suffixIcon:
IconButton(
icon: Icon(
_passwordVisible ? Icons.visibility : Icons.visibility_off,
semanticLabel: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 SingleChildScrollView 使堆栈布局可滚动,但它不滚动。这里应该使用 SingleChildScrollView 吗?
我想我已经给出了足够的描述,让任何人都能理解我的问题。此处提供更多文本以满足 StackOverflow 提出问题的要求。为此事道歉。
这是示例代码。
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: Center(
child: LayoutBuilder(
builder:
(BuildContext context, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Container(
// A fixed-height child.
color: Colors.white,
height: 120.0,
),
Expanded(
// A flexible child that will grow to fit the viewport but
// still be at least as big as necessary to fit its …Run Code Online (Sandbox Code Playgroud)