点击容器会触发onTap()处理程序,但不会显示任何墨水飞溅效果.
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new InkWell(
onTap: (){print("tapped");},
child: new Container(
width: 100.0,
height: 100.0,
color: Colors.orange,
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我试着把InkWell内部放在里面Container但是徒劳无功.
我正在构建一个页面,动态地生成一些视图.在我的情况下,显示的列表将根据用户输入(用作过滤器)进行更新.
当使用Text Widget进行动态渲染时,一切都运行得很好,但是当我尝试切换到Column或Gridview时,一切都出错并且出现了下面的错误
The following assertion was thrown building ServerGrid(dirty; state: _ServerGridState#59211289()):
I/flutter (14351): setState() or markNeedsBuild() called during build.
I/flutter (14351): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (14351): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (14351): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (14351): builds …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习flutter,我很好奇如何setState()动态地在flutter中
我React Native通常使用这样的函数来setState动态地:
class foo extends React.Component{
state={
username:null,
password:null
}
toggleSetState(whatState, value){
this.setState({ [whatState]: value })
}
render() {
return (
<View>
<TextInput
value={this.state.username}
onChangeText={(text)=>{toggleSetState(username, text)}
/>
<TextInput
value={this.state.password}
onChangeText={(text)=>{toggleSetState(password, text)}
/>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
与上面的代码等效的是什么Flutter?
我已经尝试过,Flutter但似乎不起作用
class _LoginFormState extends State<LoginForm> {
String username, password;
void ToogleState(typedata, text){
setState(() {
typedata = text;
});
}
//Widget
TextField(
onChanged: (text){ToogleState(username, text); print(username);},
decoration: InputDecoration(
hintText: 'input username', labelText: 'Username' …Run Code Online (Sandbox Code Playgroud) 单击图标按钮后,我尝试调用 showDatePicker 小部件,但是当我调用 onTap 方法时出现以下错误:
参数类型 'Future' 不能分配给参数类型 '() ?空白'。
请在下面找到我的代码:
showDatePicker 代码
DateTime selectedDate = DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2018, 1),
lastDate: DateTime(2101));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
});
}
Run Code Online (Sandbox Code Playgroud)
图标按钮代码
IconButton(
icon: Icon(Icons.date_range),
onPressed: _selectDate(context)),
Run Code Online (Sandbox Code Playgroud)
我正在使用 StatefulWidget,请告诉我如何解决这个问题。谢谢 :)
我有一个秒表,想要一个可以暂停和启动它的按钮。我正在努力解决这个问题的逻辑。打印到控制台时,布尔值停留在 false 上,并且不允许我重新单击该按钮。
秒表.dart:
class NewStopWatch extends StatefulWidget {
@override
_NewStopWatchState createState() => new _NewStopWatchState();
}
class _NewStopWatchState extends State<NewStopWatch> {
Stopwatch watch = new Stopwatch();
Timer timer;
bool startStop = true;
String elapsedTime = '';
updateTime(Timer timer) {
if (watch.isRunning) {
setState(() {
startStop = false;
print("startstop Inside=$startStop");
elapsedTime = transformMilliSeconds(watch.elapsedMilliseconds);
});
}
}
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.all(20.0),
child: new Column(
children: <Widget>[
new Text(elapsedTime, style: new TextStyle(fontSize: 25.0)),
SizedBox(height: 20.0),
new Row( …Run Code Online (Sandbox Code Playgroud)