From 74c63ee70a78188fc739dae967c731535e343cf4 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Sat, 6 Apr 2019 23:16:15 -0600 Subject: [PATCH] Added support for tab navigation (bottom widgets) for the custom app bar --- lib/src/screens/event_screen.dart | 18 ++++++++++++++++-- lib/src/widgets/custom_app_bar.dart | 23 ++++++++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/src/screens/event_screen.dart b/lib/src/screens/event_screen.dart index b72ef2c..1ba711f 100644 --- a/lib/src/screens/event_screen.dart +++ b/lib/src/screens/event_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +import '../utils.dart'; import '../blocs/event_bloc.dart'; import '../widgets/custom_app_bar.dart'; @@ -14,18 +15,31 @@ class EventScreen extends StatefulWidget { _EventScreenState createState() => _EventScreenState(); } -class _EventScreenState extends State { +class _EventScreenState extends State + with SingleTickerProviderStateMixin { EventBloc bloc; - + TabController _tabController; initState() { super.initState(); bloc = EventBloc(eventName: widget.eventName); + _tabController = TabController(vsync: this, length: 2); } Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar( title: widget.eventName, + bottom: TabBar( + controller: _tabController, + tabs: [ + Tab( + text: 'tab1', + ), + Tab( + text: 'tab2', + ), + ], + ), ), ); } diff --git a/lib/src/widgets/custom_app_bar.dart b/lib/src/widgets/custom_app_bar.dart index 3bf25b0..e84395e 100644 --- a/lib/src/widgets/custom_app_bar.dart +++ b/lib/src/widgets/custom_app_bar.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -//TODO: add support for tabed navigation. - /// A custom app bar to match the DO> design rules. /// /// This app bar is meant to be usen in screens that are not the home screen. @@ -12,16 +10,17 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { final String title; /// Widget to be shown on the bottom of the app bar. - final PreferredSize bottom; - - /// the preferred size for this widget. - final Size preferredSize; + final PreferredSizeWidget bottom; + /// The size of only the app bar part. + final double appBarHeight; CustomAppBar({ this.title = '', this.bottom, - }) : preferredSize = - Size.fromHeight(140.0 + (bottom?.preferredSize?.height ?? 0)); + }) : appBarHeight = bottom == null ? 140.0 : 120.0; + + Size get preferredSize => + Size.fromHeight(appBarHeight + (bottom?.preferredSize?.height ?? 0)); Widget build(BuildContext context) { Widget result = Container( @@ -56,8 +55,14 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { if (bottom != null) { result = Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - result, + Flexible( + child: ConstrainedBox( + constraints: const BoxConstraints(maxHeight: 140.0), + child: result, + ), + ), bottom, ], );