flutter_learning_demo icon indicating copy to clipboard operation
flutter_learning_demo copied to clipboard

有个疑问,关于在State -> build方法中获取数据

Open df13954 opened this issue 4 years ago • 0 comments

Widget build(BuildContext context) {
    /// 对 中文 进行解码
    String mName = FluroConvertUtils.fluroCnParamsDecode(widget.name);
    /// 对自定义类 进行解析
    Person person =
        Person.fromJson(FluroConvertUtils.string2map(widget.personJson));
    print(person.name);
    print(person.age);
    print(person.sex);
    /// 下面的写法也可以
    Map<String, dynamic> data = FluroConvertUtils.string2map(widget.personJson);
    print(data["name"]);
    print(data["age"]);
    print(data["sex"]);

如果页面有更新,build是会被调用的吧。 在build中这样会重复解释获得数据。

df13954 avatar Mar 02 '21 07:03 df13954