Skip to content

Commit

Permalink
finish collect and message
Browse files Browse the repository at this point in the history
  • Loading branch information
ali322 committed Jul 2, 2018
1 parent 581097c commit 2e60401
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 25 deletions.
42 changes: 41 additions & 1 deletion lib/widget/collect.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "package:flutter/material.dart";
import "../store/view_model/collect.dart";
import "../store/model/topic.dart";

class CollectScene extends StatelessWidget{
final CollectViewModel vm;
Expand All @@ -9,8 +10,47 @@ class CollectScene extends StatelessWidget{

@override
Widget build(BuildContext context) {
final topics = vm.collects;
return new Scaffold(
body: new Center(child: new Text('collect')),
appBar: new AppBar(
brightness: Brightness.dark,
elevation: 0.0,
title: new Text('收藏', style: new TextStyle(color: Colors.white, fontSize: 18.0)),
),
body: new ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: topics.length,
itemBuilder: (BuildContext context, int i) => _renderRow(context, topics[i])
)
);
}

Widget _renderRow(BuildContext context, Topic topic) {
ListTile title = new ListTile(
leading: new SizedBox(
width: 30.0,
height: 30.0,
child: new Image.network(topic.authorAvatar.startsWith('//') ? 'http:${topic.authorAvatar}' : topic.authorAvatar)
),
title: new Text(topic.authorName),
subtitle: new Row(
children: <Widget>[
new Text(DateTime.parse(topic.lastReplyAt).toString().split('.')[0])
],
),
);
return new InkWell(
child: new Column(
children: <Widget>[
title,
new Container(
padding: const EdgeInsets.all(10.0),
alignment: Alignment.centerLeft,
child: new Text(topic.title)
)
],
),
);
}
}
33 changes: 15 additions & 18 deletions lib/widget/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,30 @@ class IndexScene extends StatefulWidget{
}

class IndexState extends State<IndexScene> {
List scenes;
List _renderScenes(bool isLogined) {
final bool isLogined = widget.vm.auth["isLogined"];
return <Widget>[
new TopicsContainer(vm: widget.vm),
isLogined ? new CollectContainer(vm: widget.vm) : new LoginScene(),
isLogined ? new MessageContainer(vm: widget.vm,) : new LoginScene(),
isLogined ? new MeContainer(vm: widget.vm,) : new LoginScene()
];
}

@override
void initState() {
super.initState();
final int tabIndex = widget.vm.tabIndex;
Widget build(BuildContext context) {
final bool isLogined = widget.vm.auth["isLogined"];
scenes = <Widget>[
new TopicsContainer(vm: widget.vm),
isLogined ? new CollectContainer(vm: widget.vm) : new LoginScene(),
isLogined ? new MessageContainer(vm: widget.vm,) : new LoginScene(),
isLogined ? new MeContainer(vm: widget.vm,) : new LoginScene()
];
final currentScene = scenes[tabIndex];
final List scenes = _renderScenes(isLogined);
final int tabIndex = widget.vm.tabIndex;
final Function setTab = widget.vm.selectTab;

final currentScene = scenes[0];
if (currentScene is InitializeContainer) {
if (currentScene.getInitialized() == false) {
currentScene.initialize();
currentScene.setInitialized();
}
}
}

@override
Widget build(BuildContext context) {
final bool isLogined = widget.vm.auth["isLogined"];
final int tabIndex = widget.vm.tabIndex;
final Function setTab = widget.vm.selectTab;

return new Scaffold(
bottomNavigationBar: new CupertinoTabBar(
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoginState extends State<LoginScene>{
converter: (Store<RootState> store) {
return (String accessToken) {
store.dispatch(new StartLogin(accessToken, () {
Navigator.of(context).pushNamed("/");
// Navigator.of(context).pushNamed("/");
store.dispatch(new SelectTab(3));
}));
};
Expand Down
118 changes: 116 additions & 2 deletions lib/widget/me.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "package:flutter/material.dart";
import "../store/view_model/me.dart";
import "./recent_replies.dart";
import "./recent_topics.dart";

class MeScene extends StatelessWidget{
final MeViewModel vm;
Expand All @@ -9,19 +11,131 @@ class MeScene extends StatelessWidget{
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Color(0xFFDEDEDE),
appBar: new AppBar(
brightness: Brightness.dark,
elevation: 0.0,
title: new Text('我的', style: new TextStyle(color: Colors.white, fontSize: 14.0))
title: new Text('我的', style: new TextStyle(color: Colors.white, fontSize: 18.0))
),
body: new Column(
children: <Widget>[

_renderTitle(context),
new Divider(
color: Color(0xFFDEDEDE),
),
_renderMenus(context),
new Divider(
color: Color(0xFFDEDEDE),
),
_renderLogout(context)
],
)
);
}

Widget _renderTitle(BuildContext context) {
return new Container(
padding: const EdgeInsets.symmetric(vertical: 18.0, horizontal: 10.0),
decoration: new BoxDecoration(
color: Colors.white
),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new CircleAvatar(
radius: 35.0,
backgroundImage: new NetworkImage(vm.me.avatar),
),
new Padding(
padding: const EdgeInsets.only(left: 20.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(vm.me.username, style: new TextStyle(fontSize: 18.0)),
new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: new Text(vm.me.createdAt, style: new TextStyle(fontSize: 14.0, color: Color(0xFFF666666)))
)
],
),
)
],
)
);
}

Widget _renderMenus(BuildContext context) {
return new Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
decoration: new BoxDecoration(
color: Colors.white
),
child: new ListView(
shrinkWrap: true,
children: ListTile.divideTiles(
context: context,
tiles: [
new ListTile(
contentPadding: const EdgeInsets.all(0.0),
title: new Row(
children: <Widget>[
new Icon(Icons.description, color: Color(0xFF999999)),
new Padding(
padding: const EdgeInsets.only(left: 12.0),
child:new Text('最近主题')
)
],
),
trailing: new Icon(Icons.arrow_forward_ios, size: 14.0),
onTap: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) {
return new RecentTopicsScene(topics: vm.me.recentTopics);
}
));
},
),
new ListTile(
contentPadding: const EdgeInsets.all(0.0),
title: new Row(
children: <Widget>[
new Icon(Icons.comment, color: Color(0xFF999999)),
new Padding(
padding: const EdgeInsets.only(left: 12.0),
child:new Text('最近回复')
)
],
),
trailing: new Icon(Icons.arrow_forward_ios, size: 14.0),
onTap: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) {
return new RecentRepliesScene(replies: vm.me.recentReplies);
}
));
},
)
]).toList()
)
);
}

