383 lines
10 KiB
Dart
383 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
||
|
||
class MinePage extends StatefulWidget {
|
||
const MinePage({super.key});
|
||
|
||
@override
|
||
State<MinePage> createState() => _MinePageState();
|
||
}
|
||
|
||
|
||
class _MinePageState extends State<MinePage> {
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MaterialApp(
|
||
debugShowCheckedModeBanner: false,
|
||
title: '安全设置',
|
||
theme: ThemeData(
|
||
primarySwatch: Colors.blue,
|
||
scaffoldBackgroundColor: const Color(0xFFF5F7FA),
|
||
),
|
||
home: const SafetySettingsPage(),
|
||
);
|
||
}
|
||
}
|
||
|
||
class SafetySettingsPage extends StatefulWidget {
|
||
const SafetySettingsPage({super.key});
|
||
|
||
@override
|
||
State<SafetySettingsPage> createState() => _SafetySettingsPageState();
|
||
}
|
||
|
||
class _SafetySettingsPageState extends State<SafetySettingsPage> {
|
||
// 设置项状态
|
||
bool notificationsEnabled = false;
|
||
bool passwordChanged = false;
|
||
bool updateAvailable = false;
|
||
bool logoutSelected = false;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
body: SingleChildScrollView(
|
||
// child: Padding(
|
||
// padding: const EdgeInsets.all(24.0),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
// 顶部标题区域
|
||
_buildHeaderSection(),
|
||
const SizedBox(height: 15),
|
||
|
||
// 标语区域
|
||
// _buildSloganSection(),
|
||
// const SizedBox(height: 40),
|
||
// 图片区
|
||
_buildCenterImage(),
|
||
const SizedBox(height: 15),
|
||
|
||
// 设置项列表
|
||
_buildSettingsList(),
|
||
const SizedBox(height: 40),
|
||
|
||
// 底部按钮
|
||
// _buildActionButton(),
|
||
],
|
||
),
|
||
// ),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildHeaderSection() {
|
||
return Stack(
|
||
alignment: const FractionalOffset(0.5, 1),
|
||
children: [
|
||
|
||
Padding(
|
||
padding: EdgeInsets.fromLTRB(0,0,0,30),
|
||
child: Image.asset(
|
||
"assets/images/bannerbg.png",
|
||
width: MediaQuery.of(context).size.width, // 获取屏幕宽度
|
||
fit: BoxFit.cover,
|
||
)
|
||
),
|
||
|
||
// 标语区域
|
||
_buildSloganSection(),
|
||
const SizedBox(height: 40),
|
||
],
|
||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||
// children: [
|
||
// const Text(
|
||
// "齐津诚",
|
||
// style: TextStyle(
|
||
// fontSize: 28,
|
||
// fontWeight: FontWeight.bold,
|
||
// color: Color(0xFF1A237E),
|
||
// ),
|
||
// ),
|
||
// const SizedBox(height: 8),
|
||
// Text(
|
||
// "齐津诚",
|
||
// style: TextStyle(
|
||
// fontSize: 18,
|
||
// color: Colors.grey[700],
|
||
// ),
|
||
// ),
|
||
// ],
|
||
|
||
|
||
);
|
||
}
|
||
|
||
Widget _buildSloganSection() {
|
||
return Container(
|
||
// padding: const EdgeInsets.all(24.0),
|
||
margin: EdgeInsets.fromLTRB(24,0,24,0),
|
||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(12),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.grey.withOpacity(0.1),
|
||
spreadRadius: 2,
|
||
blurRadius: 8,
|
||
offset: const Offset(0, 4),
|
||
),
|
||
],
|
||
),
|
||
child: Row(
|
||
children: [
|
||
CircleAvatar(
|
||
backgroundImage: AssetImage("assets/images/tx.png"),
|
||
radius: 30,
|
||
),
|
||
const SizedBox(width: 16),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
"用户名称",
|
||
style: TextStyle(
|
||
fontSize: 18,
|
||
fontWeight: FontWeight.bold,
|
||
color: Color(0xFF000000),
|
||
),
|
||
),
|
||
Text(
|
||
"用户简介",
|
||
style: TextStyle(
|
||
fontSize: 14,
|
||
color: Colors.grey[600],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildSettingsList() {
|
||
return Container(
|
||
margin: const EdgeInsets.fromLTRB(24,0,24,0),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(16),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.grey.withOpacity(0.1),
|
||
spreadRadius: 2,
|
||
blurRadius: 8,
|
||
offset: const Offset(0, 4),
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
children: [
|
||
// 通知提醒
|
||
_buildSettingItem(
|
||
title: "通知提醒",
|
||
icon: "assets/images/i2.png",
|
||
value: notificationsEnabled,
|
||
onChanged: (value) => setState(() => notificationsEnabled = value!),
|
||
),
|
||
// const Divider(height: 1, indent: 60),
|
||
|
||
// 修改密码
|
||
_buildSettingItem(
|
||
title: "修改密码",
|
||
icon: "assets/images/i3.png",
|
||
value: passwordChanged,
|
||
onChanged: (value) => setState(() => passwordChanged = value!),
|
||
),
|
||
// const Divider(height: 1, indent: 60),
|
||
|
||
// 版本更新
|
||
_buildSettingItem(
|
||
title: "版本更新",
|
||
icon: "assets/images/i5.png",
|
||
value: updateAvailable,
|
||
onChanged: (value) => setState(() => updateAvailable = value!),
|
||
),
|
||
// const Divider(height: 1, indent: 60),
|
||
|
||
// 退出登录
|
||
_buildSettingItem(
|
||
title: "退出登录",
|
||
icon: "assets/images/i4.png",
|
||
value: logoutSelected,
|
||
onChanged: (value) {
|
||
setState(() => logoutSelected = value!);
|
||
if (value == true) {
|
||
_showLogoutConfirmation();
|
||
}
|
||
},
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildSettingItem({
|
||
required String title,
|
||
required String icon,
|
||
required bool value,
|
||
required ValueChanged<bool?> onChanged,
|
||
}) {
|
||
return ListTile(
|
||
leading: Container(
|
||
width: 20,
|
||
height: 20,
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(10),
|
||
),
|
||
child: Image.asset(icon ,fit: BoxFit.cover, ),
|
||
),
|
||
title: Text(
|
||
title,
|
||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||
),
|
||
|
||
trailing: Transform.scale(
|
||
scale: 1.2,
|
||
child: Image.asset(
|
||
"assets/images/right.png",
|
||
fit: BoxFit.cover,
|
||
width: 15,
|
||
height: 15,
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildActionButton() {
|
||
return SizedBox(
|
||
width: double.infinity,
|
||
child: ElevatedButton(
|
||
onPressed: () {
|
||
// 保存设置逻辑
|
||
_saveSettings();
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: const Color(0xFF1A237E),
|
||
foregroundColor: Colors.white,
|
||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
elevation: 3, // 注意:elevation应该放在styleFrom内部
|
||
),
|
||
child: const Text(
|
||
"保存设置",
|
||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _saveSettings() {
|
||
// 这里可以添加保存设置到服务器的逻辑
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: const Text("设置已保存成功"),
|
||
backgroundColor: Colors.green[700],
|
||
duration: const Duration(seconds: 2),
|
||
behavior: SnackBarBehavior.floating,
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _showLogoutConfirmation() {
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) => AlertDialog(
|
||
title: const Text("退出登录"),
|
||
content: const Text("确定要退出当前账号吗?"),
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () {
|
||
setState(() => logoutSelected = false);
|
||
Navigator.pop(context);
|
||
},
|
||
child: const Text("取消"),
|
||
),
|
||
ElevatedButton(
|
||
onPressed: () {
|
||
// 执行退出登录操作
|
||
Navigator.pop(context);
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: const Text("您已成功退出登录"),
|
||
backgroundColor: Colors.blue[700],
|
||
duration: const Duration(seconds: 2),
|
||
),
|
||
);
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: Colors.blue[700],
|
||
foregroundColor: Colors.white,
|
||
),
|
||
child: const Text("确定退出"),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
Widget _buildCenterImage (){
|
||
return Stack(
|
||
children: [
|
||
|
||
Container(
|
||
margin: const EdgeInsets.fromLTRB(24,0,24,0),
|
||
height: 100,
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(10.0),
|
||
image: DecorationImage(
|
||
image: AssetImage('assets/images/bg1.png'),
|
||
fit: BoxFit.cover,
|
||
),
|
||
),
|
||
),
|
||
Positioned(
|
||
top: 25,
|
||
left: 45,
|
||
child: Text(
|
||
"防范事故 保障安全",
|
||
style: TextStyle(
|
||
fontSize: 18,
|
||
fontWeight: FontWeight.bold,
|
||
color: Color(0xFF000000),
|
||
),
|
||
),
|
||
),
|
||
Positioned(
|
||
top: 55,
|
||
left: 45,
|
||
child: Text(
|
||
"治理隐患,健康你我他",
|
||
style: TextStyle(
|
||
fontSize: 14,
|
||
color: Colors.grey[600],
|
||
),
|
||
),
|
||
)
|
||
|
||
]
|
||
);
|
||
|
||
|
||
|
||
}
|