static String generateUri(Trip trip, String leading){
    String uri = "{leading}://trips?time={time}&origin={origin}&destination={destination}";
    uri.replaceAll("{leading}", leading)
    .replaceAll("{time}", trip.departurePlannedTime!.toIso8601String())
    .replaceAll("{origin}", trip.originLocation!.id.toString())
    .replaceAll("destination", trip.destinationLocation!.id.toString());
    return uri;
  }

顺便说一句,我需要用于深度链接的带自定义引线的URI,但我发现没有为我创建它-uri.http不能真正满足我在这里所需要的东西.

话虽如此:我正试图为我正在工作的应用程序创建一个深度链接,但似乎不起作用,运行上面的代码会得到与我在第2行中定义的完全相同的字符串.

更多的猜测,而不是头脑中的任何 idea ,我试着用replaceFirst(在这种情况下不应该有什么不同,因为只有一次出现)更改了所有的替换.

我以前使用过.REPLACE,所以我不确定为什么这不起作用.我还try 使用Blankspace将{}中的内容与字符串的其余部分分开,但也没有任何效果(如果有的话,我会感到惊讶,但这只是一个猜测).

推荐答案

replaceAll()以字符串形式返回结果,并且不修改现有结果.这应该行得通

  static String generateUri(Trip trip, String leading){
    String uri = "{leading}://trips?time={time}&origin={origin}&destination={destination}";

    return uri.replaceAll("{leading}", leading)
    .replaceAll("{time}", trip.departurePlannedTime!.toIso8601String())
    .replaceAll("{origin}", trip.originLocation!.id.toString())
    .replaceAll("destination", trip.destinationLocation!.id.toString());
  }

Flutter相关问答推荐

如何从模型列表中生成DropdownButtonFormField?

Flutter 图标记移动

分页控制器在到达页面末尾之前或在初始化页面时对每个索引调用API

如何将assets资源 实体类型转换为文件类型?

如何在不注销的情况下刷新Firebase身份验证用户

FittedBox叠加技术在Flutter 中的应用

如何使DropDownMenu宽度等于TextFormfield?

如何在Flutter中将背景 colored颜色 更改为黑色?

Flutter:使用不包含导航器的上下文请求导航器操作

如何给按钮的边框半径?

Flutter:如何在现有布局之上显示圆角布局?

'type' Icon '不是类型' IconData '的子类型

你如何在 Flutter 中组合两个数组?

如何显示从 MariaDB 获取的数据到列表视图

Flutter 动画页面计数器文本

flutter - 无法解析 JSON 消息:文档为空

Flutter 如何要求用户在应用程序中设置电话密码?

为什么容器会填满整个空间?

gridview 的所有按钮都应该在Flutter 中适合其父容器

是否可以在 Flutter 中使用 ToggleButtons 在页面 PageView 之间切换?