From dcbe71331b85be59a0b821c1872fc5e8af3ef9b9 Mon Sep 17 00:00:00 2001 From: Prathik Date: Wed, 4 Sep 2019 01:28:04 +0530 Subject: [PATCH] Fixes #14 --- lib/pages/home_page/home_page.dart | 41 ++++++++++++++++++++---------- lib/widgets/safe_app_bar.dart | 18 +++++++++++++ 2 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 lib/widgets/safe_app_bar.dart diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index a1b9a15..b211705 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -4,6 +4,7 @@ import 'package:xtimer/pages/bottom_sheet.dart'; import 'package:xtimer/pages/home_page/home_bloc.dart'; import 'package:xtimer/pages/home_page/home_events.dart'; import 'package:xtimer/pages/home_page/home_state.dart'; +import 'package:xtimer/widgets/safe_app_bar.dart'; import 'package:xtimer/widgets/task_widget.dart'; import 'package:xtimer/pages/new_task_page.dart'; @@ -61,14 +62,19 @@ class _HomePageState extends State { Widget build(BuildContext context) { return Scaffold( key: _scaffoldKey, - appBar: AppBar( - centerTitle: false, - elevation: 0.0, - backgroundColor: Colors.transparent, - title: Text( - widget.title, - style: TextStyle( - color: Colors.black, fontSize: 32.0, fontWeight: FontWeight.bold), + appBar: SafeAppBar( + appBar: AppBar( + centerTitle: false, + elevation: 0.0, + backgroundColor: Colors.transparent, + title: Text( + widget.title, + style: TextStyle( + color: Colors.black, + fontSize: 32.0, + fontWeight: FontWeight.bold, + ), + ), ), ), floatingActionButton: FloatingActionButton( @@ -91,8 +97,13 @@ class _HomePageState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - Text('No Tasks', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), + Text( + 'No Tasks', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), Text('Add a new Task and it\nwill show up here.', textAlign: TextAlign.center) ], @@ -110,15 +121,17 @@ class _HomePageState extends State { background: Container(color: Colors.red), direction: DismissDirection.endToStart, key: ObjectKey(item), - child: TaskWidget(task: item), + child: TaskWidget(task: item), onDismissed: (direction) { tasks.remove(item); setState(() {}); _homeBloc.dispatch(DeleteTaskEvent(task: item)); - Scaffold.of(context) - .showSnackBar( - SnackBar(content: Text("Task Deleted"))); + Scaffold.of(context).showSnackBar( + SnackBar( + content: Text("Task Deleted"), + ), + ); }, ), ); diff --git a/lib/widgets/safe_app_bar.dart b/lib/widgets/safe_app_bar.dart new file mode 100644 index 0000000..c2f7f20 --- /dev/null +++ b/lib/widgets/safe_app_bar.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; + +class SafeAppBar extends StatelessWidget implements PreferredSizeWidget { + final AppBar appBar; + + const SafeAppBar({Key key, this.appBar}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.only(top: 36), + child: appBar, + ); + } + + @override + Size get preferredSize => Size(double.infinity, 92); +}