dart - 我如何连接两个字符串,其中一个字符串需要是颤动中小部件的静态变量
问题描述
我有来自有状态小部件的这段代码,它看起来像
static String code = '+1';
String phone;
String finalphone = '$code' + '$phone'; =>this declaration brings an error
that 'Only static members can be accessed in initializers'
我应该如何将这两个变量放在一起,以便我有一些看起来像是+1535465345
在收集用户信息的东西
//the widget
Widget form() {
return Form(
key: _formKey,
child: TextFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0.0),
),
style: TextStyle(
letterSpacing: 2.0,
fontSize: 19.0,
fontWeight: FontWeight.bold,
color: Colors.black87),
onSaved: (value) => phone = value, //the (value) here is a
//string which is
//assigned
//to phone variable declared at the top
),
),
);
}
还使电话变量静态并打印出连接的字符串带出+1null
解决方案
推荐阅读
- reactjs - React Router + 页面动画 + 模块化
- javascript - 更改显示属性会使不透明度过渡无效
- python - Python:如何在没有索引的情况下访问列表中的字典元素?
- javascript - 如何从自定义创建的 SVG 创建一个简单的代码,该代码可以放置在其他网站上
- c# - c#如何检测Netflix是否正在运行
- ios - NavigationController 中的视图之间的分隔无法正常工作
- python - Pandas 拆分列并聚合结果与索引中的重复项
- excel - 编写此代码的更短的方法是什么?
- php - 如何计算另一个表中的子数据并显示在父表中?
- python - 尝试为 Python 传递 C 代码,总线出现错误 IndexError: list assignment index out of range