我的界面 修改昵称完成
This commit is contained in:
48
lib/features/my/presentation/bloc/my_cubit.dart
Normal file
48
lib/features/my/presentation/bloc/my_cubit.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/unbind_device_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/repository/my_repository.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/usecases/updatename_usecase.dart';
|
||||
|
||||
class MyCubit extends Cubit<MyState> {
|
||||
// 1. 修正变量命名:小驼峰规范(_updateNameUsecase)
|
||||
final UpdateNameUsecase _updateNameUsecase;
|
||||
final MyRepository repository;
|
||||
|
||||
// 2. 构造函数参数顺序与命名对齐
|
||||
MyCubit(this.repository, this._updateNameUsecase) : super(const MyState());
|
||||
|
||||
Future<void> updateName(String nickName) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: ''));
|
||||
|
||||
try {
|
||||
final params = UpdateNameParams(nickName);
|
||||
final result = await _updateNameUsecase(params);
|
||||
print("$result 修改名称结构");
|
||||
|
||||
// 4. 恢复 fold 逻辑,处理 UseCase 返回结果(关键:更新 UI 状态)
|
||||
result.fold((failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '修改昵称失败')), (successCode) {
|
||||
print("$successCode 修改名称结构");
|
||||
final isSuccess = successCode == 200;
|
||||
if (isSuccess) {
|
||||
emit(state.copyWith(isLoading: false, errorMessage: '', nickName: nickName));
|
||||
} else {
|
||||
emit(state.copyWith(isLoading: false, errorMessage: '修改昵称失败:状态码 $successCode'));
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
emit(state.copyWith(isLoading: false, errorMessage: '修改昵称异常:${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
// 保留解绑设备方法(如果需要)
|
||||
Future<void> unbindDevice(String deviceId, String deviceName) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: ''));
|
||||
// 解绑逻辑(如需保留,需补充 UnbindDeviceUsecase 依赖注入)
|
||||
}
|
||||
}
|
||||
22
lib/features/my/presentation/bloc/my_state.dart
Normal file
22
lib/features/my/presentation/bloc/my_state.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
|
||||
class MyState extends Equatable {
|
||||
final bool isLoading; // 是否正在加载
|
||||
final String? errorMessage; // 错误信息
|
||||
final String? nickName;
|
||||
|
||||
const MyState({this.isLoading = false, this.errorMessage, this.nickName});
|
||||
|
||||
// 使用 copyWith 方便局部更新状态
|
||||
MyState copyWith({bool? isLoading, String? errorMessage, String? nickName}) {
|
||||
return MyState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
errorMessage: errorMessage, // 错误信息通常每次更新都要重新赋值或清空
|
||||
nickName: nickName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [isLoading, errorMessage, nickName];
|
||||
}
|
||||
@@ -3,6 +3,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/repository/my_repository.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/usecases/updatename_usecase.dart';
|
||||
import '../../../../core/router/route_paths.dart';
|
||||
import '../../../../core/storage/user_storage.dart';
|
||||
import '../../../auth/presentation/bloc/auth_cubit.dart';
|
||||
@@ -24,7 +28,7 @@ class MyPage extends StatelessWidget {
|
||||
|
||||
if (authState is AuthAuthenticated) {
|
||||
final user = authState.user;
|
||||
userName = user.username ?? '未知用户';
|
||||
userName = user.nickname ?? '未知用户';
|
||||
userId = user.userId ?? '未知ID';
|
||||
}
|
||||
|
||||
@@ -36,7 +40,10 @@ class MyPage extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 顶部用户信息
|
||||
UserInfoCard(userName: userName, userId: userId),
|
||||
BlocProvider(
|
||||
create: (context) => MyCubit(sl<MyRepository>(), sl<UpdateNameUsecase>()),
|
||||
child: UserInfoCard(userName: userName, userId: userId),
|
||||
),
|
||||
|
||||
SizedBox(height: 16),
|
||||
|
||||
@@ -63,24 +70,14 @@ class MyPage extends StatelessWidget {
|
||||
// 添加 context 参数
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => WebViewPage(url: 'https://www.satabot.com/'),
|
||||
),
|
||||
);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => WebViewPage(url: 'https://www.satabot.com/')));
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 160,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(
|
||||
'https://c.53326.com/d/file/lan20221010/fyhj0ibovbp.jpg',
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
image: DecorationImage(image: NetworkImage('https://c.53326.com/d/file/lan20221010/fyhj0ibovbp.jpg'), fit: BoxFit.cover),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
@@ -89,23 +86,14 @@ class MyPage extends StatelessWidget {
|
||||
right: 12,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'了解我们',
|
||||
style: TextStyle(color: Colors.white, fontSize: 14),
|
||||
),
|
||||
decoration: BoxDecoration(color: Colors.black.withOpacity(0.5), borderRadius: BorderRadius.circular(4)),
|
||||
child: Text('了解我们', style: TextStyle(color: Colors.white, fontSize: 14)),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 12,
|
||||
bottom: 12,
|
||||
child: Text(
|
||||
'AI赋能农业',
|
||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
child: Text('AI赋能农业', style: TextStyle(color: Colors.white, fontSize: 16)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -115,35 +103,17 @@ class MyPage extends StatelessWidget {
|
||||
|
||||
Widget _buildFunctionList(BuildContext context) {
|
||||
final items = [
|
||||
{
|
||||
'icon': Icons.play_arrow,
|
||||
'title': '操作视频',
|
||||
'url': 'https://www.satabot.com/Support/index.html',
|
||||
},
|
||||
{
|
||||
'icon': Icons.car_rental,
|
||||
'title': '租赁服务',
|
||||
'url': 'https://www.satabot.com/Leasing.html',
|
||||
},
|
||||
{
|
||||
'icon': Icons.help_outline,
|
||||
'title': '帮助与支持',
|
||||
'url': 'https://www.satabot.com/support/index.html',
|
||||
},
|
||||
{
|
||||
'icon': Icons.policy,
|
||||
'title': '售后政策',
|
||||
'url': 'https://www.satabot.com/Aftersales-Service.html',
|
||||
},
|
||||
{'icon': Icons.play_arrow, 'title': '操作视频', 'url': 'https://www.satabot.com/Support/index.html'},
|
||||
{'icon': Icons.car_rental, 'title': '租赁服务', 'url': 'https://www.satabot.com/Leasing.html'},
|
||||
{'icon': Icons.help_outline, 'title': '帮助与支持', 'url': 'https://www.satabot.com/support/index.html'},
|
||||
{'icon': Icons.policy, 'title': '售后政策', 'url': 'https://www.satabot.com/Aftersales-Service.html'},
|
||||
];
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 4),
|
||||
],
|
||||
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 4)],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -159,13 +129,7 @@ class MyPage extends StatelessWidget {
|
||||
title: Text(item['title'] as String),
|
||||
trailing: Icon(Icons.arrow_forward),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
WebViewPage(url: item['url'] as String),
|
||||
),
|
||||
);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => WebViewPage(url: item['url'] as String)));
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,17 +1,224 @@
|
||||
// user_info_card.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart'; // 1. 导入扫码库
|
||||
import 'package:get_it/get_it.dart'; // 用于获取 Cubit 实例
|
||||
// 2. 导入你的 Cubit 文件,请根据实际路径调整
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_state.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../auth/presentation/bloc/auth_cubit.dart';
|
||||
|
||||
class UserInfoCard extends StatelessWidget {
|
||||
class UserInfoCard extends StatefulWidget {
|
||||
final String userName;
|
||||
final String userId;
|
||||
|
||||
const UserInfoCard({super.key, required this.userName, required this.userId});
|
||||
|
||||
@override
|
||||
State<UserInfoCard> createState() => _UserInfoCardState();
|
||||
}
|
||||
|
||||
class _UserInfoCardState extends State<UserInfoCard> {
|
||||
late TextEditingController _nicknameController;
|
||||
final GetIt _getIt = GetIt.I;
|
||||
MyCubit? _myCubit; // 可空类型
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 优先从 BlocProvider 获取,获取失败则从 GetIt 兜底
|
||||
try {
|
||||
_myCubit = BlocProvider.of<MyCubit>(context);
|
||||
} catch (e) {
|
||||
debugPrint('从 BlocProvider 获取 MyCubit 失败:$e,尝试从 GetIt 获取');
|
||||
try {
|
||||
_myCubit = _getIt<MyCubit>();
|
||||
} catch (e) {
|
||||
debugPrint('从 GetIt 获取 MyCubit 也失败:$e');
|
||||
}
|
||||
}
|
||||
_nicknameController = TextEditingController(text: widget.userName);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nicknameController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// 打开修改昵称的底部抽屉
|
||||
void _openEditNicknameBottomSheet() {
|
||||
// 修复1:先校验 _myCubit 是否为 null,避免空断言
|
||||
final myCubit = _myCubit;
|
||||
if (myCubit == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Cubit 初始化失败,无法修改昵称'), backgroundColor: Colors.red));
|
||||
return;
|
||||
}
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.8),
|
||||
builder: (context) => BlocProvider.value(
|
||||
// 使用非空的局部变量,无需空断言
|
||||
value: myCubit,
|
||||
child: BlocBuilder<MyCubit, MyState>(
|
||||
builder: (context, myState) {
|
||||
final cubit = context.read<MyCubit>();
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 16, right: 16, top: 20, bottom: MediaQuery.of(context).viewInsets.bottom + 80),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('修改昵称', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
IconButton(padding: EdgeInsets.zero, icon: const Icon(Icons.close, size: 20), onPressed: () => Navigator.pop(context)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('新昵称', style: TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _nicknameController,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
),
|
||||
autofocus: true,
|
||||
enabled: !myState.isLoading,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 核心:根据 MyState 显示加载/按钮/错误提示
|
||||
if (myState.isLoading)
|
||||
const Center(
|
||||
child: Column(
|
||||
children: [
|
||||
CircularProgressIndicator(color: Colors.blue),
|
||||
SizedBox(height: 8),
|
||||
Text("修改中...", style: TextStyle(color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: [
|
||||
// 修复2:使用 ?. 和 ?? 避免空断言,安全判断错误信息
|
||||
if (myState.errorMessage?.isNotEmpty ?? false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(myState.errorMessage ?? "修改失败", style: const TextStyle(color: Colors.red, fontSize: 14)),
|
||||
),
|
||||
|
||||
// 确定修改按钮
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _submitNewNickname(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: const Text('确定修改', style: TextStyle(fontSize: 16, color: Colors.white)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 提交新昵称的业务逻辑
|
||||
Future<void> _submitNewNickname(BuildContext context) async {
|
||||
final newNickname = _nicknameController.text.trim();
|
||||
if (newNickname.isEmpty ) {
|
||||
Navigator.pop(context);
|
||||
return;
|
||||
}
|
||||
|
||||
final myCubit = _myCubit;
|
||||
if (myCubit == null) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Cubit 初始化失败'), backgroundColor: Colors.red));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除重复的加载弹窗(由 BlocBuilder 显示加载状态)
|
||||
await myCubit.updateName(newNickname);
|
||||
|
||||
// 成功后由 BlocBuilder 监听状态并处理弹窗关闭和提示
|
||||
if (context.mounted && myCubit.state.errorMessage!.isEmpty ?? true) {
|
||||
setState(() {
|
||||
_nicknameController.text = newNickname;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
// 触发 AuthCubit 重新获取用户信息
|
||||
}
|
||||
}
|
||||
|
||||
// 扫码绑定设备逻辑(保留)
|
||||
Future<void> _handleScanAndBind(BuildContext context) async {
|
||||
final String? qrCode = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MobileScanner(
|
||||
onDetect: (capture) {
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isNotEmpty) {
|
||||
final String? code = barcodes.first.rawValue;
|
||||
if (code != null && code.isNotEmpty) {
|
||||
Navigator.pop(context, code);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (qrCode == null || qrCode.isEmpty) return;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(child: CircularProgressIndicator(color: Color(0xFF1677FF), strokeWidth: 4)),
|
||||
);
|
||||
|
||||
try {
|
||||
final devicesCubit = _getIt<DevicesCubit>();
|
||||
// await devicesCubit.bindDevice(qrCode);
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('设备绑定成功!'), backgroundColor: Colors.green));
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('绑定失败:$e'), backgroundColor: Colors.red));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
@@ -21,97 +228,23 @@ class UserInfoCard extends StatelessWidget {
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
image: DecorationImage(
|
||||
image: NetworkImage('https://pic4.zhimg.com/v2-c34c61a90095abb8713de9d1dca7ec7b_r.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
image: DecorationImage(image: NetworkImage('https://pic4.zhimg.com/v2-c34c61a90095abb8713de9d1dca7ec7b_r.jpg'), fit: BoxFit.cover),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(userName, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
Text('用户 id:$userId', style: TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
Text(_nicknameController.text, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
Text('用户 id:${widget.userId}', style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {},
|
||||
),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.add),
|
||||
// 3. 绑定点击事件
|
||||
onPressed: () => _handleScanAndBind(context),
|
||||
),
|
||||
IconButton(icon: const Icon(Icons.edit), onPressed: _openEditNicknameBottomSheet),
|
||||
const Spacer(),
|
||||
IconButton(icon: const Icon(Icons.add), onPressed: () => _handleScanAndBind(context)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 4. 定义扫码与绑定逻辑
|
||||
Future<void> _handleScanAndBind(BuildContext context) async {
|
||||
// 跳转到扫码页面
|
||||
final String? qrCode = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MobileScanner(
|
||||
onDetect: (capture) {
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isNotEmpty) {
|
||||
debugPrint('识别到的数据: $barcodes');
|
||||
final String? code = barcodes.first.rawValue;
|
||||
if (code != null && code.isNotEmpty) {
|
||||
// 识别成功,立即返回结果并关闭页面
|
||||
debugPrint('扫码成功,识别到的数据: $code');
|
||||
// Navigator.pop(context, code);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// 如果用户取消或未扫到码,直接返回
|
||||
if (qrCode == null || qrCode.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载对话框
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
|
||||
try {
|
||||
// 5. 获取 Cubit 实例并调用绑定接口
|
||||
final Cubit = GetIt.I<DevicesCubit>();
|
||||
|
||||
// 执行绑定逻辑
|
||||
//await Cubit.bindDevice(qrCode);
|
||||
|
||||
// 关闭加载框
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
|
||||
// 成功提示
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('设备绑定成功!'), backgroundColor: Colors.green),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// 关闭加载框
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
|
||||
// 失败提示
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('绑定失败:$e'), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user