account_settings_view.dart 5.08 KB
import 'package:doublefeel_flutter/core/theme/app_colors.dart';
import 'package:doublefeel_flutter/core/theme/app_theme.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:doublefeel_flutter/data/models/user/user_models.dart';
import 'package:doublefeel_flutter/r.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../controllers/account_settings_controller.dart';

class AccountSettingsView extends GetView<AccountSettingsController> {
  const AccountSettingsView({super.key});

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark,
        statusBarBrightness: Brightness.light,
        systemNavigationBarColor: context.colors.backgroundPage,
        systemNavigationBarIconBrightness: Brightness.dark,
      ),
      child: Scaffold(
        backgroundColor: context.colors.backgroundPage,
        appBar: AppBar(
          title: Text(
            '账号设置',
          ),
          leading: IconButton(
            highlightColor: Colors.transparent,
            splashColor: Colors.transparent,
            padding: EdgeInsets.zero,
            onPressed: controller.executeBackLogic,
            icon: Image.asset(
              R.assetsImagesNavBackIcon,
              width: 28.dp,
              height: 28.dp,
            ),
          ),
        ),
        body: Obx(() {
          final user = controller.userPrefs.preferences.value.meUserInfo;
          return Column(
            children: [
              SizedBox(height: 16.dp),
              _AccountCard(user: user, onLogout: controller.logout),
              SizedBox(height: 17.dp),
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: controller.openOnboarding,
                child: Padding(
                  padding: EdgeInsets.symmetric(
                    horizontal: 32.dp,
                    vertical: 8.dp,
                  ),
                  child: Text(
                    '注销账号',
                    style: TextStyle(
                      color: context.colors.warning,
                      fontSize: 12.dp,
                      fontWeight: FontWeight.w400,
                      height: 1.25,
                    ),
                  ),
                ),
              ),
            ],
          );
        }),
      ),
    );
  }
}

class _AccountCard extends StatelessWidget {
  const _AccountCard({
    required this.user,
    required this.onLogout,
  });

  final UserInfoResponse? user;
  final VoidCallback onLogout;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 110.dp,
      margin: EdgeInsets.symmetric(horizontal: 15.dp),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16.dp),
      ),
      child: Column(
        children: [
          SizedBox(
            height: 54.dp,
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 20.dp),
              child: Row(
                children: [
                  Text(
                    '手机号',
                    style: TextStyle(
                      color: AppColors.textPrimary,
                      fontSize: 14.dp,
                      fontWeight: FontWeight.w400,
                      height: 1.25,
                    ),
                  ),
                  const Spacer(),
                  Text(
                    _formatPhone(user?.telephone),
                    style: TextStyle(
                      color: AppColors.textSecondary,
                      fontSize: 14.dp,
                      fontWeight: FontWeight.w400,
                      height: 1.25,
                    ),
                  ),
                ],
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 20.dp),
            child: Divider(
              height: 1.dp,
              thickness: 1.dp,
              color: const Color(0xFFF3F3F3),
            ),
          ),
          Expanded(
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: onLogout,
              child: Center(
                child: Text(
                  '退出登录',
                  style: TextStyle(
                    color: AppColors.primary,
                    fontSize: 14.dp,
                    fontWeight: FontWeight.w500,
                    height: 1.25,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  String _formatPhone(String? phone) {
    final normalized = phone?.replaceAll(' ', '').trim();
    if (normalized == null || normalized.isEmpty) {
      return '130 1478 9632';
    }
    if (normalized.length == 11) {
      return '${normalized.substring(0, 3)} '
          '${normalized.substring(3, 7)} '
          '${normalized.substring(7)}';
    }
    return normalized;
  }
}