import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; import '../../../tools/titleAppBar.dart'; import '../../../translations/trans_lib.dart'; import 'nearbyLock_logic.dart'; class NearbyLockPage extends StatefulWidget { const NearbyLockPage({Key? key}) : super(key: key); @override State createState() => _NearbyLockPageState(); } class _NearbyLockPageState extends State { final logic = Get.put(NearbyLockLogic()); final state = Get.find().state; @override void initState() { // TODO: implement initState super.initState(); print("NearbyLockLogic initState()"); } @override Widget build(BuildContext context) { print("NearbyLockLogic build()"); return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: TranslationLoader.lanKeys!.nearbyLock!.tr, haveBack: true, backgroundColor: AppColors.mainColor, actionsList: [ CupertinoActivityIndicator(radius: 18.w, color: Colors.white,), SizedBox(width: 30.w) ], ), body: Obx(() { return ListView.separated( itemCount: state.devices.length, itemBuilder: (c, index) { return nearbyLockItem('images/icon_lockGroup_item.png', state.devices[index], () { // Navigator.pushNamed(context, Routers.lockAddressPage); // logic.getPublicKey(state.devices[index].serviceUuids[0].toString()); state.seletLockName.value = state.devices[index].name; // print("connect-lockId:${state.devices[index].id} deviceName:${state.devices[index].name}"); logic.connect(state.devices[index].id, state.devices[index].name); // Get.toNamed(Routers.lockAddressGaoDePage); }); }, separatorBuilder: (BuildContext context, int index) { return Divider( height: 1, color: AppColors.greyLineColor, indent: 20.w, endIndent: 0, ); }, ); }), ); } Widget nearbyLockItem(String lockTypeIcon, DiscoveredDevice discoveredDevice, Function() action ) { return GestureDetector( onTap: ((discoveredDevice.serviceUuids.isNotEmpty ? discoveredDevice.serviceUuids[0] : "").toString()[33] == "1") ? action : null, child: Column( // mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 89.h, width: 1.sw, color: Colors.white, child: Row( children: [ SizedBox(width: 20.w), Image.asset( lockTypeIcon, width: 56.w, height: 56.w, ), SizedBox(width: 20.w), Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 第32、33两位00 表示休眠, 01表示唤醒 Text(discoveredDevice.name, style: TextStyle(fontSize: 20.sp, color: ((discoveredDevice.serviceUuids.isNotEmpty ? discoveredDevice.serviceUuids[0] : "").toString()[33] == "1") ? AppColors.blackColor : Colors.grey)), ], ), SizedBox( width: 10.w, ), Image.asset( "images/mine/icon_mine_main_about.png", width: 22.w, height: 22.w, ), Expanded(child: SizedBox(width: 20.w)), Image.asset( 'images/main/icon_main_addLock.png', width: 36.w, height: 36.w, ), SizedBox(width: 30.w), ], ), ), ], ), ); } @override void dispose() { // TODO: implement dispose super.dispose(); } }