import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// 页顶导航条
class VAppBar extends AppBar {
  /// 标题文字
  final String? titleText;

  /// 标题组件
  final Widget? titleWidget;

  /// 右侧组件组
  final List<Widget>? actions;

  final BuildContext? context;

  VAppBar({
    super.key,
    this.titleText,
    this.titleWidget,
    this.actions,
    this.context,
  }) : super(
          toolbarHeight: 90,
          backgroundColor: Colors.white,
          foregroundColor: Colors.green,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: context != null
                    ? [
                        Theme.of(context).primaryColor.withOpacity(.6),
                        Theme.of(context).primaryColor,
                      ]
                    : const [
                        Color.fromRGBO(59, 188, 255, 1),
                        Color.fromRGBO(44, 120, 229, 1),
                      ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
            ),
          ),
          leadingWidth: 100,
          leading: IconButton(
            icon: const Icon(
              Icons.arrow_back_rounded,
              size: 68,
              color: Colors.white,
            ),
            onPressed: () {
              Get.back();
            },
          ),
          centerTitle: true,
          titleTextStyle: const TextStyle(fontSize: 24),
          title: titleWidget ?? Text(titleText!),
          actions: actions,
          actionsIconTheme: const IconThemeData(size: 68, color: Colors.white),
        );
}
