feat: moved topbars into each view for customization
parent
704aab2ae7
commit
7f529b090e
|
@ -13,6 +13,7 @@ class ConversationsBloc {
|
|||
|
||||
fetchConversations() async {
|
||||
List<Conversation> conversationList = await _provider.fetchConversations();
|
||||
print(conversationList);
|
||||
_conversationsFetcher.sink.add(conversationList);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,4 +19,4 @@ class MessageBloc {
|
|||
}
|
||||
|
||||
// global instance for access throughout the app
|
||||
final messageBloc = MessageBloc();
|
||||
final messageChannel = MessageBloc();
|
||||
|
|
|
@ -18,7 +18,6 @@ class ConversationActiveView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ConversationActiveViewState extends State<ConversationActiveView> {
|
||||
final bus = messageBloc;
|
||||
final conversationApiProvider = ConversationApiProvider();
|
||||
Conversation _conversation;
|
||||
List<Widget> _users;
|
||||
|
@ -91,7 +90,8 @@ class _ConversationActiveViewState extends State<ConversationActiveView> {
|
|||
icon: Icon(Icons.close),
|
||||
onPressed: () async {
|
||||
// Call method to close connection
|
||||
await bus.publish({"state": "disconnect"});
|
||||
await messageChannel
|
||||
.publish({"target": "home", "state": "disconnect"});
|
||||
print("Pressed close");
|
||||
}),
|
||||
]),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import "package:flutter/material.dart";
|
||||
|
||||
import "./widgets/home_view.dart";
|
||||
import "../../blocs/message_bloc.dart";
|
||||
|
||||
class ContactTab extends StatefulWidget {
|
||||
@override
|
||||
|
@ -10,17 +11,25 @@ class ContactTab extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ContactTabState extends State<ContactTab> {
|
||||
final GlobalKey<NavigatorState> navigatorKey =
|
||||
new GlobalKey<NavigatorState>();
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Navigator(
|
||||
initialRoute: "conversation/home",
|
||||
initialRoute: "contact/home",
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
WidgetBuilder builder;
|
||||
switch (settings.name) {
|
||||
case "conversation/home":
|
||||
case "contact/home":
|
||||
builder = (BuildContext _) => HomeView();
|
||||
break;
|
||||
case "conversation/new":
|
||||
case "contact/new":
|
||||
builder = (BuildContext _) => Center(child: Text("SOON"));
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -5,6 +5,7 @@ import "../../../models/user_model.dart";
|
|||
import "../../../blocs/contact_bloc.dart";
|
||||
|
||||
import "../widgets/contact_item.dart";
|
||||
import "../../widgets/top_bar.dart";
|
||||
import "../../widgets/search_input.dart";
|
||||
|
||||
class HomeView extends StatefulWidget {
|
||||
|
@ -31,16 +32,51 @@ class _HomeViewState extends State<HomeView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder(
|
||||
stream: contactBloc.contacts,
|
||||
builder: (context, AsyncSnapshot<List<User>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return buildList(snapshot);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
});
|
||||
return Column(children: <Widget>[
|
||||
TopBar(title: "Contacts", children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 13.0),
|
||||
child: Text("Edit",
|
||||
style: Theme.of(context)
|
||||
.accentTextTheme
|
||||
.title
|
||||
.copyWith(fontWeight: FontWeight.w300))),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, "contact/new");
|
||||
}),
|
||||
]),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
SearchInput(
|
||||
controller: searchController, hintText: "Search for people"),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
||||
child: Row(children: <Widget>[
|
||||
Icon(Icons.people_outline,
|
||||
color: Theme.of(context).primaryColorDark, size: 30.0),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20.0),
|
||||
child: Text("Invite Friends",
|
||||
style: Theme.of(context).textTheme.title.copyWith(
|
||||
color: Theme.of(context).primaryColorDark))),
|
||||
])),
|
||||
])),
|
||||
Expanded(
|
||||
child: StreamBuilder(
|
||||
stream: contactBloc.contacts,
|
||||
builder: (context, AsyncSnapshot<List<User>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return buildList(snapshot);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}))
|
||||
]);
|
||||
}
|
||||
|
||||
Widget buildList(AsyncSnapshot<List<User>> snapshot) {
|
||||
|
@ -89,7 +125,7 @@ class _HomeViewState extends State<HomeView> {
|
|||
return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
StickyHeader(
|
||||
header: Container(
|
||||
height: 20.0,
|
||||
height: 21.0,
|
||||
color: Colors.grey[200],
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
|
@ -110,25 +146,6 @@ class _HomeViewState extends State<HomeView> {
|
|||
]);
|
||||
}).toList();
|
||||
|
||||
children.insertAll(0, [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 15.0, right: 15.0),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
SearchInput(
|
||||
controller: searchController, hintText: "Search for people"),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
||||
child: Row(children: <Widget>[
|
||||
Icon(Icons.people_outline,
|
||||
color: Theme.of(context).primaryColorDark, size: 30.0),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20.0),
|
||||
child: Text("Invite Friends",
|
||||
style: Theme.of(context).textTheme.title.copyWith(
|
||||
color: Theme.of(context).primaryColorDark))),
|
||||
])),
|
||||
])),
|
||||
]);
|
||||
return ListView(padding: EdgeInsets.only(top: 10.0), children: children);
|
||||
return ListView(padding: EdgeInsets.only(top: 0.0), children: children);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import "package:flutter/material.dart";
|
||||
|
||||
import "./widgets/home_view.dart";
|
||||
|
||||
class ConversationTab extends StatefulWidget {
|
||||
|
|
|
@ -20,7 +20,6 @@ class ConversationItem extends StatefulWidget {
|
|||
class _ConversationItemState extends State<ConversationItem> {
|
||||
final bloc;
|
||||
final Conversation conversation;
|
||||
final bus = messageBloc;
|
||||
|
||||
_ConversationItemState({@required this.conversation})
|
||||
: bloc = ConversationMembersBloc(conversation.id);
|
||||
|
@ -44,8 +43,11 @@ class _ConversationItemState extends State<ConversationItem> {
|
|||
elevation: 1,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
await bus.publish(
|
||||
{"state": "connect", "conversationId": conversation.id});
|
||||
await messageChannel.publish({
|
||||
"target": "home",
|
||||
"state": "connect",
|
||||
"conversationId": conversation.id
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
|
|
|
@ -4,6 +4,7 @@ import "../../../models/conversation_model.dart";
|
|||
import "../../../blocs/conversation_bloc.dart";
|
||||
|
||||
import "../widgets/conversation_item.dart";
|
||||
import "../../widgets/top_bar.dart";
|
||||
import "../../widgets/search_input.dart";
|
||||
|
||||
class HomeView extends StatefulWidget {
|
||||
|
@ -30,22 +31,41 @@ class _HomeViewState extends State<HomeView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(padding: EdgeInsets.only(top: 10.0), children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0),
|
||||
child: SearchInput(
|
||||
controller: searchController,
|
||||
hintText: "Search for messages or users")),
|
||||
StreamBuilder(
|
||||
stream: conversationsBloc.conversations,
|
||||
builder: (context, AsyncSnapshot<List<Conversation>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return buildList(snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
})
|
||||
return Column(children: <Widget>[
|
||||
TopBar(title: "Conversations", children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 13.0),
|
||||
child: Text("Edit",
|
||||
style: Theme.of(context)
|
||||
.accentTextTheme
|
||||
.title
|
||||
.copyWith(fontWeight: FontWeight.w300))),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.add_comment),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, "conversation/new");
|
||||
}),
|
||||
]),
|
||||
Expanded(
|
||||
child:
|
||||
ListView(padding: EdgeInsets.only(top: 10.0), children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20.0, right: 20.0, bottom: 10.0),
|
||||
child: SearchInput(
|
||||
controller: searchController,
|
||||
hintText: "Search for messages or users")),
|
||||
StreamBuilder(
|
||||
stream: conversationsBloc.conversations,
|
||||
builder: (context, AsyncSnapshot<List<Conversation>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return buildList(snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
})
|
||||
]))
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import "package:flutter/material.dart";
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import "./widgets/top_bar.dart";
|
||||
import "./conversation_tab/conversation_tab.dart";
|
||||
import "./contact_tab/contact_tab.dart";
|
||||
import "./bottom_bar/bottom_bar.dart";
|
||||
|
@ -37,7 +36,7 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
|
|||
controller = TabController(vsync: this, length: 3);
|
||||
controller.index = 1; // Set default page to conversation page
|
||||
|
||||
messageBloc.bus.listen(
|
||||
messageChannel.bus.listen(
|
||||
(Map<String, String> data) async => await _processMessage(data));
|
||||
}
|
||||
|
||||
|
@ -48,24 +47,26 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
|
|||
}
|
||||
|
||||
_processMessage(Map<String, String> data) async {
|
||||
if (data["state"] == "disconnect") {
|
||||
// Disconnect and change state
|
||||
await conversationManager.exit();
|
||||
setState(() {
|
||||
currentConversationId = "";
|
||||
});
|
||||
} else if (data["state"] == "connect") {
|
||||
// Connect and change state
|
||||
await conversationManager.join(data["conversationId"]);
|
||||
setState(() {
|
||||
currentConversationId = data["conversationId"];
|
||||
});
|
||||
} else {
|
||||
// show default
|
||||
await conversationManager.exit();
|
||||
setState(() {
|
||||
currentConversationId = "";
|
||||
});
|
||||
if (data["target"] == "home") {
|
||||
if (data["state"] == "disconnect") {
|
||||
// Disconnect and change state
|
||||
await conversationManager.exit();
|
||||
setState(() {
|
||||
currentConversationId = "";
|
||||
});
|
||||
} else if (data["state"] == "connect") {
|
||||
// Connect and change state
|
||||
await conversationManager.join(data["conversationId"]);
|
||||
setState(() {
|
||||
currentConversationId = data["conversationId"];
|
||||
});
|
||||
} else {
|
||||
// show default
|
||||
await conversationManager.exit();
|
||||
setState(() {
|
||||
currentConversationId = "";
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,18 +74,14 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
body: Column(children: <Widget>[
|
||||
TopBar(state: _tabNumber),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
controller: controller,
|
||||
children: <Widget>[
|
||||
ContactTab(),
|
||||
ConversationTab(),
|
||||
Container(),
|
||||
])),
|
||||
]),
|
||||
body: TabBarView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
controller: controller,
|
||||
children: <Widget>[
|
||||
ContactTab(),
|
||||
ConversationTab(),
|
||||
Container(),
|
||||
]),
|
||||
bottomNavigationBar:
|
||||
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
BottomBar(conversationId: currentConversationId),
|
||||
|
|
|
@ -3,11 +3,11 @@ import "package:flutter/material.dart";
|
|||
import "search_input.dart";
|
||||
|
||||
class TopBar extends StatelessWidget {
|
||||
final int state;
|
||||
final String logo = "assets/logo.png";
|
||||
final List<String> titleList = ["Contacts", "Conversations", "Settings"];
|
||||
final List<Widget> children;
|
||||
final String title;
|
||||
|
||||
TopBar({@required this.state});
|
||||
TopBar({@required this.children, @required this.title});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -19,41 +19,18 @@ class TopBar extends StatelessWidget {
|
|||
child: Container(
|
||||
padding: EdgeInsets.only(top: statusbarHeight, bottom: 0),
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
elevation: 0.0,
|
||||
color: Colors.transparent,
|
||||
child: Column(children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 13.0),
|
||||
child: Text("Edit",
|
||||
style: Theme.of(context)
|
||||
.accentTextTheme
|
||||
.title
|
||||
.copyWith(fontWeight: FontWeight.w300))),
|
||||
Spacer(),
|
||||
Text(titleList[state],
|
||||
style: Theme.of(context).accentTextTheme.display1),
|
||||
Spacer(),
|
||||
(state == 1)
|
||||
? IconButton(
|
||||
icon: Icon(Icons.add_comment), onPressed: () {})
|
||||
: Container(),
|
||||
(state == 0)
|
||||
? IconButton(icon: Icon(Icons.add), onPressed: () {})
|
||||
: Container(),
|
||||
(state == 2)
|
||||
? Opacity(
|
||||
opacity: 0.0,
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.edit), onPressed: () {}))
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
])),
|
||||
type: MaterialType.transparency,
|
||||
elevation: 0.0,
|
||||
color: Colors.transparent,
|
||||
child: Stack(alignment: Alignment.center, children: [
|
||||
Text(title, style: Theme.of(context).accentTextTheme.display1),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: children,
|
||||
)
|
||||
]),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
|
|
Loading…
Reference in New Issue