151 lines
5.4 KiB
Dart
151 lines
5.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
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/components/BannerCarousel.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';
|
|
import '../../../auth/presentation/bloc/auth_state.dart';
|
|
import '../../../auth/presentation/pages/login_page.dart';
|
|
import '../../../web_view/web_view_page.dart';
|
|
import '../web_view/user_info_pages.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
class MyPage extends StatelessWidget {
|
|
const MyPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// 假设从 AuthCubit 获取用户信息
|
|
final authState = context.watch<AuthCubit>().state;
|
|
String userName = '未知用户';
|
|
String userId = '未知ID';
|
|
|
|
if (authState is AuthAuthenticated) {
|
|
final user = authState.user;
|
|
userName = user.nickname ?? '未知用户';
|
|
userId = user.userId ?? '未知ID';
|
|
}
|
|
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: SingleChildScrollView(
|
|
padding: EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 顶部用户信息
|
|
BlocProvider(
|
|
create: (context) => MyCubit(sl<MyRepository>(), sl<UpdateNameUsecase>()),
|
|
child: UserInfoCard(userName: userName, userId: userId),
|
|
),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
// 中间横幅
|
|
_buildBanner(context),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
// 功能列表
|
|
_buildFunctionList(context),
|
|
|
|
//SizedBox(height: 16),
|
|
|
|
//// 退出登录按钮
|
|
//_buildLogoutButton(context),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBanner(BuildContext context) {
|
|
// 添加 context 参数
|
|
return BannerCarousel(
|
|
items: [
|
|
BannerItem(image: 'assets/images/carousel3.jpg', title: 'AI赋能农业', url: 'https://www.satabot.com/'),
|
|
BannerItem(image: 'assets/images/carousel1.png', title: '智能农机上新', url: 'https://www.satabot.com/'),
|
|
BannerItem(image: 'assets/images/carousel2.png', title: '科技改变生活', url: 'https://www.satabot.com/'),
|
|
],
|
|
);
|
|
}
|
|
|
|
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'},
|
|
];
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 4)],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
// 功能列表
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(), // 禁止滚动,使其适应父容器高度
|
|
itemCount: items.length,
|
|
itemBuilder: (context, index) {
|
|
final item = items[index];
|
|
return ListTile(
|
|
leading: Icon(item['icon'] as IconData),
|
|
title: Text(item['title'] as String),
|
|
trailing: Icon(Icons.arrow_forward),
|
|
onTap: () {
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) => WebViewPage(url: item['url'] as String)));
|
|
},
|
|
);
|
|
},
|
|
),
|
|
// 分割线
|
|
Divider(height: 1, color: Colors.grey.withOpacity(0.3)),
|
|
// 退出登录按钮
|
|
ListTile(
|
|
leading: const Icon(Icons.logout, color: Colors.black),
|
|
title: Text('退出登录', style: TextStyle(color: Colors.black)),
|
|
trailing: Icon(Icons.exit_to_app, color: Colors.black),
|
|
onTap: () async {
|
|
await GetIt.I<UserStorage>().deleteUser();
|
|
GetIt.I<AuthCubit>().logout();
|
|
context.go(RoutePaths.login);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLogoutButton(BuildContext context) {
|
|
return ElevatedButton(
|
|
onPressed: () async {
|
|
await GetIt.I<UserStorage>().deleteUser();
|
|
GetIt.I<AuthCubit>().logout();
|
|
context.go(RoutePaths.login);
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.white,
|
|
foregroundColor: Colors.red,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 12),
|
|
),
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|