bind_partner_view.dart 13 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
import 'package:doublefeel_flutter/app/widget/dash_divider.dart';
import 'package:doublefeel_flutter/core/services/thinking_data_service.dart';
import 'package:doublefeel_flutter/core/theme/app_theme.dart';
import 'package:doublefeel_flutter/core/util/app_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:get/get.dart';

import '../../../../l10n/l10n_extensions.dart';
import '../controllers/bind_partner_controller.dart';

class BindPartnerView extends GetView<BindPartnerController> {
  const BindPartnerView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      resizeToAvoidBottomInset: true,
      extendBodyBehindAppBar: true,
      appBar: AppBar(
          automaticallyImplyLeading: false,
          leading: controller.isShowAppBarBack
              ? IconButton(
                  highlightColor: Colors.transparent,
                  padding: EdgeInsets.zero,
                  onPressed: Get.back,
                  icon: Image.asset(
                    'assets/images/common/ic_nav_back.webp',
                    width: 24,
                    height: 24,
                  ),
                )
              : SizedBox()),
      body: PopScope(
        canPop: false,
        child: Stack(
          children: [
            _buildGradientBackground(),
            Container(
              padding: EdgeInsets.only(top: 4),
              child: ListView(
                physics: const ClampingScrollPhysics(),
                children: [
                  _buildTitle(context),
                  // SizedBox(height: 28),
                  _buildCardArea(context),
                  // SizedBox(height: 58),
                  if (controller.isShowSkipButton) _buildSkipButton(context),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 渐变背景
  Widget _buildGradientBackground() {
    return Positioned.fill(
      child: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            stops: [0.0, 0.25, 0.75, 1.0],
            colors: [
              Color(0xFFE6DBFF),
              Color(0xFFEDE4FF),
              Color(0xFFEEE6FF),
              Color(0xFFF9F6FF),
            ],
          ),
        ),
      ),
    );
  }

  /// 标题文字
  Widget _buildTitle(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 37),
      child: Text(
        context.l10n.bindPartnerTitle,
        textAlign: TextAlign.center,
        style: TextStyle(
          fontSize: 20,
          fontWeight: FontWeight.w600,
          color: context.colors.textPrimary,
          height: 1.4,
        ),
      ),
    );
  }

  Widget _buildCardArea(BuildContext context) {
    return Stack(
      children: [
        Container(
          margin: EdgeInsets.only(top: 28, bottom: 64, left: 24, right: 24),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20),
            image: DecorationImage(
              image: AssetImage(
                  'assets/images/friends/bg_friend_add_subtract.webp'),
              fit: BoxFit.cover,
            ),
            boxShadow: [
              BoxShadow(
                color: context.colors.primary.withValues(alpha: 0.08),
                blurRadius: 24,
                offset: const Offset(0, 8),
              ),
            ],
          ),
          child: Column(
            children: [
              SizedBox(height: 28),
              _buildMyInfoSection(context),
              SizedBox(height: 40),
              _buildOrDivider(context),
              SizedBox(height: 28),
              _buildInputSection(context),
              SizedBox(height: 16),
              // 继续按钮
              Container(
                padding: EdgeInsets.symmetric(horizontal: 32),
                child: Obx(() {
                  return _buildPrimaryButton(
                    label: context.l10n.continueButton,
                    onTap: controller.onSubmitPartnerId,
                    enabled:
                        controller.canSubmit && !controller.isSubmitting.value,
                    isLoading: controller.isSubmitting.value,
                    primaryColor: context.colors.chartOrange,
                  );
                }),
              ),
              SizedBox(height: 40),
            ],
          ),
        ),
        Positioned(
          top: -15,
          left: -8,
          child: Image.asset(
            'assets/images/user_onboarding/ic_bind_decor_top.png',
            width: 133,
            height: 124,
            fit: BoxFit.fitHeight,
          ),
        ),
        Positioned(
          bottom: 0,
          right: 0,
          child: Image.asset(
            'assets/images/user_onboarding/ic_bind_decor_bottom.png',
            width: 133,
            height: 124,
            fit: BoxFit.fitHeight,
          ),
        ),
      ],
    );
  }

  Widget _buildMyInfoSection(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 32),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          // 标签
          Text(
            context.l10n.bindPartnerMyId,
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w400,
              color: context.colors.textPrimary,
            ),
          ),
          SizedBox(height: 13),

          Obx(() {
            return Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  controller.myInviteCode.value,
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w600,
                    color: context.colors.primary,
                    height: 1.4,
                  ),
                ),
                SizedBox(width: 8),
                // 复制图标按钮
                GestureDetector(
                  onTap: () {
                    Clipboard.setData(
                      ClipboardData(text: controller.myInviteCode.value),
                    );
                    AppToast.show(context.l10n.copiedSuccessfully);
                    ta.track('click_doublefeel_add_friend_page', properties: {
                      'channel_type': controller.channel,
                      'click_content': '复制共享码'
                    });
                  },
                  child: Container(
                    width: 20,
                    height: 20,
                    decoration: BoxDecoration(
                      color: const Color(0xFFF0F0F6),
                      borderRadius: BorderRadius.circular(6),
                    ),
                    padding: EdgeInsets.all(3),
                    child: Image.asset(
                      'assets/images/common/ic_copy_purple.webp',
                    ),
                  ),
                ),
              ],
            );
          }),
          SizedBox(height: 26),
          // 分享按钮
          _buildPrimaryButton(
            label: context.l10n.bindPartnerShareMyCode,
            onTap: controller.onShareMyCode,
            enabled: true,
            primaryColor: context.colors.primary,
          ),
        ],
      ),
    );
  }

  Widget _buildOrDivider(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: Padding(
            padding: const EdgeInsets.only(left: 27),
            child: DashedDivider(),
          ),
        ),
        Container(
          width: 36,
          height: 36,
          decoration: const BoxDecoration(
            color: Color(0xFFEDE5FF),
            shape: BoxShape.circle,
          ),
          alignment: Alignment.center,
          child: Text(
            context.l10n.bindPartnerOr,
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w400,
              color: context.colors.primary,
            ),
          ),
        ),
        Expanded(
          child: Padding(
            padding: const EdgeInsets.only(right: 27),
            child: DashedDivider(),
          ),
        ),
      ],
    );
  }

  /// 输入伙伴 ID 区域
  Widget _buildInputSection(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 32),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          // 标签
          Text(
            context.l10n.bindPartnerContactId,
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w400,
              color: context.colors.textPrimary,
            ),
          ),
          SizedBox(height: 16),
          // 输入框
          Container(
            height: 52,
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: const Color(0xFFF0F0F6), width: 1),
              borderRadius: BorderRadius.circular(27),
            ),
            child: Stack(
              alignment: Alignment.center, // 确保 Stack 里的子项绝对居中
              children: [
                // 自定义 Hint 文字层
                Obx(() => controller.partnerIdInput.value.isEmpty
                    ? IgnorePointer(
                        child: Text(
                          context.l10n.bindPartnerInputHint,
                          style: const TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.w400,
                            color: Color(0xFFD0D0D2),
                            height: 1.1,
                          ),
                        ),
                      )
                    : const SizedBox()),
                // 真正的输入框层(不设 hintText)
                TextField(
                  controller: controller.partnerIdController,
                  textAlign: TextAlign.center,
                  textAlignVertical: TextAlignVertical.center,
                  contextMenuBuilder: (BuildContext context,
                      EditableTextState editableTextState) {
                    // 获取默认的菜单项列表
                    List<ContextMenuButtonItem> buttonItems =
                        editableTextState.contextMenuButtonItems;

                    // 例如:只保留“粘贴” (Paste)
                    buttonItems.removeWhere(
                        (item) => item.type != ContextMenuButtonType.paste);
                    return AdaptiveTextSelectionToolbar.buttonItems(
                      anchors: editableTextState.contextMenuAnchors,
                      buttonItems: buttonItems,
                    );
                  },
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w400,
                    color: context.colors.textPrimary,
                    height: 1.1,
                  ),
                  cursorWidth: 2.0,
                  cursorHeight: 24.0,
                  cursorRadius: const Radius.circular(1.5),
                  decoration: const InputDecoration(
                    border: InputBorder.none,
                    isCollapsed: true,
                    contentPadding:
                        EdgeInsets.symmetric(horizontal: 20, vertical: 0),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /// 通用主按钮
  Widget _buildPrimaryButton({
    required String label,
    required VoidCallback onTap,
    bool enabled = true,
    bool isLoading = false,
    required Color primaryColor,
  }) {
    return GestureDetector(
      onTap: enabled ? onTap : null,
      child: Container(
        width: double.infinity,
        height: 40,
        decoration: BoxDecoration(
          color: enabled ? primaryColor : primaryColor.withValues(alpha: 0.3),
          borderRadius: BorderRadius.circular(100),
        ),
        alignment: Alignment.center,
        child: isLoading
            ? SizedBox(
                width: 18,
                height: 18,
                child: const CircularProgressIndicator(
                  strokeWidth: 2,
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
                ),
              )
            : Text(
                label,
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.w600,
                  color: Colors.white,
                ),
              ),
      ),
    );
  }

  /// 底部"下次再说"按钮
  Widget _buildSkipButton(BuildContext context) {
    return GestureDetector(
      onTap: controller.onSkip,
      behavior: HitTestBehavior.opaque,
      child: Container(
        width: 280,
        height: 48,
        alignment: Alignment.center,
        child: Text(
          context.l10n.bindPartnerSkip,
          style: TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.w600,
            color: const Color(0xFFA1A0A5),
          ),
        ),
      ),
    );
  }
}