美文网首页
Flutter 路由传入中文参数报错无法push问题

Flutter 路由传入中文参数报错无法push问题

作者: iOSChenC | 来源:发表于2019-06-10 09:08 被阅读0次

    flutter自带路由传递参数和使用第三方库fluro路由传递参数都可以通过一下方式解决问题

    String jsonString = json.encode(mapValue);
    var jsons = jsonEncode(Utf8Encoder().convert(jsonString));
    Application.router.navigateTo(context, '/informationDetail?informationString=${jsons}',transition: TransitionType.inFromRight);
    

    其中mapValue是你需要传递的参数,我是将所有下个界面需要使用的参数全部装入这个map中然后通过json去编码转义,比如我的`

    mapValue = {
     'name' = '张三',
     'employeeId' = '123456789',
     'age' = '25',
     .........
     'key' = 'value'
    }
    

    中间可以组合很多,这个可以根据大家具体的求来进行组装就可以了,走到这个地方还没有完,因为在下个界面你要对传过来的值进行反转,翻转方法如下

    var list = List<int>();
        ///字符串解码
    jsonDecode(informationString).forEach(list.add);
    final String value = Utf8Decoder().convert(list);
    var mapValue = json.decode(value);
    

    上面的informationString就是上个界面传入的数据,然后进行翻转的字符串,最后得到的mapValue就可以使用了,这样路由中传递中文参数出错的问题就解决了。
    如果对大家有帮助,希望大家点赞、点喜欢,写文章不易呀

    相关文章

      网友评论

          本文标题:Flutter 路由传入中文参数报错无法push问题

          本文链接:https://www.haomeiwen.com/subject/tgkaxctx.html