import 'dart:async'; import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:liftmanager/internal/bbs/bbs_router.dart'; import 'package:liftmanager/internal/bbs/model/expert_model.dart'; import 'package:liftmanager/internal/bbs/presenter/expert_list_presenter.dart'; import 'package:liftmanager/internal/search/presenter/base_list_provider.dart'; import 'package:liftmanager/mvp/base_page_state.dart'; import 'package:liftmanager/net/api_service.dart'; import 'package:liftmanager/res/resources.dart'; import 'package:liftmanager/routers/fluro_navigator.dart'; import 'package:liftmanager/utils/theme_utils.dart'; import 'package:liftmanager/utils/toast.dart'; import 'package:liftmanager/widgets/app_search_bar.dart'; import 'package:liftmanager/widgets/load_image.dart'; import 'package:liftmanager/widgets/my_refresh_list.dart'; import 'package:liftmanager/widgets/star_item.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; int dataId; String dataTable; class ExpertList extends StatefulWidget { ExpertList(this.id); final String id; @override ExpertListState createState() => ExpertListState(); } class ExpertListState extends BasePageState { BaseListProvider provider = BaseListProvider(); // ExpertListState({Key key}) : super(key: key); AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin(); StreamSubscription> _locationListener; Map _locationResult; bool sortBool = true; String sortName = "排序"; int indexNowConst = 999999; String checkId = ""; int _page = 1; double apiExpertFee = 0.0; int sortNum = 0; List sortListChiose = ["采纳排序", "咨询人数", "评论星级", "距离优先"]; @override void initState() { super.initState(); ///移除定位监听 if (null != _locationListener) { _locationListener.cancel(); } ///销毁定位 if (null != _locationPlugin) { _locationPlugin.destroy(); } _locationListener = _locationPlugin .onLocationChanged() .listen((Map result) { setState(() { _locationPlugin.stopLocation(); _locationResult = result; // address latitude longitude lat = _locationResult["latitude"]; lng = _locationResult["longitude"]; _onRefresh(); // _locationResult.forEach((key, value) { // if(key == 'city'){ // cityName = '$value'; // setState(() { // }); // } // print(111); // print('key:$key :'); // print('value:$value :'); // }); }); }); getDataId(); getApiFee(); getType(); sortType = "adopt_counts"; _onRefresh(); } Future getApiFee() async { await NewApiService().getFee(onSuccess: (res) { if (res != null) { apiExpertFee = res; setExpertFee(apiExpertFee); setState(() {}); print(res); print(6666544); } }, onError: (code, msg) { toasts(msg); }); } void setExpertFee(double expertFee) async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setDouble("expertFee", expertFee); } void getDataId() async { SharedPreferences prefs = await SharedPreferences.getInstance(); dataId = prefs.getInt("dataId"); } void getType() async { SharedPreferences prefs = await SharedPreferences.getInstance(); dataTable = prefs.getString("questionType"); } // 绑定专家 void generateRoom(expertId) { NewApiService().generateRoom({ "id": dataId, "chargerId": expertId, }, onSuccess: (res) { getRoom(); }, onError: (code, msg) { toasts(msg); }); } //用诊单Id获取房间号 Future getRoom() async { await NewApiService().findOne(dataId, onSuccess: (res) { print(res); String roomId = res.sessionid; toasts("即将进入聊天室!"); NavigatorUtils.push(context, "${BbsRouter.chatRoom}?id=$roomId&type=someToOne&toUserId=''"); // toasts("欢迎使用,请在使用过程中注意个人信息及财产安全!"); print(666); }, onError: (code, msg) { toasts(msg); }); } ///获取定位权限 Future requestPermission() async { final permissions = await PermissionHandler() .requestPermissions([PermissionGroup.location]); if (permissions[PermissionGroup.location] == PermissionStatus.granted) { return true; } else { toasts('需要定位权限!'); return false; } } double lat; double lng; ///获取位置信息 getLocation() async { if (await requestPermission()) { // final location = await AmapLocation.fetchLocation(); // LatLng latlng = await location.latLng; // print(latlng.latitude); // print(latlng.longitude); // print(latlng); // lat = latlng.latitude; // lng = latlng.longitude; // _onRefresh(); if (null != _locationPlugin) { _locationPlugin.startLocation(); } } } @override void dispose() { ///移除定位监听 if (null != _locationListener) { _locationListener.cancel(); } ///销毁定位 if (null != _locationPlugin) { _locationPlugin.destroy(); } super.dispose(); } String sortType = "create_time"; @override Widget build(BuildContext context) { double width = MediaQuery.of(context).size.width; double height = MediaQuery.of(context).size.height; return Container( child: ChangeNotifierProvider>( create: (_) => provider, child: Scaffold( appBar: SearchAppBar2( backgroundColor: Colors.white, onPressed: (text) { //搜索逻辑未能实现 // title = text; // getBrandList(); }, ), body: Container( child: Stack( children: [ Column( children: [ Container( height: ScreenUtil().setWidth(140), ), Expanded( flex: 1, child: Consumer>( builder: (_, provider, __) { return MyListView( key: Key('expert_list'), pageSize: 10, itemCount: provider.list.length, stateType: provider.stateType, onRefresh: _onRefresh, loadMore: _loadMore, hasMore: provider.hasMore, itemBuilder: (_, index) { return ExpertListWidget( changeState: (params, id) { setState(() { indexNowConst = params; checkId = id; if (dataTable != "2") { NavigatorUtils.push(context, "${BbsRouter.expertDetail}?id=$checkId"); } else { // 绑定专家 generateRoom(checkId); } }); }, indexNow: indexNowConst, checkIdConst: checkId, item: provider.list[index], index: index); }, ); })) ], ), !sortBool ? Positioned( top: ScreenUtil().setWidth(140), left: 0, child: GestureDetector( onTap: () { setState(() { sortBool = true; }); }, child: Container( width: width, height: height, color: Color.fromRGBO(0, 0, 0, 0.5)), )) : Container(child: null), Positioned( top: 0, left: 0, child: GestureDetector( onTap: () async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.remove("expertName"); prefs.remove("expertFee"); if (dataTable != "2") { NavigatorUtils.push( context, "${BbsRouter.buyService}?id="); } else { // 绑定专家 generateRoom(null); } }, child: Container( width: width, height: ScreenUtil().setWidth(70), decoration: BoxDecoration( border: Border( bottom: BorderSide(width: 0.5, color: Colours.line), ), ), padding: EdgeInsets.only( left: ScreenUtil().setWidth(15), right: ScreenUtil().setWidth(15)), child: Row(children: [ Container( padding: EdgeInsets.only(right: ScreenUtil().setWidth(10)), child: LoadAssetImage( // image: AssetImage(i['img']), "tab_first/zhiding", width: ScreenUtil().setWidth(36), height: ScreenUtil().setWidth(36), // alignment: Alignment.centerLeft, ), ), Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Row( children: [ Text( "平台指定专家", style: TextStyle( fontSize: ScreenUtil().setSp(14)), textAlign: TextAlign.start, ), Text( dataTable != "2" ? "¥$apiExpertFee" : "", style: TextStyle( color: Color(0xffff0000), fontSize: ScreenUtil().setSp(14)), textAlign: TextAlign.start, ), ], ), SizedBox(height: 5), Text( "平台根据问题和品牌自动指定优质专家", style: TextStyle( color: Color(0xff999999), fontSize: ScreenUtil().setSp(14)), textAlign: TextAlign.start, ), ], ), ), Expanded(child: Container()), Icon( Icons.arrow_forward_ios, size: 13, color: Color(0xffcccccc), ) ]), ), ), ), Positioned( left: 0, top: ScreenUtil().setWidth(70), child: Container( padding: EdgeInsets.symmetric(horizontal: 0), child: Container( width: width, height: ScreenUtil().setWidth(70), decoration: BoxDecoration( border: Border( bottom: BorderSide(width: 0.5, color: Colours.line), ), ), padding: EdgeInsets.only( // left: ScreenUtil().setWidth(15), right: ScreenUtil().setWidth(15)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: Row(children: [ // Container( // padding: EdgeInsets.only( // right: ScreenUtil().setWidth(10)), // child: LoadAssetImage( // // image: AssetImage(i['img']), // "tab_first/tuijian", // width: ScreenUtil().setWidth(36), // height: ScreenUtil().setWidth(36), // // alignment: Alignment.centerLeft, // ), // ), Container( // margin: EdgeInsets.only( // top: ScreenUtil().setHeight(0)), width: ScreenUtil().setWidth(2), height: ScreenUtil().setHeight(13), color: Color(0xFF568AFF), ), SizedBox( width: 5, ), Text( "系统推荐专家", style: TextStyle( fontSize: ScreenUtil().setSp(15), fontWeight: FontWeight.w400), textAlign: TextAlign.start, ), ]), ), GestureDetector( onTap: () { print("7898"); setState(() { sortBool = !sortBool; }); }, child: sortBool ? Container( child: Row(children: [ Text( '排序', style: TextStyle( fontSize: ScreenUtil().setSp(15), color: Color(0xff999999)), textAlign: TextAlign.start, ), Container( padding: EdgeInsets.only(top: 3), child: Icon( Icons.keyboard_arrow_down, size: 26.0, color: Color(0xffcccccc), ), ) ]), ) : Container( child: Row(children: [ Text( '排序', style: TextStyle( color: Color(0xff01A4FF), fontSize: ScreenUtil().setSp(15)), textAlign: TextAlign.start, ), Container( padding: EdgeInsets.only(top: 3), child: Icon( Icons.keyboard_arrow_up, size: 26.0, color: Color(0xff01A4FF), ), ) ]), ), ), ], )), )), !sortBool ? Positioned( top: ScreenUtil().setWidth(140), left: 0, child: Container( width: width, color: Colors.white, padding: EdgeInsets.only( left: ScreenUtil().setWidth(15), right: ScreenUtil().setWidth(15), bottom: ScreenUtil().setWidth(10)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: sortListChiose.asMap().keys.map((index) { return InkWell( onTap: () { print("666"); setState(() { sortBool = true; sortName = sortListChiose[index]; if (index == 0) { sortNum = 0; lat = null; lng = null; sortType = "adopt_counts"; _onRefresh(); } else if (index == 1) { sortNum = 1; lat = null; lng = null; sortType = "service_counts"; _onRefresh(); } else if (index == 2) { sortNum = 2; lat = null; lng = null; sortType = "average_score"; _onRefresh(); } else if (index == 3) { sortNum = 3; getLocation(); } indexNowConst = 99999; checkId = ""; }); }, child: Container( width: width, padding: EdgeInsets.only( bottom: ScreenUtil().setWidth(10), top: ScreenUtil().setWidth(5)), decoration: BoxDecoration( border: Border( bottom: BorderSide( width: 0.5, color: Colours.line), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( sortListChiose[index], style: TextStyle( color: Color(0xff666666), fontSize: ScreenUtil().setSp(13)), textAlign: TextAlign.start, ), sortNum == index ? LoadAssetImage('icon_type_Select', fit: BoxFit.fill) // Icon( // const IconData(0xe6de, // fontFamily: "Iconfont"), // color: Colours.blue_app_main, // ) // Text( // "√", // style: TextStyle( // color: sortNum == index // ? Colours.blue_app_main // : Colors.transparent, // fontSize: // ScreenUtil().setSp(20)), // textAlign: TextAlign.start, // ) : Container( child: null, ), ], )), ); }).toList(), ))) : Container(child: null), ], ))), )); } Future _onRefresh() async { _page = 1; await presenter.getExpertList( _page, sortType, int.parse(widget.id), lat, lng); // await presenter.getExpertList(_page,sortType,int.parse(widget.id)); } Future _loadMore() async { _page++; await presenter.getExpertList( _page, sortType, int.parse(widget.id), lat, lng); } @override ExpertListPresenter createPresenter() { return ExpertListPresenter(); } } class ExpertListWidget extends StatelessWidget { ExpertListWidget( {Key key, this.changeState, this.indexNow, this.checkIdConst, this.item, this.index}) : super(key: key); int indexNow; String checkFalse = "tab_first/check_false"; String checkTrue = "tab_first/check_true"; String checkIdConst; Function changeState; dynamic item; int index; getLevel(level) { String img; if (level == 1) { img = "L1@2x"; } else if (level == 2) { img = "L2@2x"; } else if (level == 3) { img = "L3@2x"; } else if (level == 4) { img = "L4@2x"; } else if (level == 5) { img = "L5@2x"; } return img; } @override Widget build(BuildContext context) { double width = MediaQuery.of(context).size.width; return InkWell( onTap: () { changeState(index, item.userId.toString()); print(indexNow); print(66663); print(item.userId); }, child: Container( // height: 20, padding: EdgeInsets.only( bottom: ScreenUtil().setWidth(8), top: ScreenUtil().setWidth(10)), margin: EdgeInsets.only(left: ScreenUtil().setWidth(10)), decoration: BoxDecoration( border: Border( bottom: BorderSide(width: 0.5, color: Colours.line), ), ), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Container( // padding: EdgeInsets.only( // top: ScreenUtil().setWidth(10), // left: ScreenUtil().setWidth(5), // right: ScreenUtil().setWidth(5), // bottom: ScreenUtil().setWidth(10)), // child: LoadAssetImage( // // image: AssetImage(i['img']), // indexNow == index ? checkTrue : checkFalse, // width: ScreenUtil().setWidth(20), // height: ScreenUtil().setWidth(20), // // alignment: Alignment.centerLeft, // ), // ), Expanded( child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: < Widget>[ Container( margin: EdgeInsets.only( left: ScreenUtil().setWidth(5), right: ScreenUtil().setWidth(10), top: ScreenUtil().setWidth(5)), decoration: BoxDecoration( borderRadius: BorderRadius.circular(ScreenUtil().setWidth(27)), ), child: Container( width: ScreenUtil().setWidth(50), height: ScreenUtil().setWidth(70), child: Stack( children: [ Container( padding: EdgeInsets.only(left: ScreenUtil().setWidth(3)), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(50)), child: LoadNetworkImage( // image: AssetImage(i['img']), item.avatarUrl, width: ScreenUtil().setWidth(44), height: ScreenUtil().setWidth(44), // alignment: Alignment.centerLeft, ), ), ), // Positioned( // top:ScreenUtil().setWidth(34), // left: 0, // child: LoadAssetImage( // // image: AssetImage(i['img']), // getLevel(item.expertLevel), // width: ScreenUtil().setWidth(50), // height: ScreenUtil().setWidth(13), // // alignment: Alignment.centerLeft, // ), // ) ], ), )), Expanded( child: Container( padding: EdgeInsets.only(right: ScreenUtil().setWidth(15)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: width * 0.3, // width: width * 0.2, child: Text( item.name ?? "", style: TextStyle( fontSize: ScreenUtil().setSp(18)), textAlign: TextAlign.start, maxLines: 1, overflow: TextOverflow.ellipsis, ), ), // Container( // padding: EdgeInsets.only(left: 5,right:5), // width: width * 0.2, // child: Text( // item.proficiencyBrandName ?? "", // style: TextStyle( // color: Color(0xff666666), // fontSize: // ScreenUtil().setSp(14)), // textAlign: TextAlign.start, // maxLines: 1, // overflow: TextOverflow.ellipsis, // ), // ), // item.platformInvitedFlag==0?Container( // padding:EdgeInsets.only(left:5,right:5), // margin: EdgeInsets.only(right:5), // // color:Colors.red, // decoration: BoxDecoration( // borderRadius: BorderRadius.circular(1.0), // border: Border.all( // width:0.5, // color:Color(0xffB0E2FF), // ), // ), // child:Text( // "特邀专家", // style: TextStyle( // color:Color(0xff01A7FF), // fontSize:ScreenUtil().setSp(12) // ), // textAlign:TextAlign.center, // ), // ):Container(child: null,) ]), // Container( // child: Text( // "${item.averageScore ?? 0}分", // style: TextStyle( // color: Colors.red, // fontSize: ScreenUtil().setSp(14)), // textAlign: TextAlign.end, // ), // ) StarItemShow( starRating: item.averageScore != null ? double.parse( item.averageScore.toString()) : 0.0, ), ])), Container( child: Text( "擅长品牌:" + (item.proficiencyBrandName ?? ''), // "擅长:"+(item.proficiency ?? ''), style: TextStyle( color: Color(0xff999999), fontSize: ScreenUtil().setSp(14)), textAlign: TextAlign.start, maxLines: 1, overflow: TextOverflow.ellipsis, ), ), item.platformInvitedFlag == 0 ? Container( padding: EdgeInsets.only(left: 5, right: 5), margin: EdgeInsets.only(right: 5, top: 5), // color:Colors.red, decoration: BoxDecoration( borderRadius: BorderRadius.circular(1.0), border: Border.all( width: 0.5, color: Color(0xffB0E2FF), ), ), child: Text( "特邀专家", style: TextStyle( color: Color(0xff01A7FF), fontSize: ScreenUtil().setSp(12)), textAlign: TextAlign.center, ), ) : Container( child: null, ), Container( margin: EdgeInsets.only(top: 6), padding: EdgeInsets.only(top: 6), decoration: BoxDecoration( border: Border( top: BorderSide( width: 0.5, color: Colours.line), ), ), child: Row(children: [ Container( padding: EdgeInsets.only(right: 5), child: Text( dataTable != "2" ? "¥${item.serviceFee ?? 0}" : "", style: TextStyle( color: Colors.red, fontSize: ScreenUtil().setSp(16)), textAlign: TextAlign.start, ), ), Container( child: Text( "服务次数${item.serviceCounts ?? 0}", style: TextStyle( color: Color(0xff666666), fontSize: ScreenUtil().setSp(14)), textAlign: TextAlign.start, ), ) ])) ], ))) ]), ), ], ), ), ); } }