Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter “错误”;不支持的操作:removeLast";从列表<;字符串>;由Uri.parse(';';).pathSegments生成_Flutter_Dart_Runtime Error_Uri_String Parsing - Fatal编程技术网

Flutter “错误”;不支持的操作:removeLast";从列表<;字符串>;由Uri.parse(';';).pathSegments生成

Flutter “错误”;不支持的操作:removeLast";从列表<;字符串>;由Uri.parse(';';).pathSegments生成,flutter,dart,runtime-error,uri,string-parsing,Flutter,Dart,Runtime Error,Uri,String Parsing,在当前基于颤振1.23.0-18.1.pre-Dart SDK 2.10.4的上运行以下代码 导入“包装:颤振/材料.省道”; void main(){ 最终的_列表=['1','2','3','4']; 打印(“'u list是一个${'u list.runtimeType}”); 打印(“${u list.last}”); 试一试{ _list.removeLast(); }捕获(e){ 印刷品(e); } 打印(“${u list.last}”); 最终_routeInfo=路由信息(位置

在当前基于颤振1.23.0-18.1.pre-Dart SDK 2.10.4的
上运行以下代码

导入“包装:颤振/材料.省道”;
void main(){
最终的_列表=['1','2','3','4'];
打印(“'u list是一个${'u list.runtimeType}”);
打印(“${u list.last}”);
试一试{
_list.removeLast();
}捕获(e){
印刷品(e);
}
打印(“${u list.last}”);
最终_routeInfo=路由信息(位置:'/user/info/5');
final _segments=Uri.parse(_routeInfo.location).pathSegments;
打印(“U段是${U段.runtimeType}”);
打印(“${u segments.last}”);
试一试{
_片段。removeLast();
}捕获(e){
印刷品(e);
}
打印(“${u segments.last}”);
}
我有以下输出:

_list is a List<String>
4
3
_segments is a List<String>
5
Unsupported operation: removeLast
5
\u列表是一个列表
4.
3.
_段是一个列表
5.
不支持的操作:removeLast
5.

我不明白,我遗漏了什么?

显然,将列表包装如下可以解决问题

final _segments=[…Uri.parse(_routeInfo.location).pathSegments]

import 'package:flutter/material.dart';

void main() {
  final _list = ['1', '2', '3', '4'];
  print('_list is a ${_list.runtimeType}');

  print('${_list.last}');
  try {
    _list.removeLast();
  } catch (e) {
    print(e);
  }
  print('${_list.last}');
  
  final _routeInfo = RouteInformation(location: '/user/info/5');

-  final _segments = Uri.parse(_routeInfo.location).pathSegments;

+  final _segments = [...Uri.parse(_routeInfo.location).pathSegments];

  print('_segments is a ${_segments.runtimeType}');
  print('${_segments.last}');
  try {
    _segments.removeLast();
  } catch (e) {
    print(e);
  }
  print('${_segments.last}');
}

显然,按如下方式包装列表可以解决问题

final _segments=[…Uri.parse(_routeInfo.location).pathSegments]

import 'package:flutter/material.dart';

void main() {
  final _list = ['1', '2', '3', '4'];
  print('_list is a ${_list.runtimeType}');

  print('${_list.last}');
  try {
    _list.removeLast();
  } catch (e) {
    print(e);
  }
  print('${_list.last}');
  
  final _routeInfo = RouteInformation(location: '/user/info/5');

-  final _segments = Uri.parse(_routeInfo.location).pathSegments;

+  final _segments = [...Uri.parse(_routeInfo.location).pathSegments];

  print('_segments is a ${_segments.runtimeType}');
  print('${_segments.last}');
  try {
    _segments.removeLast();
  } catch (e) {
    print(e);
  }
  print('${_segments.last}');
}