相关疑难解决方法(0)

Flutter streambuilder vs futurebuilder

有人请解释一下streambuilder和futurebuilder之间的主要区别.我真的很困惑.

  • 使用什么以及何时使用?

  • 他们打算执行哪些任务?

  • 他们每个人如何监听动态列表中的更改?

dart flutter

28
推荐指数
4
解决办法
6460
查看次数

在Flutter中完成"构建"功能时是否有任何回调告诉我?

我的屏幕上有一个listView.我已经附加了一个控制器.我可以调用我的端点,接收响应,解析它并插入行.ListView应该自动滚动.确实如此,但并非完美无缺.我总是背后的一个项目.这是我的代码:

@override
  Widget build(BuildContext context) {
    // Scroll to the most recent item
    if (equationList.length > 0) {
      _toEnd();
    }

    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: EquList(equationList, _scrollController),
      floatingActionButton: new FloatingActionButton(
        onPressed: onFabClick,
        tooltip: 'Fetch Post',
        child: new Icon(isLoading ? Icons.pause : Icons.play_arrow),
      ),
    );
  }

  void _toEnd() {
    _scrollController.animateTo(
      _scrollController.position.maxScrollExtent,
      duration: const Duration(milliseconds: 250),
      curve: Curves.ease,
    );
  }
Run Code Online (Sandbox Code Playgroud)

问题是,我_toEnd()在最后一项插入列表之前调用函数.所以,我正在寻找一个回调(如果有的话)告诉我build()完成了.然后我打电话给我的_toEnd()功能.

在这种情况下,最佳做法是什么?

flutter

17
推荐指数
3
解决办法
7695
查看次数

为什么 initState() 被调用两次?

initState() 在我路由到的第一个 Widget 上被调用两次。

我已经删除了 initState() 方法中正在完成的所有方法调用和工作,以排除它以某种方式调用自身的任何可能性。它所做的只是调用 super.initState()。

路线.dart:

final routes = {
  '/login' : (BuildContext context) => new LoginPage(),
  '/' : (BuildContext context) => new LoginPage()
};
Run Code Online (Sandbox Code Playgroud)

主要.dart:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Personnel Ledger',
      initialRoute: '/login',
      routes: routes,
      theme: ThemeData(
        scaffoldBackgroundColor: Color(0xFF30778B)
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

登录页面.dart:

class LoginPage extends StatefulWidget {
  @override
  LoginPageState createState() => LoginPageState();
}

class LoginPageState extends State<LoginPage> {
  TextEditingController emailTextfieldCtrl;
  TextEditingController …
Run Code Online (Sandbox Code Playgroud)

flutter

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

在initState中调用SetState的重要性

setState()方法应该被称为的内部initState()方法StatefullWidget吗?

我的理解是该initState()方法将自动应用状态。

下面的代码不起作用。post对象的值为空。

  @override
  void initState() {
    ItemService.getItemById(widget.postId).then((DocumentSnapshot doc){
        post = ItemService.getPostFromDocument(doc);
    });
  }
Run Code Online (Sandbox Code Playgroud)

但是下面的作品。

  @override
  void initState() {
    ItemService.getItemById(widget.postId).then((DocumentSnapshot doc){
      setState((){
        post = ItemService.getPostFromDocument(doc);
      });
    });
  }
Run Code Online (Sandbox Code Playgroud)

在其他一些情况下,即使不使用setState()同一类也可以正常工作。

因此,什么时候应该使用setState()内部initState()方法,什么时候不应该使用?

另一个相关问题:

super.initState()initState()什么时候应该打电话给我?我不打扰没关系吗?

flutter

6
推荐指数
2
解决办法
1722
查看次数

Flutter 中 'Future&lt;dynamic&gt;' 的实例

我从服务器获取一个 int Id,它在颤振的 HTTP 请求中,这没问题,我想将此值保存在一个变量中,但是当我调用返回值时,我收到此错误实例 'Future' ,有什么建议吗? ? 这是代码

                    child: RaisedButton(onPressed:() {
                    CurrentPrjId= SaveProject();
                    print("CurrentPrjId Is saved CurrentPrjId :::::::: " );
                    print(CurrentPrjId);
                    Navigator.of(context).pushReplacementNamed('/AllUSerStories');
                }
//Save Project

  Future SaveProject() async {

//SaveProjectResult has the id of the current created project which i need that for its user stories
var SaveProjectResult = await GetPostProjects().createProject(_ProjectnameController.text, _CustomernameController.text, _dropNewItem, _dropNewItem2, _StartDateController.text, _EndDateController.text,);
print(":::::::::::::::::::::::::::::::The Project Is Created And Here Its ID In SaveProject:::::::::");
print(SaveProjectResult);
return SaveProjectResult;
Run Code Online (Sandbox Code Playgroud)

}

c# asp.net-mvc future dart flutter

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

标签 统计

flutter ×5

dart ×2

asp.net-mvc ×1

c# ×1

future ×1