Finished app bar for the home screen
This commit is contained in:
parent
b112e629a4
commit
d4bb1c631a
3 changed files with 120 additions and 2 deletions
|
|
@ -33,6 +33,11 @@ class HomeBloc {
|
||||||
return user.photoUrl;
|
return user.photoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getUserDisplayName() async {
|
||||||
|
final user = await _auth.currentUser;
|
||||||
|
return user.displayName;
|
||||||
|
}
|
||||||
|
|
||||||
void markTaskAsDone(TaskModel task) async {
|
void markTaskAsDone(TaskModel task) async {
|
||||||
_firestore.updateTask(
|
_firestore.updateTask(
|
||||||
task.id,
|
task.id,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../models/task_model.dart';
|
import '../models/task_model.dart';
|
||||||
import '../blocs/home_bloc.dart';
|
import '../blocs/home_bloc.dart';
|
||||||
|
import '../widgets/home_app_bar.dart';
|
||||||
import '../widgets/task_list_tile.dart';
|
import '../widgets/task_list_tile.dart';
|
||||||
import '../widgets/loading_indicator.dart';
|
import '../widgets/loading_indicator.dart';
|
||||||
|
|
||||||
|
|
@ -11,17 +14,30 @@ class HomeScreen extends StatefulWidget {
|
||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen> {
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
final HomeBloc bloc = HomeBloc();
|
final HomeBloc bloc = HomeBloc();
|
||||||
|
String avatarUrl;
|
||||||
|
String userDisplayName;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
bloc.fetchTasks();
|
bloc.fetchTasks();
|
||||||
|
setUserAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setUserAttributes() async {
|
||||||
|
final url = await bloc.getUserAvatarUrl();
|
||||||
|
final name = await bloc.getUserDisplayName();
|
||||||
|
setState(() {
|
||||||
|
avatarUrl = url;
|
||||||
|
userDisplayName = name;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: HomeAppBar(
|
||||||
title: Text('Main Screen'),
|
avatarUrl: avatarUrl,
|
||||||
|
subtitle: 'Hello $userDisplayName!',
|
||||||
),
|
),
|
||||||
body: StreamBuilder(
|
body: StreamBuilder(
|
||||||
stream: bloc.userTasks,
|
stream: bloc.userTasks,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
|
||||||
|
import './logo.dart';
|
||||||
|
|
||||||
|
class HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
|
final String avatarUrl;
|
||||||
|
final String subtitle;
|
||||||
|
|
||||||
|
HomeAppBar({
|
||||||
|
this.avatarUrl,
|
||||||
|
this.subtitle = '',
|
||||||
|
});
|
||||||
|
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
color: Theme.of(context).cardColor,
|
||||||
|
child: SafeArea(
|
||||||
|
top: true,
|
||||||
|
child: Container(
|
||||||
|
height: preferredSize.height,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
buildTopSection(),
|
||||||
|
SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(left: 30),
|
||||||
|
child: Logo(),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(left: 30),
|
||||||
|
child: Text(
|
||||||
|
subtitle,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildTopSection() {
|
||||||
|
return Row(
|
||||||
|
children: <Widget>[
|
||||||
|
SizedBox(
|
||||||
|
width: 20,
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
FontAwesomeIcons.bars,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
Spacer(),
|
||||||
|
maybeBuildAvatar(),
|
||||||
|
SizedBox(
|
||||||
|
width: 20,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget maybeBuildAvatar() {
|
||||||
|
return avatarUrl == null
|
||||||
|
? Container(
|
||||||
|
height: 60,
|
||||||
|
width: 60,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(30),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Icon(
|
||||||
|
FontAwesomeIcons.question,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ClipOval(
|
||||||
|
child: Image.network(
|
||||||
|
avatarUrl,
|
||||||
|
height: 60,
|
||||||
|
width: 60,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final preferredSize = Size.fromHeight(240.0);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue