city_selecter.dart
import 'package:city_pickers/city_pickers.dart';
import 'package:flutter/material.dart';
class CitySelecter extends StatefulWidget{
final Function callback;
const CitySelecter({Key? key, required this.callback}) : super(key: key);
@override
State<StatefulWidget> createState() => _state();
}
class _state extends State<CitySelecter>{
String text = "请选择";
// Result result;
Result result = Result();
show(BuildContext context, Function onClick) async {
Result? tempResult = await CityPickers.showCitiesSelector(
context: context,
hotCities: [
HotCity(id: 110100, name: '北京'),
HotCity(id: 310100, name: '上海'),
HotCity(id: 440100, name: '广洲'),
HotCity(id: 440300, name: '深圳'),
],);
if (tempResult == null) {
return;
}
onClick(tempResult);
// return tempResult;
}
@override
Widget build(BuildContext context) {
// print(list);
// TODO: implement build
return InkWell(
onTap: (){
show(context, (e)=>{
// print(e)
setState(() {
result = e;
});
widget.callback(e);
});
},
child: Row(
children: [
Text(result.cityName??text, style: const TextStyle(fontSize: 14),),
const Icon(Icons.arrow_forward_ios, size: 16,)
],
),
);
}
}
报错如图,应该是一个语法错误,但我尝试去除 ; ,则下一行又报错,我在其它地方有类似的写法,但并没有报错
下面是同样类型语法的地方,但未报错。
去掉 => 号