Fair icon indicating copy to clipboard operation
Fair copied to clipboard

打开demo中的page_two出现异常错误:exceptionValue:TypeError: undefined is not an object

Open softAlexs opened this issue 3 years ago • 7 comments

问题

打开demo中的page_two出现异常错误:exceptionValue:TypeError: undefined is not an object

页面源码:

Navigator.pushNamed(context, 'fair_page_two', arguments: { 'path': 'assets/fair/lib_developer_page2page_page_two.fair.json', 'data': {'title': 'PageTwo'} });

import 'package:fair/fair.dart'; import 'package:flutter/material.dart';

@FairPatch() class PageTwo extends StatefulWidget { PageTwo({Key? key, this.fairProps}) : super(key: key);

dynamic fairProps;

@override _PageTwoState createState() => _PageTwoState(); }

class _PageTwoState extends State<PageTwo> { @FairProps() var fairProps;

@override void initState() { super.initState(); fairProps = widget.fairProps; }

String getTitle() { return fairProps['title']; }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( /// 如果需要进行字符串拼接的话,在build()方法里进行拼接即可,不建议在getTitle() /// 方法里做字符串拼接 title: Text('参数:${getTitle()}'), ), body: Container( child: Padding( padding: EdgeInsets.all(20), child: Text('xxxxx'), )), ); } }

错误日志: [Fair]: File:FairDartBridge.m, Function:-[FairDartBridge obtainModelWithMessage:], Line:103 >> {"path":"GLOBAL['null#1']=(function(initProps){const global=this;return runCallback(function(mod){with(mod.imports){function _PageTwoState(){const inner=_PageTwoState.inner;if(this==global){return new _PageTwoState({args:arguments});}else{const args=arguments.length>0?arguments[0].args||arguments:[];inner.apply(this,args);_PageTwoState.prototype.ctor.apply(this,args);return this;}}_PageTwoState.inner=function inner(){this.fairProps=initProps;};_PageTwoState.prototype={initState:function initState(){const thiz=this;with(thiz){fairProps=widget.fairProps;}},getTitle:function getTitle(){const thiz=this;with(thiz){return fairProps.op_idx('title');}},};_PageTwoState.prototype.ctor=function(){Object.prototype.ctor.call(this);};;return _PageTwoState();}},[]);})(convertObjectLiteralToSetOrMap(JSON.parse('{"title":"PageTwo"}')));","pageName":"null#1"} [Fair]: File:FairProcessManager.m, Function:-[FairProcessManager injectionJSScriptWtihJSScript:callback:], Line:59 >> GLOBAL['null#1']=(function(initProps){const global=this;return runCallback(function(mod){with(mod.imports){function _PageTwoState(){const inner=_PageTwoState.inner;if(this==global){return new _PageTwoState({args:arguments});}else{const args=arguments.length>0?arguments[0].args||arguments:[];inner.apply(this,args);_PageTwoState.prototype.ctor.apply(this,args);return this;}}_PageTwoState.inner=function inner(){this.fairProps=initProps;};_PageTwoState.prototype={initState:function initState(){const thiz=this;with(thiz){fairProps=widget.fairProps;}},getTitle:function getTitle(){const thiz=this;with(thiz){return fairProps.op_idx('title');}},};_PageTwoState.prototype.ctor=function(){Object.prototype.ctor.call(this);};;return _PageTwoState();}},[]);})(convertObjectLiteralToSetOrMap(JSON.parse('{"title":"PageTwo"}'))); [Fair]: File:FairJSBridge.m, Function:-[FairJSBridge context]_block_invoke, Line:220 >> exceptionValue:ReferenceError: Can't find variable: GLOBAL [Fair]:

环境信息

[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3 21E230 darwin-arm, locale zh-Hans-CN) • Flutter version 2.10.5 at /Users/xxx/fvm/versions/2.10.5 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5464c5bac7 (4 months ago), 2022-04-18 09:55:37 -0700 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn

提供Fair版本号

dependencies: fair: ^2.6.1

相关截图 WX20220810-112618

softAlexs avatar Aug 10 '22 03:08 softAlexs

routes 需要在 main.dart 里面注册,把下图注释去掉即可:

image

yancechen avatar Aug 10 '22 03:08 yancechen

这段注释已经取消,进入页面了

softAlexs avatar Aug 10 '22 03:08 softAlexs

看了下错误日志 似乎是报了exceptionValue:TypeError: undefined is not an object的错误,导致AppBar的text没有显示出来

softAlexs avatar Aug 10 '22 04:08 softAlexs

你是直接运行的 example 里的代码,没有改其他东西吧?

yancechen avatar Aug 10 '22 06:08 yancechen

我把page_two.dart拷贝到自己项目里面运行的

softAlexs avatar Aug 10 '22 06:08 softAlexs

1.代码直接拷贝应该没啥大问题,都是测试过的。

2.你拷贝代码之后,是自己运行 build_runner 命令重新生成的 bundle 文件,还是直接从 example 拷贝的 bundle 文件到你的项目中呢?

yancechen avatar Aug 10 '22 06:08 yancechen

运行build_runner 生成的bundle文件

softAlexs avatar Aug 10 '22 07:08 softAlexs

建议先执行 flutter clean 操作。

yancechen avatar Aug 17 '22 03:08 yancechen