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

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

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

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

  final BuildContext? context;

  VAppBar({
    super.key,
    this.titleText,
    this.titleWidget,
    this.actions,
    this.context,
  }) : super(
          elevation: 0,
          scrolledUnderElevation: 0,
          toolbarHeight: 60,
          backgroundColor: Colors.white,
          foregroundColor: Colors.green,
          flexibleSpace: Builder(builder: (context) {
            return Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Theme.of(context).primaryColor.withOpacity(.6),
                    Theme.of(context).primaryColor,
                  ],
                  begin: Alignment.topRight,
                  end: Alignment.bottomLeft,
                ),
              ),
            );
          }),
          leadingWidth: 88,
          leading: IconButton(
            icon: const Icon(
              Icons.arrow_back_ios_new,
              size: 36,
              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),
        );
}
