123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import 'package:flutter/material.dart';
- class TransparentAppBarWidget extends StatefulWidget {
- final Widget? body;
- final Widget? title;
- final List<Widget>? actions;
- final Color backButtonColor;
- const TransparentAppBarWidget({super.key, required this.body, required this.title, required this.actions, required this.backButtonColor});
- @override
- State<StatefulWidget> createState() {
- return _TransparentAppBarState();
- }
- }
- class _TransparentAppBarState extends State<TransparentAppBarWidget> {
- @override
- Widget build(BuildContext context) {
- var padding = MediaQuery.of(context).padding;
- return Stack(
- children: stackChildren(padding),
- );
- }
- List<Widget> stackChildren(EdgeInsets padding) {
- if (widget.body!=null) {
- return <Widget>[
- widget.body!,
- Padding(
- padding: padding,
- child: SizedBox(
- height: kToolbarHeight,
- child: Row(
- children: appBarChildren(),
- ),
- ),
- )
- ];
- }else {
- return <Widget>[
- Padding(
- padding: padding,
- child: SizedBox(
- height: kToolbarHeight,
- child: Row(
- children: appBarChildren(),
- ),
- ),
- )
- ];
- }
- }
- List<Widget> appBarChildren() {
- if (widget.actions != null && widget.actions!.isNotEmpty) {
- return <Widget>[
- Padding(
- padding: const EdgeInsets.fromLTRB(5, 3, 5, 3),
- child: backAndTitle(),
- ),
- Expanded(
- flex: 1,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: widget.actions!,
- ),
- )
- ];
- }else {
- return <Widget>[
- Padding(
- padding: const EdgeInsets.fromLTRB(5, 3, 5, 3),
- child: backAndTitle(),
- )
- ];
- }
- }
- Widget backAndTitle() {
- if (widget.title!= null) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- BackButton(
- color: widget.backButtonColor,
- ),
- widget.title!
- ],
- );
- }else {
- return BackButton(
- color: widget.backButtonColor,
- );
- }
- }
- }
|