do_more/lib/src/screens/home_screen.dart

155 lines
4.2 KiB
Dart
Raw Normal View History

2019-03-20 22:57:44 -06:00
import 'dart:async';
import 'package:flutter/material.dart';
2019-03-21 00:06:56 -06:00
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../models/task_model.dart';
import '../blocs/home_bloc.dart';
2019-03-20 22:57:44 -06:00
import '../widgets/home_app_bar.dart';
import '../widgets/task_list_tile.dart';
import '../widgets/loading_indicator.dart';
2019-03-21 00:06:56 -06:00
import '../widgets/gradient_touchable_container.dart';
class HomeScreen extends StatefulWidget {
createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
2019-03-21 00:06:56 -06:00
static const _searchBoxHeight = 50.0;
final HomeBloc bloc = HomeBloc();
2019-03-20 22:57:44 -06:00
String avatarUrl;
String userDisplayName;
@override
initState() {
super.initState();
bloc.fetchTasks();
2019-03-20 22:57:44 -06:00
setUserAttributes();
}
Future<void> setUserAttributes() async {
final url = await bloc.getUserAvatarUrl();
final name = await bloc.getUserDisplayName();
setState(() {
avatarUrl = url;
userDisplayName = name;
});
}
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(FontAwesomeIcons.plus),
backgroundColor: Color(0xFF707070),
onPressed: () {},
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
2019-03-20 22:57:44 -06:00
appBar: HomeAppBar(
avatarUrl: avatarUrl,
subtitle: 'Hello $userDisplayName!',
),
body: StreamBuilder(
stream: bloc.userTasks,
builder: (BuildContext context, AsyncSnapshot<List<TaskModel>> snap) {
if (!snap.hasData) {
return Center(
child: LoadingIndicator(),
);
}
2019-03-21 00:06:56 -06:00
return Stack(
overflow: Overflow.visible,
children: <Widget>[
buildTasksList(snap.data),
// This container is needed to make it seem like the search box is
// part of the app bar.
2019-03-21 00:06:56 -06:00
Container(
height: _searchBoxHeight / 2,
width: double.infinity,
color: Theme.of(context).cardColor,
),
buildSearchBox(),
],
);
},
),
);
}
Widget buildTasksList(List<TaskModel> tasks) {
return ListView(
padding: EdgeInsets.only(top: _searchBoxHeight + 15),
children: tasks
.map((task) => Container(
child: TaskListTile(
task: task,
onDone: () => bloc.markTaskAsDone(task),
),
padding: EdgeInsets.only(bottom: 12),
))
.toList()
..add(Container(height: 70)),
);
}
2019-03-21 00:06:56 -06:00
Widget buildSearchBox() {
return Row(
children: <Widget>[
Spacer(flex: 1),
Expanded(
flex: 8,
child: GradientTouchableContainer(
radius: _searchBoxHeight / 2,
height: _searchBoxHeight,
shadow: BoxShadow(
color: Color(0x20FFFFFF),
offset: Offset(0, 3),
blurRadius: 6,
spreadRadius: 1,
),
child: Row(
children: <Widget>[
SizedBox(
width: 10,
),
Icon(
FontAwesomeIcons.sistrix,
color: Colors.white,
),
SizedBox(
width: 8,
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Search...',
hintStyle: TextStyle(
fontSize: 16,
color: Colors.white,
),
),
cursorColor: Colors.white,
scrollPadding: EdgeInsets.zero,
style: TextStyle(
fontSize: 16,
color: Colors.white,
),
),
),
],
),
),
),
Spacer(flex: 1),
],
);
}
@override
void dispose() {
bloc.dispose();
super.dispose();
}
}