Flutter实战一Flutter聊天应用(十六)
在上一篇文章《Flutter实战一Flutter聊天应用(十五)》中,我们完成了登陆屏幕。在用户登陆成功后,会在本地创建一个 在 import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:async';
import 'dart:io';
import 'sign_in.dart';
import 'group_chat_list.dart';
void main() {
_getLandingFile().then((onValue) {
runApp(new TalkcasuallyApp(onValue.existsSync()));
});
}
Future<File> _getLandingFile() async {
String dir = (await getApplicationDocumentsDirectory()).path;
return new File('$dir/LandingInformation');
}
class TalkcasuallyApp extends StatelessWidget {
TalkcasuallyApp(this.landing);
final bool landing;
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: '谈天论地',home: landing ? new GroupChatList() : new SignIn());
}
}
在上面代码中有一个 import 'package:flutter/material.dart';
class GroupChatList extends StatefulWidget {
@override
State createState() => new _GroupChatListState();
}
class _GroupChatListState extends State<GroupChatList> {
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("谈天论地"),),body: new Text("聊天列表"),floatingActionButton: new FloatingActionButton(
onPressed: null,child: new Icon(Icons.add)));
}
}
在用户进入聊天列表屏幕时,我们需要读取 在 //...
import 'package:path_provider/path_provider.dart';
import 'dart:async';
import 'dart:convert';
import 'dart:io';
//...
class _GroupChatListState extends State<GroupChatList> {
String name = "null";
String phone = "null";
String email = "null";
@override
void initState() {
super.initState();
_readLoginData().then((Map onValue) {
setState(() {
name = onValue["name"];
phone = onValue["phone"];
email = onValue["email"];
});
});
}
Future<Map> _readLoginData() async {
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/LandingInformation');
String data = await file.readAsString();
Map json = new JsonDecoder().convert(data);
return json;
}
//...
}
获取用户信息后,我们可以使用 首先我们先写一个自定义的 class _GroupChatListState extends State<GroupChatList> {
//...
Widget _drawerOption(Icon icon,String name) {
return new Container(
padding: const EdgeInsets.only(top: 22.0),child: new Row(
children: <Widget>[
new Container(
padding: const EdgeInsets.only(right: 28.0),child: icon),new Text(name)
],);
}
//...
}
然后在 class _GroupChatListState extends State<GroupChatList> {
//...
Widget build(BuildContext context) {
//...
Drawer drawer = new Drawer(
child: new ListView(
children: <Widget>[
new DrawerHeader(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Container(
padding: const EdgeInsets.only(right: 12.0),child: new CircleAvatar(
child: new Text(name[0]),new Column(
crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
new Text(
name,textScaleFactor: 1.2,new Text(phone)
],)
],_drawerOption(new Icon(Icons.account_circle),"个人资料"),_drawerOption(new Icon(Icons.settings),"应用设置"),],))
],));
//...
}
}
最后我们再修改一下 class _GroupChatListState extends State<GroupChatList> {
//...
Widget build(BuildContext context) {
//...
return new Scaffold(
appBar: new AppBar(
title: new Text("谈天论地"),drawer: drawer,body: new Center(
child: new Text("聊天列表"),child: new Icon(Icons.add)));
}
}
大家可以在GitHub上直接查看group_chat_list.dart文件的代码。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 打开 VirtualBox-5.2 出错:获取 VirtualBox COM 对象失败
- ruby-on-rails – 在Rails 3中如何解析ISO8601日期字符串以
- application.xml中配置list
- arrays – 计算Int Optionals的arrary中的nil值的数量
- C – int数组到char *的转换
- 如何收集大型Makefile项目的所有依赖项?
- objective-c – SoundCloud API iOS,无共享 – 只收听
- NoSQL:MongoDB或BigTable并不总是“可用”
- arrays – Swift 4无法使用类型的参数列表调用’index’
- NoSQL -- Mongodb 安装 使用 副本集 备份恢复