diff --git a/assets/images/ic_password.png b/assets/images/ic_password.png new file mode 100644 index 0000000..3d5abb3 Binary files /dev/null and b/assets/images/ic_password.png differ diff --git a/assets/images/ic_username.png b/assets/images/ic_username.png new file mode 100644 index 0000000..be15d41 Binary files /dev/null and b/assets/images/ic_username.png differ diff --git a/assets/images/jspang.png b/assets/images/jspang.png new file mode 100644 index 0000000..09473b9 Binary files /dev/null and b/assets/images/jspang.png differ diff --git a/lib/chatting_api.dart b/lib/chatting_api.dart new file mode 100644 index 0000000..272304a --- /dev/null +++ b/lib/chatting_api.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import 'package:dio/dio.dart'; + +Dio dio = new Dio(); + +class ChattingApi{ + + + + + //获取通讯录列表 + getContactList(String id) async { + var result = await dio.get('http://www.liulongbin.top:3005/api/v2/movie/subject/$id'); + return result.data; + } + + //获取聊天列表 + getChattingList(String id) async { + var result = await dio.get(''); + return result.data; + } + + //获取当前用户信息 + getCurrentUserInfo(String id) async { + var result = await dio.get(''); + return result.data; + } +} \ No newline at end of file diff --git a/lib/chatting_data_page.dart b/lib/chatting_data_page.dart index f4743ef..9ef60ca 100644 --- a/lib/chatting_data_page.dart +++ b/lib/chatting_data_page.dart @@ -8,8 +8,11 @@ enum MessageType { SYSTEM, PUBLIC, CHAT, GROUP } // 聊天数据 class MessageData { - //id - int id; + //发送者的id + int sendId; + + //接受者的id + int toId; //头像 String avatar; @@ -26,13 +29,16 @@ class MessageData { //消息类型 MessageType type; - MessageData(this.avatar, this.title, this.subTitle, this.time, this.type); + MessageData(this.sendId, this.toId, this.avatar, this.title, this.subTitle, + this.time, this.type); + + } List messageData = [ - new MessageData("http://blogimages.jspang.com/blogtouxiang1.jpg", "张三", "一哥", new DateTime.now(), MessageType.CHAT), - new MessageData("http://blogimages.jspang.com/blogtouxiang1.jpg", "李四", "一哥", new DateTime.now(), MessageType.CHAT), - new MessageData("http://blogimages.jspang.com/blogtouxiang1.jpg", "王麻子", "一哥", new DateTime.now(), MessageType.CHAT), - new MessageData("http://blogimages.jspang.com/blogtouxiang1.jpg", "王五", "一哥", new DateTime.now(), MessageType.CHAT), - new MessageData("http://blogimages.jspang.com/blogtouxiang1.jpg", "赵柳", "一哥", new DateTime.now(), MessageType.CHAT), + new MessageData(12,1,"http://blogimages.jspang.com/blogtouxiang1.jpg", "张三", "一哥", new DateTime.now(), MessageType.CHAT), + new MessageData(12,3,"http://blogimages.jspang.com/blogtouxiang1.jpg", "李四", "一哥", new DateTime.now(), MessageType.CHAT), + new MessageData(1,12,"http://blogimages.jspang.com/blogtouxiang1.jpg", "王麻子", "一哥", new DateTime.now(), MessageType.CHAT), + new MessageData(3,12,"http://blogimages.jspang.com/blogtouxiang1.jpg", "王五", "一哥", new DateTime.now(), MessageType.CHAT), + new MessageData(1,3,"http://blogimages.jspang.com/blogtouxiang1.jpg", "赵柳", "一哥", new DateTime.now(), MessageType.CHAT), ]; \ No newline at end of file diff --git a/lib/chatting_details_page.dart b/lib/chatting_details_page.dart index 21ad5e8..903a074 100644 --- a/lib/chatting_details_page.dart +++ b/lib/chatting_details_page.dart @@ -106,7 +106,6 @@ class _ChattingDetailsState extends State with TickerProviderSt onPressed: _isComposing ? () => _handleSubmitted(_textEditingController.text) : null ), ) - ], ), ), diff --git a/lib/chatting_message_page.dart b/lib/chatting_message_page.dart index 41d0062..9ba4466 100644 --- a/lib/chatting_message_page.dart +++ b/lib/chatting_message_page.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:chatting/chatting_data_page.dart'; @@ -22,15 +23,9 @@ class ChatMessagePage extends StatefulWidget { class _ChatMessagePageState extends State { - @override Widget build(BuildContext context) { - if(widget.messageData.title==null){ - print("11"); - - } - return SizeTransition( sizeFactor: CurvedAnimation( parent: widget.animationController, @@ -42,29 +37,62 @@ class _ChatMessagePageState extends State { } Widget cellContaint (BuildContext context){ + var sendId = widget.messageData.sendId; + var toId = widget.messageData.toId; + var currentId = 12; + if(sendId == currentId){ + print(sendId); + return Container( + padding:const EdgeInsets.fromLTRB(300.0,0.0,10,0.0), + margin: const EdgeInsets.symmetric(vertical: 10.0), + child: Row( + + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Container( + margin: const EdgeInsets.only(right: 16.0), + child: new CircleAvatar(child: new Text(widget.messageData.title[0])), + ), + new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text(widget.messageData.title, style: Theme.of(context).textTheme.subhead), + new Container( + margin: const EdgeInsets.only(top: 5.0), + child: new Text(widget.text, textAlign: TextAlign.right,), + ) + ] + ) + ], + ), + ); + }else{ + return Container( + padding:const EdgeInsets.fromLTRB(0.0,0.0,0.0,0.0), + margin: const EdgeInsets.symmetric(vertical: 10.0), + child: Row( + + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Container( + margin: const EdgeInsets.only(right: 16.0), + child: new CircleAvatar(child: new Text(widget.messageData.title[0])), + ), + new Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + new Text(widget.messageData.title, style: Theme.of(context).textTheme.subhead), + new Container( + margin: const EdgeInsets.only(top: 5.0), + child: new Text(widget.text, textAlign: TextAlign.right,), + ) + ] + ) + ], + ), + ); + } - return Container( - margin: const EdgeInsets.symmetric(vertical: 10.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - new Container( - margin: const EdgeInsets.only(right: 16.0), - child: new CircleAvatar(child: new Text(widget.messageData.title[0])), - ), - new Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - new Text(widget.messageData.title, style: Theme.of(context).textTheme.subhead), - new Container( - margin: const EdgeInsets.only(top: 5.0), - child: new Text(widget.text), - ) - ] - ) - ], - ), - ); } } diff --git a/lib/loading_page.dart b/lib/loading_page.dart index 0c40c61..f1bcb47 100644 --- a/lib/loading_page.dart +++ b/lib/loading_page.dart @@ -16,7 +16,9 @@ class _LoadingPageState extends State { //加载页默认停留三秒 Future.delayed(Duration(seconds: 3),(){ print("仿微信app页面正在加载中"); - Navigator.of(context).pushReplacementNamed("app"); + //判断是否登录,如果没有登陆则跳转至登录页,如果登录则跳转至聊天页 + Navigator.of(context).pushReplacementNamed("login"); + //Navigator.of(context).pushReplacementNamed("app"); }); } diff --git a/lib/login_page.dart b/lib/login_page.dart new file mode 100644 index 0000000..87cdf53 --- /dev/null +++ b/lib/login_page.dart @@ -0,0 +1,245 @@ +import 'package:date_format/date_format.dart'; +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +class LoginPag extends StatefulWidget { + @override + _LoginPagState createState() => _LoginPagState(); +} + +class _LoginPagState extends State { + TextEditingController _pwdEditController; + TextEditingController _userNameEditController; + + final FocusNode _userNameFocusNode = FocusNode(); + final FocusNode _pwdFocusNode = FocusNode(); + + @override + void initState() { + super.initState(); + + _pwdEditController = TextEditingController(); + _userNameEditController = TextEditingController(); + + _pwdEditController.addListener(() => setState(() => {})); + _userNameEditController.addListener(() => setState(() => {})); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(''), + centerTitle: true, + backgroundColor: Colors.blue[400], + elevation: 0, + ), + body: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + buildTopWidget(context), + SizedBox( + height: 80, + ), + buildEditWidget(context), + buildLoginButton() + ], + ), + ), + ); + } + + /// 头部 + Widget buildTopWidget(BuildContext context) { + double height = 200.0; + double width = MediaQuery.of(context).size.width; + print(width); + return Container( + width: width, + height: height, + color: Colors.blue[400], + child: Stack( + overflow: Overflow.visible, // 超出部分显示 + children: [ + Positioned( + left: (width - 90) / 2.0, + top: height - 45, + child: Container( + width: 90.0, + height: 90.0, + decoration: BoxDecoration( + ///阴影 + boxShadow: [ + BoxShadow(color: Theme.of(context).cardColor, blurRadius: 4.0) + ], + ///形状 + shape: BoxShape.circle, + ///图片 + image: DecorationImage( + fit: BoxFit.cover, + image: NetworkImage( + 'https://upload.jianshu.io/users/upload_avatars/2416132/dd23e2841509.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96/format/webp'), + ), + ), + ), + ) + ], + ), + ); + } + + Widget buildEditWidget(BuildContext context) { + return Container( + margin: EdgeInsets.only(left: 15, right: 15), + child: Column( + children: [ + buildLoginNameTextField(), + SizedBox(height: 20.0), + buildPwdTextField(), + ], + ), + ); + } + + Widget buildLoginNameTextField() { + return Container( + height: 40, + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: BorderRadius.all(Radius.circular(20.0)), + ), + child: Stack( + children: [ + Positioned( + left: 16, + top: 11, + width: 18, + height: 18, + child: Image.asset('assets/images/ic_username.png'), + ), + Positioned( + left: 45, + top: 10, + bottom: 10, + width: 1, + child: Container( + color: Colors.black, + ), + ), + Positioned( + left: 55, + right: 10, + top: 10, + height: 30, + child: TextField( + controller: _userNameEditController, + focusNode: _userNameFocusNode, + decoration: InputDecoration( + hintText: "请输入用户名", + border: InputBorder.none, + ), + style: TextStyle(fontSize: 14), + ), + ) + ], + ), + ); + } + + Widget buildPwdTextField() { + return Container( + height: 40, + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: BorderRadius.all(Radius.circular(20.0)), + ), + child: Stack( + children: [ + Positioned( + left: 16, + top: 11, + width: 18, + height: 18, + child: Image.asset('assets/images/ic_password.png'), + ), + Positioned( + left: 45, + top: 10, + bottom: 10, + width: 1, + child: Container( + color: Colors.black, + ), + ), + Positioned( + left: 55, + right: 10, + top: 10, + height: 30, + child: TextField( + controller: _pwdEditController, + focusNode: _pwdFocusNode, + decoration: InputDecoration( + hintText: "请输入密码", + border: InputBorder.none, + ), + style: TextStyle(fontSize: 14), + obscureText: true, + + /// 设置密码 + ), + ) + ], + )); + } + + Widget buildLoginButton() { + return Container( + margin: EdgeInsets.only(top: 40, left: 10, right: 10), + padding: EdgeInsets.all(0), + width: MediaQuery.of(context).size.width - 20, + height: 40, + child: RaisedButton( + onPressed: () { + if (checkInput()) { + Fluttertoast.showToast( + msg: "登录成功", + gravity: ToastGravity.CENTER, + timeInSecForIos: 2, + textColor: Colors.white, + fontSize: 14.0); + } + }, + child: Text("登录"), + color: Colors.blue[400], + textColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20.0)), + ), + ), + ); + } + + bool checkInput() { + if (_userNameEditController.text.length == 0) { + Fluttertoast.showToast( + msg: "请输入用户名", + gravity: ToastGravity.CENTER, + timeInSecForIos: 2, + textColor: Colors.white, + fontSize: 14.0); + + return false; + } else if (_pwdEditController.text.length == 0) { + Fluttertoast.showToast( + msg: "请输入密码", + gravity: ToastGravity.CENTER, + timeInSecForIos: 2, + textColor: Colors.white, + fontSize: 14.0); + return false; + } + return true; + } +} diff --git a/lib/main.dart b/lib/main.dart index 6a75f46..2107b9b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:chatting/loading_page.dart'; import 'package:chatting/app_page.dart'; +import 'package:chatting/login_page.dart'; void main(){ return runApp(MyApp()); @@ -18,7 +19,10 @@ class MyApp extends StatelessWidget { routes: { 'app' : (BuildContext context){ return new App(); - } + }, + 'login' : (BuildContext context){ + return new LoginPag(); + }, }, //指定首页,默认为加载页 home: LoadingPage(), diff --git a/pubspec.lock b/pubspec.lock index c0add7d..ad06482 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -50,6 +50,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" + cookie_jar: + dependency: transitive + description: + name: cookie_jar + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.8" crypto: dependency: transitive description: @@ -71,6 +78,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.8" + dio: + dependency: "direct main" + description: + name: dio + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.17" flutter: dependency: "direct main" description: flutter @@ -88,6 +102,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.3.11" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.3" image: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 60ddc19..45e3b41 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,6 +30,9 @@ dependencies: cupertino_icons: ^0.1.3 flutter_webview_plugin: ^0.3.4 date_format: ^1.0.4 + dio: ^1.0.9 + fluttertoast: ^3.0.3 + dev_dependencies: flutter_test: sdk: flutter @@ -68,7 +71,10 @@ flutter: - assets/images/ic_new_friend.png - assets/images/ic_label.png - assets/images/ic_group.png + - assets/images/ic_username.png + - assets/images/ic_password.png - assets/images/icon_right.png + - assets/images/jspang.png fonts: - family: appIconFonts