我正在使用kotlin coroutines进行网络请求,使用扩展方法在这样的改造中调用类
public suspend fun <T : Any> Call<T>.await(): T {
return suspendCancellableCoroutine { continuation ->
enqueue(object : Callback<T> {
override fun onResponse(call: Call<T>?, response: Response<T?>) {
if (response.isSuccessful) {
val body = response.body()
if (body == null) {
continuation.resumeWithException(
NullPointerException("Response body is null")
)
} else {
continuation.resume(body)
}
} else {
continuation.resumeWithException(HttpException(response))
}
}
override fun onFailure(call: Call<T>, t: Throwable) {
// Don't bother with resuming the continuation if it is already cancelled.
if (continuation.isCancelled) return
continuation.resumeWithException(t)
} …
Run Code Online (Sandbox Code Playgroud) 我有一个现有的android应用程序,并且在我的项目中集成了flutter,我想调用在我的主要方法中定义的flutter特定路线
class FlutterView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Platform View',
initialRoute: '/',
routes: {
'/': (context) => HomeScreen(),
'/secound': (context) => MyCustomForm(),
'/dashboard': (context) => DashBoardScreen(),
'/login': (context) => LoginScreen(),
},
theme: new ThemeData(
primarySwatch: Colors.red,
textSelectionColor: Colors.red,
textSelectionHandleColor: Colors.red,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
从我的android活动中,我正在这样叫颤动
startActivity(new Intent(this,FlutterActivity.class));
它的确打开了flutter活动,但是使用了initialRoute:'/'很好,但是有一段时间我想在打开flutter活动时针对eg('/ dashboard')路线打开它,我该怎么做?
我想实现下拉菜单的这种设计,但是不确定如何获得这种下拉菜单
Container(
padding: EdgeInsets.all(10.0),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
items:_locations.map((String val){
return DropdownMenuItem<String>(
value: val,
child: Container(
margin: EdgeInsets.only(left: 10.0,right: 10.0),
child: new Text(val)
),
);
}).toList(),
hint:Text(_SelectdType),
onChanged:(String val){
_SelectdType = val;
setState(() {});
}
),
),
)
Run Code Online (Sandbox Code Playgroud) 我正在像这样的流媒体列表进行屏幕更改,当它发出时,我更改屏幕
@override
void initState() {
super.initState();
appBloc.error.listen((data) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(content: new
Text(data)));
});
appBloc.success.listen((_) => goToDashBoardScreen(context));
}
Run Code Online (Sandbox Code Playgroud)
和doToDashBoardScreen看起来像这样
Navigator.pushReplacement(context, new SlideRightRoute(widget:
DashBoardScreen()));
Run Code Online (Sandbox Code Playgroud)
但是我遇到这样的错误,但是我更改了页面。
22:05:02.446 3 info flutter.tools E/flutter (13216): NoSuchMethodError:
The method 'ancestorStateOfType' was called on null.
22:05:02.446 4 info flutter.tools E/flutter (13216): Receiver: null
22:05:02.446 5 info flutter.tools E/flutter (13216): Tried calling:
ancestorStateOfType(Instance of 'TypeMatcher<NavigatorState>')
22:05:02.446 6 info flutter.tools E/flutter (13216): #0
Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:48:5)
22:05:02.446 7 info flutter.tools E/flutter (13216): #1
Navigator.of (package:flutter/src/widgets/navigator.dart:1270:19)
22:05:02.446 8 info flutter.tools E/flutter (13216): …
Run Code Online (Sandbox Code Playgroud)