在普通颤动中,我用来将多个参数传递到其他屏幕,如下所示:
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => CatalogFilterPage(
list: list,
bloc: bloc,
)))
Run Code Online (Sandbox Code Playgroud)
非常简单和容易。我可以传递 2 个所需的参数,列表和块。在 CatalogFilterPage 中使用后。
现在,在切换到 go_router 并查看文档后,我似乎找不到如何传递多个数据。即使传递单个对象似乎也不是那么好:
onTap: () =>
context.pushNamed('SelectedCatalogItem', extra: list[index]),
Run Code Online (Sandbox Code Playgroud)
在路由器中,我必须使用强制转换来设置正确的类型:
builder: (context, state) => SelectedCatalogItem(
item: state.extra as ListItemsModel,
),
Run Code Online (Sandbox Code Playgroud)
对于单个参数来说很好。但现在我不知道如何传递多个参数。我该怎么做?甚至传递参数(例如模型)作为额外的方法是正确的方法吗?
PS 我知道您可以将参数传递为context.pushNamed('CatalogFilterPage', params: ___),但params类型为 Map<String, String> ,但不允许我传递模型的
Map<String,String> headers = {'Content-Type':'application/json','authorization':'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='};
var response = await post(Urls.getToken,
headers: headers,
body: {"grant_type":"password","username":"******","password":"*****","scope":"offline_access"},
);
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,我无法接收数据并且抛出的错误是
错误状态:无法设置内容类型为“application/json”的请求的正文字段
我正在尝试使用颤振中的容器小部件构建一侧圆形边框。我已经搜索过它,但找不到任何解决方案。
Container(
width: 150.0,
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(30.0),
/* border: Border(
left: BorderSide()
),*/
color: Colors.white
),
child: Text("hello"),
),
Run Code Online (Sandbox Code Playgroud) 自 Flutter 1.12 发布以来,我的以下代码:
static MyInheritedWidget of(BuildContext context) {
return context.inheritFromWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
Run Code Online (Sandbox Code Playgroud)
警告如下:
'inheritFromWidgetOfExactType' 已弃用,不应使用。改用dependOnInheritedWidgetOfExactType。此功能在 v1.12.1 之后被弃用。尝试用替换来替换弃用成员的使用。
但是当我尝试更换它时,它不起作用:
static MyInheritedWidget of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
Run Code Online (Sandbox Code Playgroud)
有人知道怎么做吗?谢谢!
我正在尝试试驾一个应用程序。由于应用程序无法调试/运行,我一直遇到这个问题的奇怪问题。SDK 版本为 28,其余版本如下:
Flutter 1.13.9-pre.79 • channel master • https://github.com/flutter/flutter.git
Framework • revision 9eb9ea0ffa (6 hours ago) • 2020-01-13 21:30:42 -0800
Engine • revision 0235a50843
Tools • Dart 2.8.0 (build 2.8.0-dev.0.0 28c335d5a2)
Run Code Online (Sandbox Code Playgroud)
Gradle 构建未能生成 .apk 文件。这个文件很可能是在 C:\Development\\build 下生成的,但工具找不到它。
有没有办法通过向 Gradle 提供或提供输出路径来传递这个问题或允许我运行的配置?.apk 似乎是在错误状态下生成的。
更新:
Android Studio -v 3.5.3
Gradle -v 3.4.2
Gradle Wrapper -v 5.1.1
Run Code Online (Sandbox Code Playgroud) 我是新手 Flutter
运行简单的 flutter APP 时出现此错误。我无法弄清楚为什么会发生此错误。
错误
Null check operator used on a null value
我在 main.dart 中的代码
import 'package:flutter/material.dart';
import './ui/login.dart';
void main() {
runApp(new MaterialApp(
title: "Login Template",
home: new Login(),
));
}
Run Code Online (Sandbox Code Playgroud)
我在 login.dart 中的代码
import 'package:flutter/material.dart';
class Login extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new LoginState();
}
}
class LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Login"),
centerTitle: true,
backgroundColor: Colors.blueAccent.shade50,
),
backgroundColor: Colors.blueGrey, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用颤振插件 HTTP 发出 HTTP POST 请求,但出现标题错误。有谁知道这是什么原因,因为在我的其他应用程序中这工作得很好?
await http.post(Uri.encodeFull("https://api.instagram.com/oauth/access_token"), body: {
"client_id": clientID,
"redirect_uri": redirectUri,
"client_secret": appSecret,
"code": authorizationCode,
"grant_type": "authorization_code"
});
Run Code Online (Sandbox Code Playgroud) 我对super.initSate()在 Flutter 中调用的位置感到困惑?在一些代码示例中,它在开始时被调用,而在其他代码示例中则在最后被调用。有区别吗?
我试图用谷歌搜索这个,但没有找到关于这个函数调用位置的任何解释。
哪一个是正确的?
void initState() {
super.initState();
//DO OTHER STUFF
}
Run Code Online (Sandbox Code Playgroud)
或者
void initState() {
//DO OTHER STUFF
super.initState();
}
Run Code Online (Sandbox Code Playgroud) 我在我的 android flutter 应用程序中使用了 google maps api 和 location pub,dev 包,并尝试使用 api 中的 url 调出图像。这是带有一些代码的网址:
class LocationHelper{
static String mapviewpointer({double latitude, double longitude}){
return "https://maps.googleapis.com/maps/api/staticmap?center=$latitude,$longitude&zoom=13&size=600x300&maptype=roadmap&markers=color:pink%7Clabel:C%7C$latitude,$longitude&key=$GOOGLE_API_KEY";
}
}
Run Code Online (Sandbox Code Playgroud)
它抛出以下错误消息:
Plugin project :location_web not found. Please update settings.gradle;
我不知道如何解决这个错误。
这是我在终端中收到的另一个错误:
I/flutter (21880): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future%3CString%3E'
Run Code Online (Sandbox Code Playgroud)
我收到上述错误消息的区域在我的代码中:
Future <String> _getUserLocation() async{
final locData = await Location().getLocation();
final staticMapUrl = LocationHelper.mapviewpointer(
latitude: locData.latitude,
longitude: locData.longitude,
);
return staticMapUrl;
}
final mapview = _getUserLocation();
class NearbyScreen extends StatelessWidget {
@override …Run Code Online (Sandbox Code Playgroud) google-maps-api-3 dart flutter flutter-dependencies flutter-web
我在 Visual Studio Code 中收到此错误代码。我该如何修复它?
我使用的是 Flutter v2.5.3。

flutter ×10
dart ×9
android ×1
apk ×1
border ×1
flutter-web ×1
gradle ×1
http ×1
navigation ×1
routes ×1