import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sport/widgets/image.dart'; const titleStyle = TextStyle( fontWeight: FontWeight.w600, fontSize: 18.0, color: Color(0xff333333)); Widget buildSliverAppBar(BuildContext context, String title, {List actions, backgroundColor = Colors.white, paddingLeading = true, useClose = false, canBack = true, innerBoxIsScrolled = false, height = 110.0, brightness = 0, textStyle = titleStyle, whiteBackButton = false, pinned = true }) { return SliverAppBar( pinned: pinned, brightness: brightness == 1 ? Brightness.dark : Brightness.light, expandedHeight: height, backgroundColor: backgroundColor, forceElevated: innerBoxIsScrolled, titleSpacing: 0, elevation: 0, leading: useClose ? IconButton( icon: Image.asset("lib/assets/img/topbar_cancel.png"), onPressed: () { Navigator.of(context).pop(); }, ) : canBack ? IconButton( icon: arrowBack(), onPressed: () { Navigator.of(context).pop(); }, ) : whiteBackButton ? IconButton( icon: Image.asset("lib/assets/img/topbar_return_white.png"), onPressed: () { Navigator.of(context).pop(); }, ) : Container(), actions: actions, flexibleSpace: buildFlexibleSpace(title, paddingLeading: paddingLeading, textStyle: textStyle)); } Widget buildFlexibleSpace( String title, { paddingLeading = true, textStyle = titleStyle, }) { return LayoutBuilder(builder: (context, box) { final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType(); return FlexibleSpaceBar( centerTitle: false, titlePadding: EdgeInsets.fromLTRB(12.0, 0, 0, 15.0), title: paddingLeading ? Padding( padding: EdgeInsets.only( left: (settings.maxExtent - box.biggest.height) / 3 * 2), child: Text( title, style: textStyle, ), ) : Text( title, style: textStyle, ), ); }); } Widget buildActionButton(String title, VoidCallback onPressed, {Color textColor}) { return IconButton( icon: Text( title, style: textColor != null ? TextStyle(fontSize: 16.0, color: textColor) : TextStyle(fontSize: 16), ), onPressed: onPressed, ); } Widget buildBackButton(BuildContext context) { return IconButton( icon: arrowBack(), onPressed: () { Navigator.maybePop(context); }, ); }