| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639 |
- import 'dart:io';
- import 'package:clean/model/asset_info.dart';
- import 'package:clean/module/privacy/privacy_controller.dart';
- import 'package:clean/module/privacy/privacy_state.dart';
- import 'package:clean/router/app_pages.dart';
- import 'package:clean/utils/expand.dart';
- import 'package:clean/utils/file_utils.dart';
- import 'package:clean/utils/image_util.dart';
- import 'package:flutter/Material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import '../../base/base_view.dart';
- import '../../dialog/privacy_lock_dialog.dart';
- import '../../resource/assets.gen.dart';
- import 'dart:typed_data';
- class PrivacyPage extends BaseView<PrivacyController> {
- const PrivacyPage({super.key});
- @override
- Widget buildBody(BuildContext context) {
- return Obx(() {
- return Stack(
- children: [
- !controller.isUnlock.value
- ? _buildPasswordPage()
- : _buildPrivacySpace(context),
- IgnorePointer(
- child: Assets.images.bgHome.image(
- width: 360.w,
- ),
- ),
- ],
- );
- });
- }
- // 输入密码界面
- Widget _buildPasswordPage() {
- return SafeArea(
- child: Container(
- padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- GestureDetector(
- onTap: () {
- Get.back();
- },
- child:
- Assets.images.iconCommonBack.image(width: 28.w, height: 28.w),
- ),
- SizedBox(
- height: 28.h,
- ),
- Align(
- child: Column(
- children: [
- Assets.images.iconPrivacyLock
- .image(width: 70.w, height: 70.w),
- Text(
- controller.passwordTitle.value,
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.sp,
- fontWeight: FontWeight.w700,
- ),
- ),
- SizedBox(
- height: 28.h,
- ),
- Obx(() {
- return Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Container(
- width: 32.h,
- height: 32.h,
- decoration: BoxDecoration(
- border: Border.all(
- color: "#0279FB".color,
- width: 2.w,
- ),
- borderRadius:
- BorderRadius.all(Radius.circular(16.h)),
- color: controller.passwordStr.value.isNotEmpty
- ? "#0279FB".color
- : Colors.transparent),
- ),
- Container(
- margin: EdgeInsets.only(left: 16.w),
- width: 32.h,
- height: 32.h,
- decoration: BoxDecoration(
- border: Border.all(
- color: "#0279FB".color,
- width: 2.w,
- ),
- borderRadius:
- BorderRadius.all(Radius.circular(16.h)),
- color: controller.passwordStr.value.length >= 2
- ? "#0279FB".color
- : Colors.transparent),
- ),
- Container(
- margin: EdgeInsets.only(left: 16.w),
- width: 32.h,
- height: 32.h,
- decoration: BoxDecoration(
- border: Border.all(
- color: "#0279FB".color,
- width: 2.w,
- ),
- borderRadius:
- BorderRadius.all(Radius.circular(16.h)),
- color: controller.passwordStr.value.length >= 3
- ? "#0279FB".color
- : Colors.transparent),
- ),
- Container(
- margin: EdgeInsets.only(left: 16.w),
- width: 32.h,
- height: 32.h,
- decoration: BoxDecoration(
- border: Border.all(
- color: "#0279FB".color,
- width: 2.w,
- ),
- borderRadius:
- BorderRadius.all(Radius.circular(16.h)),
- color: controller.passwordStr.value.length >= 4
- ? "#0279FB".color
- : Colors.transparent),
- ),
- ],
- );
- }),
- SizedBox(
- height: 67.h,
- ),
- _buildPasswordInput(),
- ],
- ),
- )
- ],
- ),
- ),
- );
- }
- Widget _buildPasswordInput() {
- return Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- _buildNumberBtn("1"),
- _buildNumberBtn("2"),
- _buildNumberBtn("3"),
- ],
- ),
- SizedBox(height: 20.h),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- _buildNumberBtn("4"),
- _buildNumberBtn("5"),
- _buildNumberBtn("6"),
- ],
- ),
- SizedBox(height: 20.h),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- _buildNumberBtn("7"),
- _buildNumberBtn("8"),
- _buildNumberBtn("9"),
- ],
- ),
- SizedBox(height: 20.h),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- _buildNumberBtn(""),
- _buildNumberBtn("0"),
- _buildDeleteBtn(),
- ],
- ),
- ],
- );
- }
- Widget _buildNumberBtn(String num) {
- return Opacity(
- opacity: num.isEmpty ? 0 : 1,
- child: GestureDetector(
- onTap: () {
- controller.inputPassword(num);
- },
- child: Container(
- width: 76.w,
- height: 76.w,
- decoration: BoxDecoration(
- color: "#FFFFFF".color.withOpacity(0.12),
- borderRadius: BorderRadius.all(Radius.circular(38.w)),
- ),
- child: Align(
- child: Text(
- num,
- style: TextStyle(
- color: Colors.white,
- fontSize: 20.sp,
- fontWeight: FontWeight.w700,
- ),
- ),
- ),
- ),
- ),
- );
- }
- Widget _buildDeleteBtn() {
- return GestureDetector(
- onTap: () {
- if (controller.passwordStr.isNotEmpty) {
- controller.passwordStr.value = controller.passwordStr.value
- .substring(0, controller.passwordStr.value.length - 1);
- }
- },
- child: Container(
- width: 76.w,
- height: 76.w,
- decoration: BoxDecoration(
- color: "#FFFFFF".color.withOpacity(0.12),
- borderRadius: BorderRadius.all(Radius.circular(38.w)),
- ),
- child: Center(
- child:
- Assets.images.iconPrivacyDelete.image(width: 34.w, height: 24.h),
- ),
- ),
- );
- }
- Widget _buildPrivacySpace(BuildContext context) {
- return SafeArea(
- child: Container(
- padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
- child: Obx(() {
- return Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- !controller.isEdit.value
- ? Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- GestureDetector(
- onTap: () {
- Get.back();
- },
- child: Assets.images.iconCommonBack
- .image(width: 28.w, height: 28.w),
- ),
- Obx(() {
- return Visibility(
- visible: PrivacyState.imageList.isNotEmpty,
- child: GestureDetector(
- onTap: () {
- controller.isEdit.value = true;
- },
- child: Container(
- width: 71.w,
- height: 30.h,
- decoration: BoxDecoration(
- color: "#1F2D3F".color,
- borderRadius: BorderRadius.all(
- Radius.circular(15.h),
- ),
- ),
- child: Center(
- child: Text(
- "Select",
- style: TextStyle(
- color: Colors.white,
- fontSize: 14.sp,
- ),
- ),
- ),
- ),
- ),
- );
- }),
- ],
- )
- : Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- GestureDetector(
- onTap: () {
- controller.isEdit.value = false;
- },
- child: Container(
- width: 71.w,
- height: 30.h,
- decoration: BoxDecoration(
- color: "#1F2D3F".color,
- borderRadius: BorderRadius.all(
- Radius.circular(15.h),
- ),
- ),
- child: Center(
- child: Text(
- "Cancel",
- style: TextStyle(
- color: Colors.white,
- fontSize: 14.sp,
- ),
- ),
- ),
- ),
- ),
- Obx(() {
- return Visibility(
- visible: PrivacyState.imageList.isNotEmpty,
- child: GestureDetector(
- onTap: () {
- controller.toggleSelectAll();
- },
- child: Text(
- "Select All",
- style: TextStyle(
- color: Colors.white.withOpacity(0.65),
- fontSize: 14.sp,
- ),
- ),
- ),
- );
- }),
- ],
- ),
- SizedBox(
- height: 12.h,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- "Privacy Space",
- style: TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.w700,
- fontSize: 24.sp,
- ),
- ),
- GestureDetector(
- onTap: () {
- showDialog(
- context: context,
- builder: (context) => PrivacyLockDialog(
- isPrivacyOn: controller.isPrivacyExistPasswd.value,
- onResetPassword: () {
- // 处理重置密码
- controller.dialogSetPassword();
- Navigator.pop(context);
- },
- onSetPublic: () {
- // 处理设为公开
- controller.setPublic();
- Navigator.pop(context);
- },
- ),
- );
- },
- child: controller.isPrivacyExistPasswd.value
- ? Assets.images.iconPrivacyLock
- .image(width: 34.w, height: 34.w)
- : Assets.images.iconPrivacyUnlock
- .image(width: 34.w, height: 34.w),
- ),
- ],
- ),
- PrivacyState.imageList.isEmpty
- ? _buildEmptyPhotoView(context)
- : _buildPhotoView(),
- ],
- );
- }),
- ),
- );
- }
- _buildEmptyPhotoView(BuildContext context) {
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- SizedBox(
- height: 130.h,
- ),
- Assets.images.iconPrivacyEmptyImage.image(width: 70.w, height: 70.w),
- SizedBox(
- height: 22.h,
- ),
- Text(
- "Upload Files to Privacy Space",
- style: TextStyle(
- color: Colors.white.withOpacity(0.9),
- fontWeight: FontWeight.w500,
- fontSize: 18.sp,
- ),
- ),
- SizedBox(
- height: 116.h,
- ),
- GestureDetector(
- onTap: () {
- controller.uploadBtnClick();
- },
- child: Container(
- width: 180.w,
- height: 48.h,
- decoration: BoxDecoration(
- color: "#0279FB".color,
- borderRadius: BorderRadius.all(
- Radius.circular(10.r),
- ),
- ),
- child: Center(
- child: Text(
- "Upload",
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildPhotoView() {
- return Expanded(
- child: Column(
- children: [
- SizedBox(
- height: 20.h,
- ),
- Expanded(
- child: ListView.builder(
- shrinkWrap: true,
- itemCount: controller.monthCount,
- itemBuilder: (context, index) {
- final monthAssets =
- ImageUtil.getMonthAssets(controller.assetsByMonth, index);
- return Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- ImageUtil.getMonthText(controller.assetsByMonth, index),
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- color: Colors.white),
- ),
- SizedBox(
- height: 11.h,
- ),
- GridView.builder(
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- itemCount: monthAssets.length,
- itemBuilder: (context, index) {
- var asset = monthAssets[index];
- return _buildAssetItem(asset);
- },
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3, // 每行有 4 列
- mainAxisSpacing: 8.w, // 主轴(垂直)上的间距
- crossAxisSpacing: 8.w, // 交叉轴(水平)上的间距
- childAspectRatio: 1.0, // 子项宽高比
- ),
- ),
- SizedBox(
- height: 24.h,
- ),
- ],
- );
- },
- ),
- ),
- !controller.isEdit.value
- ? GestureDetector(
- onTap: () {
- controller.uploadBtnClick();
- },
- child: Container(
- width: 328.w,
- height: 48.h,
- decoration: BoxDecoration(
- color: "#0279FB".color,
- borderRadius: BorderRadius.all(
- Radius.circular(10.r),
- ),
- ),
- child: Center(
- child: Text(
- "Upload",
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ),
- )
- : GestureDetector(
- onTap: () {
- controller.deleteBtnClick();
- },
- child: Container(
- width: 328.w,
- height: 48.h,
- decoration: BoxDecoration(
- color: "#0279FB".color,
- borderRadius: BorderRadius.all(
- Radius.circular(10.r),
- ),
- ),
- child: Center(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Assets.images.iconPrivacyPhotoDelete
- .image(width: 18.w, height: 18.h),
- SizedBox(
- width: 5.w,
- ),
- Text(
- controller.formatFileSize(
- controller.selectedTotalSize.value),
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- ),
- )
- ],
- ),
- );
- }
- // 构建图片项
- Widget _buildAssetItem(AssetInfo asset) {
- return GestureDetector(
- onTap: () async {
- // 获取当前资产在列表中的索引
- final index = PrivacyState.imageList.indexWhere((item) => item.id == asset.id);
- if (index != -1) { // 确保找到了索引
- final result = await Get.toNamed(RoutePath.photoInfo, arguments: {
- "type": "privacy",
- "list": PrivacyState.imageList,
- "index": index,
- });
- // 检查返回结果并刷新
- if (result != null && result['deleted'] == true) {
- controller.loadAssets();
- }
- }
- },
- child: Stack(
- children: [
- ClipRRect(
- borderRadius: BorderRadius.circular(8.r),
- child: FutureBuilder<Uint8List?>(
- future: ImageUtil.getImageThumbnail(FileType.privacy, asset),
- builder: (context, snapshot) {
- if (snapshot.data != null) {
- return Image.memory(
- snapshot.data!,
- width: double.infinity,
- height: double.infinity,
- fit: BoxFit.cover,
- gaplessPlayback: true,
- );
- } else {
- return Container();
- }
- },
- ),
- ),
- // 删除按钮
- Visibility(
- visible: controller.isEdit.value,
- child: Positioned(
- right: 4.w,
- bottom: 4.h,
- child: GestureDetector(
- onTap: () {
- controller.toggleSelectAsset(asset.id);
- },
- child: Container(
- child: controller.selectedAssets.contains(asset.id)
- ? Center(
- child: Assets.images.iconSelected.image(
- width: 16.w,
- height: 16.h,
- ),
- )
- : Center(
- child: Assets.images.iconUnselected.image(
- width: 16.w,
- height: 16.h,
- ),
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
|