Widget _renderLogout(BuildContext context) {
return new Row(
children: <Widget>[
new Expanded(
child: new Container(
height: 40.0,
decoration: new BoxDecoration(
color: Colors.white
),
alignment: Alignment.center,
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0, left: 10.0, right: 10.0),
child: new Text('退出登陆', style: new TextStyle(fontSize: 16.0))
)
)
]
);
}
}
95 changes: 93 additions & 2 deletions lib/widget/message.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,107 @@
import "package:flutter/material.dart";
import "../store/view_model/message.dart";
import "../store/model/message.dart";

class MessageScene extends StatelessWidget{
class MessageScene extends StatefulWidget{
final MessagesViewModel vm;

MessageScene({Key key, @required this.vm}):super(key: key);

@override
State<StatefulWidget> createState() {
return new MessageState();
}
}

class MessageState extends State<MessageScene> with TickerProviderStateMixin{
TabController _tabController;
List<Tab> _tabs;

@override
void dispose() {
super.dispose();
_tabController.dispose();
}

@override
Widget build(BuildContext context) {
final messages = widget.vm.messages;
List<Widget> _renderTabViews() {
final _tabViews = <Widget>[];
messages.forEach((k, v) {
_tabViews.add(new ListView.builder(
physics: new NeverScrollableScrollPhysics(),
// shrinkWrap: true,
itemCount: v.length,
itemBuilder: (BuildContext context, int i) => _renderRow(context, v[i]),
));
});
return _tabViews;
}

_tabs = <Tab>[];
messages.keys.forEach((v) {
_tabs.add(new Tab(text: v == 'read' ? '已读' : '未读'));
});
_tabController = new TabController(vsync: this, length: _tabs.length);
return new Scaffold(
body: new Center(child: new Text('message'))
appBar: new AppBar(
brightness: Brightness.dark,
elevation: 0.0,
titleSpacing: 0.0,
bottom: null,
title: new Align(
alignment: Alignment.bottomCenter,
child: new TabBar(
labelColor: Colors.white,
tabs: _tabs,
controller: _tabController,
)
)
),
body: new TabBarView(
controller: _tabController,
children: _renderTabViews(),
)
);
}

Widget _renderRow(BuildContext context, Message message) {
ListTile title = new ListTile(
leading: new SizedBox(
width: 30.0,
height: 30.0,
child: new Image.network(message.authorAvatar.startsWith('//') ? 'http:${message.authorAvatar}' : message.authorAvatar)
),
title: new Text(message.authorName),
subtitle: new Row(
children: <Widget>[
new Text(DateTime.parse(message.replyAt).toString().split('.')[0])
],
),
);
return new Column(
children: <Widget>[
title,
new Container(
padding: const EdgeInsets.all(10.0),
alignment: Alignment.centerLeft,
child: new RichText(
text: new TextSpan(
text: '评论了 ',
style: new TextStyle(color: Colors.lightBlue),
children: <TextSpan>[
new TextSpan(text: message.topicTitle, style: DefaultTextStyle.of(context).style)
]
),
),
),
new Container(
padding: const EdgeInsets.all(10.0),
alignment: Alignment.centerLeft,
child: new Text(message.content),
),
],
);
}
}
Loading

0 comments on commit 2e60401

Please sign in to comment.