276 lines
8.5 KiB
Dart
Executable File
276 lines
8.5 KiB
Dart
Executable File
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/app_settings/app_colors.dart';
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
|
import 'package:star_lock/main/lockMian/lockList/lockList_xhj_page.dart';
|
|
import 'package:star_lock/tools/noData.dart';
|
|
import 'package:star_lock/tools/submitBtn.dart';
|
|
|
|
import '../../../appRouters.dart';
|
|
import '../../../baseWidget.dart';
|
|
import '../../../flavors.dart';
|
|
import '../../../mine/mine/starLockMine_page.dart';
|
|
import '../../../tools/EasyRefreshTool.dart';
|
|
import '../../../tools/eventBusEventManage.dart';
|
|
import '../../../tools/storage.dart';
|
|
import '../../../tools/titleAppBar.dart';
|
|
import '../../../translations/trans_lib.dart';
|
|
import '../../lockDetail/lockDetail/lockDetail_page.dart';
|
|
import '../entity/lockListInfo_entity.dart';
|
|
import '../lockList/lockList_page.dart';
|
|
import 'lockMain_logic.dart';
|
|
|
|
class StarLockMainPage extends StatefulWidget {
|
|
StarLockMainPage({Key? key, this.showAppBar = true, this.showDrawer = true})
|
|
: super(key: key);
|
|
bool showAppBar;
|
|
bool showDrawer;
|
|
|
|
@override
|
|
State<StarLockMainPage> createState() => _StarLockMainPageState();
|
|
}
|
|
|
|
class _StarLockMainPageState extends State<StarLockMainPage> with BaseWidget {
|
|
final logic = Get.put(LockMainLogic());
|
|
final state = Get.find<LockMainLogic>().state;
|
|
|
|
Future<void> getHttpData(
|
|
{bool clearScanDevices = false, bool isUnShowLoading = false}) async {
|
|
LockListInfoGroupEntity? lockListInfoGroupEntity =
|
|
await Storage.getLockMainListData();
|
|
if (lockListInfoGroupEntity != null) {
|
|
var localLockListInfoGroupEntity = lockListInfoGroupEntity;
|
|
logic.loadMainDataLogic(localLockListInfoGroupEntity);
|
|
}
|
|
await logic.getStarLockInfo(isUnShowLoading: isUnShowLoading);
|
|
await Future.delayed(const Duration(milliseconds: 200));
|
|
if (clearScanDevices) {
|
|
BlueManage().scanDevices.clear();
|
|
}
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
setState(() {});
|
|
});
|
|
// if (mounted) {
|
|
// setSŒe(() {});
|
|
// }
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
logic.pageNo = 1;
|
|
getHttpData();
|
|
_initLoadDataAction();
|
|
setState(() {});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget child = EasyRefreshTool(
|
|
onRefresh: () {
|
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
|
// 更新状态的代码
|
|
logic.pageNo = 1;
|
|
getHttpData();
|
|
});
|
|
},
|
|
// child: getDataReturnUI(state.dataLength.value));
|
|
child: getDataReturnUI(state.dataLength.value));
|
|
if (widget.showAppBar || widget.showDrawer) {
|
|
child = Scaffold(
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
appBar: widget.showAppBar
|
|
? TitleAppBar(
|
|
barTitle: F.navTitle,
|
|
haveBack: false,
|
|
haveOtherLeftWidget: true,
|
|
leftWidget: Builder(
|
|
builder: (context) => IconButton(
|
|
icon: Image.asset(
|
|
'images/main/mainLeft_menu_icon.png',
|
|
color: Colors.white,
|
|
width: 44.w,
|
|
height: 44.w,
|
|
),
|
|
onPressed: () {
|
|
Scaffold.of(context).openDrawer();
|
|
},
|
|
)),
|
|
backgroundColor: AppColors.mainColor,
|
|
)
|
|
: null,
|
|
drawer: widget.showDrawer
|
|
? Drawer(
|
|
width: 1.sw / 3 * 2,
|
|
child: const StarLockMinePage(),
|
|
)
|
|
: null,
|
|
body: child,
|
|
);
|
|
}
|
|
child = F.sw(
|
|
skyCall: () => child,
|
|
xhjCall: () => Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('images/xhj_main_bg.jpg'),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
// decoration: BoxDecoration(
|
|
// // 设置渐变
|
|
// gradient: LinearGradient(
|
|
// // 渐变颜色列表
|
|
// colors: [
|
|
// AppColors.mainColor.withOpacity(0.8), // 左上角颜色
|
|
// AppColors.mainColor.withOpacity(0.4), // 右上角颜色
|
|
// Colors.white, // 右下角颜色
|
|
// Colors.white, // 左下角颜色
|
|
// ],
|
|
// // 渐变的起始和结束位置
|
|
// begin: Alignment.topLeft,
|
|
// end: Alignment.bottomRight,
|
|
// // 颜色停靠点,对应颜色数组的索引位置
|
|
// stops: [0.0, 0.23, 0.47, 1],
|
|
// ),
|
|
// ),
|
|
child: child,
|
|
));
|
|
return child;
|
|
}
|
|
|
|
Widget getDataReturnUI(int type) {
|
|
Widget returnWidget;
|
|
|
|
if (type == 1) {
|
|
type = F.sw(skyCall: () => 1, xhjCall: () => 2);
|
|
}
|
|
switch (type) {
|
|
case 0:
|
|
// 显示无数据模式
|
|
returnWidget = unHaveData();
|
|
break;
|
|
case 1:
|
|
// 只有一条数据
|
|
Storage.setBool(ifIsDemoModeOrNot, false);
|
|
returnWidget = LockDetailPage(
|
|
isOnlyOneData: true,
|
|
lockListInfoItemEntity:
|
|
state.lockListInfoGroupEntity.value.groupList![0].lockList![0]);
|
|
break;
|
|
case 2:
|
|
// 有多条数据
|
|
Storage.setBool(ifIsDemoModeOrNot, false);
|
|
returnWidget = F.sw(
|
|
skyCall: () => LockListPage(
|
|
lockListInfoGroupEntity: state.lockListInfoGroupEntity.value),
|
|
xhjCall: () => LockListXHJPage(
|
|
lockListInfoGroupEntity: state.lockListInfoGroupEntity.value));
|
|
break;
|
|
default:
|
|
returnWidget = NoData();
|
|
break;
|
|
}
|
|
return returnWidget;
|
|
}
|
|
|
|
//鑫泓佳背景
|
|
Widget XHJBg({required Widget child}) {
|
|
return Container();
|
|
}
|
|
|
|
Widget unHaveData() {
|
|
return ListView(
|
|
children: [
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
SizedBox(
|
|
height: 160.h,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
SizedBox(
|
|
width: 330.w,
|
|
child: InkWell(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(30.0),
|
|
child: Image.asset(
|
|
'images/main/icon_main_unHaveLockData.png',
|
|
width: 260.w,
|
|
height: 260.w,
|
|
),
|
|
),
|
|
onTap: () {
|
|
//实现回调函数
|
|
Navigator.pushNamed(
|
|
context,
|
|
Routers.selectLockTypePage,
|
|
);
|
|
},
|
|
)),
|
|
],
|
|
),
|
|
Container(
|
|
// padding: EdgeInsets.all(30.w),
|
|
child: Text(
|
|
TranslationLoader
|
|
.lanKeys!.whenAddingLockThePhoneMustBeNextToTheLock!.tr,
|
|
style: TextStyle(
|
|
fontSize: 26.sp,
|
|
// fontWeight: FontWeight.w800,
|
|
color: Colors.black),
|
|
)),
|
|
SizedBox(
|
|
height: 160.h,
|
|
),
|
|
if (F.isLite)
|
|
Container()
|
|
else
|
|
SubmitBtn(
|
|
btnName: '演示模式',
|
|
onClick: () {
|
|
Get.toNamed(Routers.demoModeLockDetailPage);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void onShow() {}
|
|
|
|
void onHide() {}
|
|
|
|
late StreamSubscription _teamEvent;
|
|
|
|
void _initLoadDataAction() {
|
|
_teamEvent = eventBus.on<RefreshLockListInfoDataEvent>().listen((event) {
|
|
logic.pageNo = 1;
|
|
getHttpData(
|
|
clearScanDevices: event.clearScanDevices,
|
|
isUnShowLoading: event.isUnShowLoading);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
super.dispose();
|
|
_teamEvent.cancel();
|
|
}
|
|
}
|