123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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<Widget> actions,
- backgroundColor = Colors.white,
- paddingLeading = true,
- useClose = false,
- canBack = true,
- innerBoxIsScrolled = false,
- height = 110.0,
- brightness = -1,
- textStyle = titleStyle,
- whiteBackButton = false,
- pinned = true
- }) {
- return SliverAppBar(
- pinned: pinned,
- brightness: brightness ==-1? null :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<FlexibleSpaceBarSettings>();
- 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);
- },
- );
- }
|