相关疑难解决方法(0)

InkWell没有显示涟漪效应

点击容器会触发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但是徒劳无功.

dart flutter

37
推荐指数
10
解决办法
2万
查看次数

颤抖 - 无法建造,因为frawework已经建成

我正在构建一个页面,动态地生成一些视图.在我的情况下,显示的列表将根据用户输入(用作过滤器)进行更新.

当使用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)

dart flutter

10
推荐指数
2
解决办法
5786
查看次数

如何在flutter中动态设置State变量?

我刚刚开始学习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)

dart flutter

3
推荐指数
1
解决办法
7574
查看次数

Flutter 错误:无法将参数类型 'Future&lt;void&gt;' 分配给参数类型 '() ?空白'

单击图标按钮后,我尝试调用 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,请告诉我如何解决这个问题。谢谢 :)

dart flutter

1
推荐指数
1
解决办法
3953
查看次数

Flutter:使用相同按钮启动和停止计时器

我有一个秒表,想要一个可以暂停和启动它的按钮。我正在努力解决这个问题的逻辑。打印到控制台时,布尔值停留在 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)

asynchronous timer widget dart flutter

1
推荐指数
1
解决办法
5145
查看次数

标签 统计

dart ×5

flutter ×5

asynchronous ×1

timer ×1

widget ×1