我正在使用 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) 我有一个连续的图像和该图像旁边的文本。我希望该行完全展开,图像作为其大小,然后保持完整区域应由 Container 使用。
这是我的代码片段:
Row(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(10, 50, 10, 8),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color.fromARGB(100, 0, 0, 0),
blurRadius: 5,
),
],
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Column(children: <Widget>[
Image.asset(
'assets/card.png',
height: 62,
width: 62,
fit: BoxFit.cover,
)
]),
Container(
child: Text("Hello world"),
)
],
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
我想要这样: Flutter UI
我查看了 Flutter 文档,试图找到一个事件、回调,甚至是在 FlexibleSpaceBar 折叠或展开时可以挂钩的状态。
return new FlexibleSpaceBar(
title: new Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Text(_name, style: textTheme.headline),
new Text(_caption, style: textTheme.caption)
]),
centerTitle: false,
background: getImage());`
Run Code Online (Sandbox Code Playgroud)
当 FlexibleSpaceBar 被对齐(折叠)时,我想隐藏_caption文本并只显示_name文本。当它完全展开时,我显然想同时显示_name和_caption。
我该怎么做?
我不熟悉颤振,所以我对此有些迷失。
我在 Flutter 中创建了一个扩展 AppBar 类的类,这样我就可以在需要时重用它。我的问题是如何访问有状态/无状态小部件构建上下文?
class AppBarLayout extends AppBar {
static final AppController _appController = new AppController();
final GlobalKey<ScaffoldState> _scaffoldKey;
final String appBarTitle;
AppBarLayout(this.appBarTitle,this._scaffoldKey): super(
title: Text(appBarTitle),
leading: IconButton(
onPressed: () => _scaffoldKey.currentState.openDrawer(),
iconSize: 28,
icon: Icon(Icons.menu,color: Colors.white),
),
actions: <Widget>[
IconButton(
onPressed: () => _appController.signOut().then((_) {
_appController.navigateTo(context, new GoogleSignView());
}),
icon: Icon(Icons.account_box),
padding: EdgeInsets.all(0.0),
),
],
);
}
Run Code Online (Sandbox Code Playgroud) 我有一个 2 列颤动数据表,线条不跨越屏幕宽度,留下大量空白。我发现了这个问题
https://github.com/flutter/flutter/issues/12775
建议将 DataTable 包装在 SizedBox.expand 小部件中,但这不起作用 RenderBox was not laid out:
SizedBox.expand(
child: DataTable(columns:_columns, rows:_rows),
),
Run Code Online (Sandbox Code Playgroud)
完整的小部件
@override
Widget build(BuildContext context) {
return new Scaffold(
body:
SingleChildScrollView(
child: Column(
children: [Container(Text('My Text')),
Container(
alignment: Alignment.topLeft,
child: SingleChildScrollView(scrollDirection: Axis.horizontal,
child: SizedBox.expand(
child: DataTable(columns:_columns, rows:_rows),
),
),
),
]))
);
}
Run Code Online (Sandbox Code Playgroud) 目标:按下一个按钮,让它切换到另一个带有动画过渡的页面。
为此,我正在使用 AnimatedSwitcher。
下面是我的代码:
class WelcomeScreenSwitcher extends State<RandomWords>{
Widget calledWidget;
void switchPage(int newNumber, context) {
if (newNumber == 1) {
setState(() {calledWidget = welcomeScreen(context);},);
} else if (newNumber == 2) {
setState(() {calledWidget = learnMoreScreen(context);},);}
}
@override
Widget build(BuildContext context) {
if (calledWidget == null) {
switchPage(1, context);
}
return AnimatedSwitcher(
duration: Duration(milliseconds: 5000),
child: calledWidget,
);
Widget welcomeScreen(context){
return Scaffold({body: Column(children: [
RaisedButton(onPressed: () {switchPage(2, context);}, child: Text('B'),),],
);
});
}
Widget learnMoreScreen(context){
return Scaffold({body: Column(children: [
RaisedButton(onPressed: () …Run Code Online (Sandbox Code Playgroud) 我想在显示日期选择器中将语言从英语更改为法语,请在下面找到我正在使用的代码和一个应该解决该问题的类似代码,但它使代码不适用于此部分:
new Step(
title: new Text("Quelle est la date de 1er immatriculation?"),
content: Column(
children: <Widget>[
Text(_datetime == null ? "Vous n'avez pas encore choisi de date" : _datetime.toString().substring(0, 10)),
RaisedButton(
child: Text('choisissez une date'),
onPressed: () {
showDatePicker(context: context,
locale : const Locale("fr","FR"),//this line making the code not working too
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.fallback(),
child: child,
);
},
// locale: const Locale('eu', 'FR'),
initialDate: DateTime.now(),
firstDate: DateTime(1920),
lastDate: DateTime(2100),
).then((date) {
setState(() { …Run Code Online (Sandbox Code Playgroud) dart flutter flutter-dependencies flutter-layout flutter-animation
当我尝试从 url 加载 pdf 时出现错误。它显示pdf的页数,但随后崩溃。
使用插件 - https://pub.dev/packages/advance_pdf_viewer
????????????????????????????????????????????????????????????????????????????????????????????????????
I/flutter (28488): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????????????????????????????????????????????????????????????
I/flutter (28488): The following assertion was thrown while rebuilding dirty elements:
I/flutter (28488): 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4371 pos 14:
I/flutter (28488): 'owner!._debugCurrentBuildTarget == this': is not true.
I/flutter (28488):
I/flutter (28488): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (28488): more information in this error message to help you determine and fix the …Run Code Online (Sandbox Code Playgroud)