123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- import 'dart:async';
- import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
- import 'package:amap_location_flutter_plugin/amap_location_option.dart';
- import 'package:amap_map_fluttify/amap_map_fluttify.dart';
- // import 'package:flustars/flustars.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:liftmanager/internal/sign/model/sign_config_item.dart';
- import 'package:liftmanager/internal/sign/model/sign_list_entity.dart';
- import 'package:liftmanager/internal/sign/sign_router.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/toast.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:permission_handler/permission_handler.dart';
- class SignPage extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- return SignPageState();
- }
- }
- class SignPageState extends State<SignPage> {
- Map<String, Object> _locationResult;
- StreamSubscription<Map<String, Object>> _locationListener;
- AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
- //计时器。
- Timer _timer;
- String _nowTimeStr = "";
- LatLng latLng = LatLng(0, 0);
- String currentAddress = "";
- SignConfigItem configItem = SignConfigItem();
- List<SignListItem> list = [];
- BuildContext mContext;
- AmapController _controller;
- startTime() async {
- _timer = Timer.periodic(Duration(seconds: 1), (timer) {
- if (!mounted) return;
- setState(() {
- _nowTimeStr = DateTime.now().toString().split(" ")[1].split(".")[0];
- });
- });
- }
- @override
- void initState() {
- super.initState();
- _locationListener = _locationPlugin
- .onLocationChanged()
- .listen((Map<String, Object> result) {
- setState(() {
- _locationPlugin.stopLocation();
- _locationResult = result;
- // address latitude longitude
- _locationResult.forEach((key, value) {
- if (key == 'address') {
- currentAddress = '$value';
- setState(() {});
- } else if (key == 'latitude') {
- latLng.latitude = double.parse('$value');
- setState(() {});
- } else if (key == 'longitude') {
- latLng.longitude = double.parse('$value');
- setState(() {});
- }
- print(111);
- print('key:$key :');
- print('value:$value :');
- });
- });
- });
- mContext = context;
- startTime();
- getSignConfig();
- getTodayList();
- getLocation();
- }
- void _setLocationOption() {
- if (null != _locationPlugin) {
- AMapLocationOption locationOption = new AMapLocationOption();
- ///是否单次定位
- locationOption.onceLocation = true;
- ///是否需要返回逆地理信息
- locationOption.needAddress = true;
- ///逆地理信息的语言类型
- locationOption.geoLanguage = GeoLanguage.DEFAULT;
- ///设置Android端连续定位的定位间隔
- locationOption.locationInterval = 20000;
- ///设置Android端的定位模式<br>
- ///可选值:<br>
- ///<li>[AMapLocationMode.Battery_Saving]</li>
- ///<li>[AMapLocationMode.Device_Sensors]</li>
- ///<li>[AMapLocationMode.Hight_Accuracy]</li>
- locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
- ///设置iOS端的定位最小更新距离<br>
- locationOption.distanceFilter = -1;
- ///设置iOS端期望的定位精度
- /// 可选值:<br>
- /// <li>[DesiredAccuracy.Best] 最高精度</li>
- /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
- /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
- /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
- /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
- locationOption.desiredAccuracy = DesiredAccuracy.NearestTenMeters;
- ///设置iOS端是否允许系统暂停定位
- locationOption.pausesLocationUpdatesAutomatically = false;
- ///将定位参数设置给定位插件
- _locationPlugin.setLocationOption(locationOption);
- }
- }
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- mContext.dependOnInheritedWidgetOfExactType();
- }
- getLocation() async {
- if (await requestPermission()) {
- if (null != _locationPlugin) {
- ///开始定位之前设置定位参数
- _setLocationOption();
- _locationPlugin.startLocation();
- }
- }
- }
- @override
- void dispose() {
- _timer.cancel();
- if (null != _locationListener) {
- _locationListener.cancel();
- }
- ///销毁定位
- if (null != _locationPlugin) {
- _locationPlugin.destroy();
- }
- super.dispose();
- }
- getSignConfig() {
- ApiService(context: context).signConfig(
- onSuccess: (res) {
- configItem = res;
- setState(() {});
- },
- onError: (code, msg) {});
- }
- getTodayList() {
- ApiService(context: context).signList(
- 1, 10, DateTime.now().toString().split(" ")[0], onSuccess: (data) {
- list = data.rows;
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- getSignAdd() {
- if (configItem.topTime.length == 0) {
- toasts("未设置打卡");
- return;
- }
- if (currentAddress.length == 0) {
- toasts("定位正在初始化,请重试。");
- return;
- }
- NavigatorUtils.pushResult(context,
- "${SignRouter.signAddPage}?address=${Uri.encodeComponent(currentAddress)}&coordinate=${latLng.longitude},${latLng.latitude}&toptime=${configItem.topTime}&downtime=${configItem.downTime}&toptimepm=${configItem.topTimePm}&downtimepm=${configItem.downTimePm}&toptimeot=${configItem.topTimeOt}&downtimeot=${configItem.downTimeOt}",
- (res) {
- getTodayList();
- });
- }
- Future<bool> requestPermission() async {
- final permissions = await PermissionHandler()
- .requestPermissions([PermissionGroup.location]);
- if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
- // toasts("已经定位.");
- return true;
- } else {
- toasts('需要定位权限!');
- return false;
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: MyAppBar(
- centerTitle: "考勤",
- actions: <Widget>[
- FlatButton(
- child: Text("考勤记录", key: const Key('actionName')),
- textColor: Colours.text,
- highlightColor: Colors.transparent,
- onPressed: () {
- NavigatorUtils.push(context, SignRouter.signListPage);
- },
- )
- ],
- ),
- body: Container(
- color: Colors.white,
- child: Column(
- children: <Widget>[
- // Container(
- // color: ThemeUtils.getTabsBg(context),
- // padding: EdgeInsets.fromLTRB(15, 10, 15, 10),
- // child: Row(
- // children: <Widget>[
- // Expanded(
- // flex: 1,
- // child: Text(
- // "当前位置:${currentAddress ?? ''}",
- // maxLines: 1,
- // overflow: TextOverflow.ellipsis,
- // ),
- // )
- // ],
- // )),
- Container(
- height: ScreenUtil().setHeight(250),
- child: Stack(
- children: <Widget>[
- AmapView(
- mapType: MapType.Standard,
- showZoomControl: false,
- centerCoordinate: latLng,
- zoomLevel: 17,
- maskDelay: Duration(milliseconds: 500),
- onMapCreated: (controller) async {
- _controller = controller;
- await _controller?.showMyLocation(MyLocationOption(
- myLocationType: MyLocationType.Locate,
- ));
- },
- ),
- Positioned(
- top: ScreenUtil().setHeight(140),
- left: ScreenUtil().setWidth(130),
- child:
- ClipRRect(
- borderRadius: BorderRadius.circular(4),
- child: Container(
- width: ScreenUtil().setWidth(222),
- padding: EdgeInsets.all(5),
- color: Colours.blue_app_main,
- child:Text(
- " 当前位置:${currentAddress ?? ''} ",
- style: TextStyle(color: Colors.white),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ), ),
- )
-
- )
- // AmapView(
- // mapType: MapType.Standard,
- // // 是否显示缩放控件
- // showZoomControl: false,
- // // 是否显示指南针控件
- // showCompass: false,
- // // 是否显示比例尺控件
- // showScaleControl: false,
- // // 是否使能缩放手势
- // zoomGesturesEnabled: true,
- // // 是否使能滚动手势
- // scrollGesturesEnabled: true,
- // // 是否使能旋转手势
- // rotateGestureEnabled: true,
- // // 是否使能倾斜手势
- // tiltGestureEnabled: true,
- // // 缩放级别
- // zoomLevel: 18,
- //// markers: _markers,
- // // 中心点坐标
- // centerCoordinate: latLng,
- // // 标记
- // onMapCreated: (controller) async {
- // if (await requestPermission()) {
- // await controller.showMyLocation(MyLocationOption(show: true));
- // }
- //// await getLocation();
- //// _markers = [
- //// MarkerOption(
- //// title: "我的位置",
- //// latLng: latLng,
- //// iconUri: _assetsIcon,
- //// imageConfig:
- //// createLocalImageConfiguration(mContext),
- //// width: 28,
- //// height: 28)
- //// ];
- //// controller.setCenterCoordinate(latLng);
- //// controller.showMyLocation(MyLocationOption());
- //// setState(() {});
- // },
- // ),
- // BoxShadow(color: Colors.grey[300],offset: Offset(1, 1),
- // ///模糊阴影半径
- // blurRadius: 5,
- // )
- // Positioned(
- // right: 14,
- // bottom: 19,
- // child: GestureDetector(
- // onTap: () {
- // getSignAdd();
- // },
- // child: Container(
- // height: 75,
- // width: 75,
- // decoration: BoxDecoration(
- // color: Colours.app_main,
- // boxShadow: [
- // ///阴影颜色/位置/大小等
- // BoxShadow(
- // color: Colors.grey[300], offset: Offset(1, 1),
- // ///模糊阴影半径
- // blurRadius: 5,
- // ),
- // BoxShadow(
- // color: Colors.grey[300],
- // offset: Offset(-1, -1),
- // blurRadius: 5),
- // BoxShadow(
- // color: Colors.grey[300],
- // offset: Offset(1, -1),
- // blurRadius: 5),
- // BoxShadow(
- // color: Colors.grey[300],
- // offset: Offset(-1, 1),
- // blurRadius: 5)
- // ],
- // borderRadius: BorderRadius.circular(73)),
- // child: Column(
- // mainAxisAlignment: MainAxisAlignment.center,
- // children: <Widget>[
- // Text(
- // "打卡",
- // style: TextStyle(
- // fontSize: 13,
- // fontWeight: FontWeight.w500,
- // color: Colors.white),
- // ),
- // Text("${_nowTimeStr}",
- // style: TextStyle(
- // fontSize: 13,
- // fontWeight: FontWeight.w500,
- // color: Colors.white))
- // ],
- // ),
- // ),
- // ),
- // ),
- ],
- )),
- Container(
- // padding: EdgeInsets.only(left: 10),
- alignment: Alignment.centerLeft,
- height: 45,
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(width: 0.5, color: Colours.line),
- ),
- ),
- child:Row(
- children: [
- Container(
- // margin: EdgeInsets.only(left: 10),
- height:13 ,width: 2,color: Colours.blue_app_main,),
- SizedBox(width: 10,),
-
- Text(
- "今日打卡记录",
- style: TextStyle(fontSize: 14, color: Colours.text),
- ),
- ],
- )
-
- ),
- Expanded(
- flex: 1,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- list.length>0? Container(
- color: Colors.white,
- padding: const EdgeInsets.symmetric(
- horizontal: 15.0, vertical: 12.0),
- alignment: Alignment.centerLeft,
- child: RichText(
- text: TextSpan(
- // style: DefaultTextStyle.of(context).style,
- children: <InlineSpan>[
- TextSpan(
- text: '${list[0].createDate}',
- style: TextStyle(color: Colours.text)),
- TextSpan(text: ' ${list[0].typeDesc}',
- style: TextStyle(color: Colours.blue_app_main)
- ),
- ])),
- ):Container(),
- list.length > 1
- ? Container(
- height: 22,
- width: 2,
- color: Colours.new_dark_line,
- margin: EdgeInsets.only(left: 90),
- )
- : Container(),
- list.length > 1
- ? Container(
- color: Colors.white,
- padding: const EdgeInsets.symmetric(
- horizontal: 15.0, vertical: 12.0),
- alignment: Alignment.centerLeft,
- child: Text(
- "${list[1].createDate} ${list[1].typeDesc}",
- style: TextStyle(color: Colours.text_gray),
- ),
- )
- : Container()
- ],
- )
- // ListView.separated(
- // shrinkWrap: true,
- // itemCount: list.length,
- // separatorBuilder: (BuildContext context, int index) {
- // return Container(
- // height: 0.5,
- // color: Color(0xFFF5F5F5),
- // );
- // },
- // itemBuilder: (_, index) {
- // return Container(
- // color: Colors.white,
- // padding: const EdgeInsets.symmetric(
- // horizontal: 15.0, vertical: 12.0),
- // alignment: Alignment.centerLeft,
- // child: Row(
- // children: [
- // Text("${list[index].createDate} ${list[index].typeDesc}"),
- // ],
- // )
- // // Column(
- // // crossAxisAlignment: CrossAxisAlignment.start,
- // // mainAxisAlignment: MainAxisAlignment.start,
- // // children: <Widget>[
- // // // Text("类型:${list[index].typeDesc}"),
- // // // Text("时间:${list[index].createDate}"),
- // // // Text("地址:${list[index].address}"),
- // // // Text("状态:${list[index].statusDesc}")
- // // ],
- // // ),
- // );
- // },
- // )
- ),
- GestureDetector(
- onTap: () {
- getSignAdd();
- },
- child: Container(
- height: 110,
- width: 110,
- decoration: BoxDecoration(
- color: Colours.blue_app_main,
- boxShadow: [
- ///阴影颜色/位置/大小等
- BoxShadow(
- color: Colors.grey[300], offset: Offset(1, 1),
- ///模糊阴影半径
- blurRadius: 5,
- ),
- BoxShadow(
- color: Colors.grey[300],
- offset: Offset(-1, -1),
- blurRadius: 5),
- BoxShadow(
- color: Colors.grey[300],
- offset: Offset(1, -1),
- blurRadius: 5),
- BoxShadow(
- color: Colors.grey[300],
- offset: Offset(-1, 1),
- blurRadius: 5)
- ],
- borderRadius: BorderRadius.circular(73)),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text("${_nowTimeStr}",
- style: TextStyle(
- fontSize: 22,
- fontWeight: FontWeight.w500,
- color: Colors.white)),
- Text(
- "打卡",
- style: TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.w500,
- color: Colors.white),
- ),
- ],
- ),
- ),
- ),
- SizedBox(
- height: ScreenUtil().setHeight(30),
- )
- ],
- ),
- ),
- );
- }
- }
|