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

import 'package:flutter/material.dart';
import 'package:doublefeel_flutter/l10n/l10n_extensions.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 SizedBox(
      height: 147 + bottomInset,
      child: Stack(
        children: [
          const Positioned.fill(
            child: IgnorePointer(
              child: DecoratedBox(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.center,
                    colors: [Color(0x00F5F2FF), PurchaseColors.background],
                  ),
                ),
              ),
            ),
          ),
          IgnorePointer(
            ignoring: loading,
            child: Padding(
              padding: EdgeInsets.only(bottom: bottomInset),
              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: context.l10n.purchaseTermsOfService,
                        onTap: onTermsTap,
                      ),
                      const Padding(
                        padding: EdgeInsets.symmetric(horizontal: 8),
                        child: Text(
                          '|',
                          style: TextStyle(
                            color: PurchaseColors.subtitle,
                            fontSize: 12,
                          ),
                        ),
                      ),
                      _BottomLink(
                        label: context.l10n.purchasePrivacyPolicy,
                        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,
        ),
      ),
    );
  }
}