jjzjj

BuildContext

全部标签

firebase - 为小部件调用两个不同端点的最佳实践?

当需要两个不同的端点来呈现某些内容时,最佳做法是什么?现在我正在嵌套FutureBuilders,但这似乎并不理想。例子:@overrideWidgetbuild(BuildContextcontext){returnnewFutureBuilder(future:Firestore.instance.collection('games').document(this.documentId).get(),builder:(BuildContextgamesContext,AsyncSnapshotgamesSnapshot){returnnewFutureBuilder(future:

firebase - 为小部件调用两个不同端点的最佳实践?

当需要两个不同的端点来呈现某些内容时,最佳做法是什么?现在我正在嵌套FutureBuilders,但这似乎并不理想。例子:@overrideWidgetbuild(BuildContextcontext){returnnewFutureBuilder(future:Firestore.instance.collection('games').document(this.documentId).get(),builder:(BuildContextgamesContext,AsyncSnapshotgamesSnapshot){returnnewFutureBuilder(future:

flutter - 使用 FutureBuilder 时重新加载数据

当小部件加载时,我正在加载数据,如下面的代码。一旦UI完全加载,我喜欢添加一个刷新按钮来重新加载数据。如何刷新View?class_MyHomePageStateextendsState{@overrideWidgetbuild(BuildContextcontext){varfutureBuilder=newFutureBuilder(future:_getData(),builder:(BuildContextcontext,AsyncSnapshotsnapshot){switch(snapshot.connectionState){caseConnectionState.non

flutter - 使用 FutureBuilder 时重新加载数据

当小部件加载时,我正在加载数据,如下面的代码。一旦UI完全加载,我喜欢添加一个刷新按钮来重新加载数据。如何刷新View?class_MyHomePageStateextendsState{@overrideWidgetbuild(BuildContextcontext){varfutureBuilder=newFutureBuilder(future:_getData(),builder:(BuildContextcontext,AsyncSnapshotsnapshot){switch(snapshot.connectionState){caseConnectionState.non

flutter - 像 SliverAppBar 一样隐藏 TabBar

所以网上有很多例子,你可以使用在滚动时隐藏的SliverAppBar,而下面的TabBar仍然显示。我找不到任何相反的方法:当我向上滚动我只想隐藏TabBar,保留AppBar一直持续显示。有谁知道如何做到这一点?HereisaexamplewithAppBarhiding(这不是我想要的,只是有助于更好地理解我想要的)。更新这是我迄今为止尝试过的,我认为它有效,但问题是我无法让Positioned字段中的AppBar获得正确的高度(例如iPhoneX,它的高度更大,并且与标签栏重叠)。//thissliverappbarisonlyusetohide/showthetabBar,th

flutter - 像 SliverAppBar 一样隐藏 TabBar

所以网上有很多例子,你可以使用在滚动时隐藏的SliverAppBar,而下面的TabBar仍然显示。我找不到任何相反的方法:当我向上滚动我只想隐藏TabBar,保留AppBar一直持续显示。有谁知道如何做到这一点?HereisaexamplewithAppBarhiding(这不是我想要的,只是有助于更好地理解我想要的)。更新这是我迄今为止尝试过的,我认为它有效,但问题是我无法让Positioned字段中的AppBar获得正确的高度(例如iPhoneX,它的高度更大,并且与标签栏重叠)。//thissliverappbarisonlyusetohide/showthetabBar,th

dart - 通过参数获取 BuildContext 不可用时

是否有不需要上下文的Navigator.push替代方案?这是我的问题。我有一个嵌套很深的调用堆栈,并不是每个函数都有一个BuildContext参数。除了将当前BuildContext从一个函数传递到另一个函数之外,还有其他方法可以获取当前BuildContext吗?test1.dartWidgetbuild(BuildContext){...newGestureDetector(onTap:()=>foo1()//verydeepcallstackuntilitcallsfoo30...}test2.dartvoidfoo30(){//needcontextherelike:Bui

unit-testing - Flutter 中的单元测试通过 BuildContext

我在Dart类中有一个方法,它接受BuildContext参数,如下所示:classMyClass{myMethodName(BuildContextcontext,...){...doSomethingreturnsomething;}}我想测试该方法是否按预期工作:import'package:flutter/material.dart';import'package:flutter_test/flutter_test.dart';import'package:mockito/mockito.dart';...voidmain(){MyClasssut;setUp((){sut=M

flutter - 如何在有状态或无状态小部件之外访问 BuildContext?

我在Flutter中创建了一个扩展AppBar类的类,这样我就可以在需要时重用它。我的问题是如何访问有状态/无状态小部件构建上下文?classAppBarLayoutextendsAppBar{staticfinalAppController_appController=newAppController();finalGlobalKey_scaffoldKey;finalStringappBarTitle;AppBarLayout(this.appBarTitle,this._scaffoldKey):super(title:Text(appBarTitle),leading:Icon

dart - 在 Flutter 中获取 BuildContext 以进行本地化

我尝试使用本地化包在Flutter中本地化一个字符串。问题是需要我翻译的位置。它与UI无关,而是在我模型的某个深处,我无权访问BuildContext。有没有其他的可能继续使用翻译功能?//Idon'thaveacontextvariablehereMyLocalizations.of(context).trans("foo") 最佳答案 是的。您不需要BuildContext来访问字符串。这是我的解决方案:classStrings{Strings._(Localelocale):_localeName=locale.toStrin