purchase_bottom_bar.dart 3.48 KB
import 'dart:math' as math;

import 'package:flutter/material.dart';

import 'purchase_colors.dart';

class PurchaseBottomBar extends StatelessWidget {
  const PurchaseBottomBar({
    super.key,
    required this.label,
    required this.loading,
    required this.onPressed,
    this.onTermsTap,
    this.onPrivacyTap,
  });

  final String label;
  final bool loading;
  final VoidCallback onPressed;
  final VoidCallback? onTermsTap;
  final VoidCallback? onPrivacyTap;

  @override
  Widget build(BuildContext context) {
    final bottomInset = MediaQuery.paddingOf(context).bottom;
    final buttonWidth = math.min(280.0, MediaQuery.sizeOf(context).width - 74);

    return IgnorePointer(
      ignoring: loading,
      child: Container(
        height: 147 + bottomInset,
        padding: EdgeInsets.only(bottom: bottomInset),
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.center,
            colors: [Color(0x00F5F2FF), PurchaseColors.background],
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            SizedBox(
              width: buttonWidth,
              height: 48,
              child: ElevatedButton(
                onPressed: onPressed,
                style: ElevatedButton.styleFrom(
                  elevation: 0,
                  shadowColor: Colors.transparent,
                  backgroundColor: PurchaseColors.proYellow,
                  foregroundColor: PurchaseColors.title,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(24),
                  ),
                  textStyle: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                    letterSpacing: 0,
                  ),
                ),
                child: loading
                    ? const SizedBox(
                        width: 18,
                        height: 18,
                        child: CircularProgressIndicator(
                          strokeWidth: 2,
                          color: PurchaseColors.title,
                        ),
                      )
                    : Text(label),
              ),
            ),
            const SizedBox(height: 12),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                _BottomLink(label: '服务条款', onTap: onTermsTap),
                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 8),
                  child: Text(
                    '|',
                    style: TextStyle(
                      color: PurchaseColors.subtitle,
                      fontSize: 12,
                    ),
                  ),
                ),
                _BottomLink(label: '隐私政策', onTap: onPrivacyTap),
              ],
            ),
            const SizedBox(height: 18),
          ],
        ),
      ),
    );
  }
}

class _BottomLink extends StatelessWidget {
  const _BottomLink({required this.label, required this.onTap});

  final String label;
  final VoidCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Text(
        label,
        style: const TextStyle(
          color: PurchaseColors.subtitle,
          fontSize: 12,
          height: 1.2,
        ),
      ),
    );
  }
}