privacy_settings_view.dart 3.99 KB
import 'package:doublefeel_flutter/core/theme/app_colors.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:doublefeel_flutter/l10n/l10n_extensions.dart';
import 'package:doublefeel_flutter/r.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/privacy_settings_controller.dart';

class PrivacySettingsView extends GetView<PrivacySettingsController> {
  const PrivacySettingsView({super.key});

  static const _background = Color(0xFFF5F2FF);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: _background,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        toolbarHeight: 44.dp,
        centerTitle: true,
        title: Text(
          context.l10n.privacySettingsTitle,
          style: const TextStyle(
            fontSize: 16,
            color: Color(0xFF000000),
            fontWeight: FontWeight.w500,
          ),
        ),
        leading: IconButton(
          highlightColor: Colors.transparent,
          padding: EdgeInsets.zero,
          onPressed: () {
            controller.executeBackLogic();
          },
          icon: Image(
            width: 24.w,
            height: 24.w,
            alignment: Alignment.centerLeft,
            image: AssetImage(R.assetsImagesNavBackIcon),
          ),
        ),
      ),
      body: PopScope(canPop: false, child: _buildContentView(context)),
    );
  }

  Widget _buildContentView(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      height: double.infinity,
      child: Column(
        children: [
          SizedBox(height: 16.dp),
          noAddByIdView(context),
          SizedBox(height: 12.dp),
          showRealtimeStressView(context),
        ],
      ),
    );
  }

  Widget noAddByIdView(BuildContext context) {
    return _settingRow(
      title: context.l10n.privacySettingsDisableAddById,
      value: controller.enableAddWithUCode,
      onChanged: () => controller.isUpdatingEnableAddWithUCode.value
          ? null
          : controller.updateEnableAddWithUCode,
    );
  }

  Widget showRealtimeStressView(BuildContext context) {
    return _settingRow(
      title: context.l10n.privacySettingsShowRealtimeStress,
      value: controller.showRealtimeStress,
      onChanged: () => controller.updateShowRealtimeStress,
      height: 56.dp,
      titleAccessory: () => controller.isVip.value
          ? const SizedBox.shrink()
          : SizedBox(
              width: 43.dp,
              height: 16.dp,
              child: Image.asset(
                'assets/images/common/ic_pro_badge.webp',
                fit: BoxFit.fill,
              ),
            ),
    );
  }

  Widget _settingRow({
    required String title,
    required RxBool value,
    required ValueChanged<bool>? Function() onChanged,
    Widget Function()? titleAccessory,
    double? height,
  }) {
    return Container(
      width: double.infinity,
      height: height ?? 48.dp,
      margin: EdgeInsets.symmetric(horizontal: 16.dp),
      padding: EdgeInsets.symmetric(horizontal: 20.dp),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16.dp),
      ),
      child: Row(
        children: [
          Text(
            title,
            style: const TextStyle(
              fontSize: 14,
              color: AppColors.textPrimary,
            ),
          ),
          if (titleAccessory != null) ...[
            SizedBox(width: 4.dp),
            Obx(titleAccessory),
          ],
          const Spacer(),
          Obx(
            () => Transform.scale(
              scaleX: 52 / 51,
              scaleY: 28 / 31,
              child: CupertinoSwitch(
                value: !value.value,
                activeTrackColor: AppColors.primary,
                inactiveTrackColor: const Color(0xFFE5E5EA),
                onChanged: onChanged(),
              ),
            ),
          ),
        ],
      ),
    );
  }
}