123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- 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:flutter/material.dart';
- import 'package:liftmanager/common/common.dart';
- import 'package:liftmanager/common/user_db.dart';
- import 'package:liftmanager/internal/heavy/heavy_router.dart';
- import 'package:liftmanager/internal/heavy/model/heavy_user_entity.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_bar.dart';
- import 'package:permission_handler/permission_handler.dart';
- class HeavySignPage extends StatefulWidget {
- HeavySignPage(this.projectId);
- String projectId;
- @override
- State<StatefulWidget> createState() {
- return HeavySignPageState();
- }
- }
- class HeavySignPageState extends State<HeavySignPage> {
- //计时器。
- Timer _timer;
- String _nowTimeStr = "";
- LatLng latLng = LatLng(0, 0);
- String currentAddress = "";
- List<HeavyUserEntity> list = [];
- BuildContext mContext;
- List<MarkerOption> _markers = [];
- AmapController _controller;
- Map<String, Object> _locationResult;
- StreamSubscription<Map<String, Object>> _locationListener;
- AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
- 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();
- mContext = context;
- _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 :');
- });
- });
- });
- startTime();
- getTodayList();
- getHasRole();
- getLocation();
- }
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- mContext.dependOnInheritedWidgetOfExactType();
- }
- Future<LatLng> getLocation() async {
- if (await requestPermission()) {
- if (null != _locationPlugin) {
- ///开始定位之前设置定位参数
- _setLocationOption();
- _locationPlugin.startLocation();
- }
- }
- return latLng;
- }
- bool noRole = true;
- getHasRole() async {
- var role = await User().getCompanyRole();
- if (role == Constant.RoleAdmin ||
- role == Constant.RoleRegion ||
- role == Constant.RoleWork) {
- noRole = false;
- setState(() {});
- }
- }
- 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 dispose() {
- _timer.cancel();
- if (null != _locationListener) {
- _locationListener.cancel();
- }
- ///销毁定位
- if (null != _locationPlugin) {
- _locationPlugin.destroy();
- }
- super.dispose();
- }
- getTodayList() {
- ApiService(context: context).heavyUserList(
- widget.projectId, true, DateTime.now().toString().split(" ")[0],
- onSuccess: (data) {
- list = data;
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- getSignAdd() {
- if (currentAddress.length == 0) {
- toasts("定位正在初始化,请重试。");
- return;
- }
- showLoading(context, "正在签到");
- ApiService(context: context).heavySignAdd(
- "${latLng.longitude},${latLng.latitude}",
- currentAddress,
- widget.projectId, onSuccess: (res) {
- dismissLoading(context);
- toasts("签到成功");
- getTodayList();
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- }
- 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,
- "${HeavyRouter.heavyUserPage}?id=" + widget.projectId);
- },
- )
- ],
- ),
- body: Container(
- 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: 345,
- child: Stack(
- children: <Widget>[
- AmapView(
- mapType: MapType.Standard,
- showZoomControl: false,
- zoomLevel: 17,
- maskDelay: Duration(milliseconds: 500),
- onMapCreated: (controller) async {
- _controller = controller;
- await _controller?.showMyLocation(MyLocationOption(
- myLocationType: MyLocationType.Locate,
- ));
- },
- ),
- // 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 {
- // _controller = controller;
- //// await getLocation();
- // if (Platform.isIOS) {
- // await getLocation();
- // setState(() {
- //
- // });
- // } else {
- // if (await requestPermission()) {
- // await _controller?.showMyLocation(MyLocationOption(
- // show: true,
- // ));
- // }
- // }
- // },
- // ),
- // BoxShadow(color: Colors.grey[300],offset: Offset(1, 1),
- // ///模糊阴影半径
- // blurRadius: 5,
- // )
- Positioned(
- right: 14,
- bottom: 19,
- child: Offstage(
- offstage: noRole,
- 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(
- color: ThemeUtils.getTabsBg(context),
- border: Border(
- bottom: BorderSide(width: 0.5, color: Colours.line),
- ),
- ),
- child: Text(
- "今日打卡记录",
- style: TextStyle(fontSize: 14, color: Color(0xFF333333)),
- ),
- ),
- ListView.separated(
- shrinkWrap: true,
- itemCount: list.length > 0 ? list[0].attendanceRecord.length : 0,
- separatorBuilder: (BuildContext context, int index) {
- return Container(
- height: 0.5,
- color: Color(0xFFF5F5F5),
- );
- },
- itemBuilder: (_, index) {
- return Container(
- color: ThemeUtils.getTabsBg(context),
- padding: const EdgeInsets.symmetric(
- horizontal: 15.0, vertical: 12.0),
- alignment: Alignment.centerLeft,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Text(
- "入场时间:${list[0].attendanceRecord[index].approachTime}"),
- Text(
- "离场时间:${list[0].attendanceRecord[index].leavingTime}"),
- // Text("时间:${list[index].createDate}"),
- // Text("地址:${list[index].address}"),
- // Text("状态:${list[index].statusDesc}")
- ],
- ),
- );
- },
- )
- ],
- ),
- ),
- );
- }
- }
|