修改登陆页面
parent
e2f2e45ac8
commit
6d89211df9
|
|
@ -1,26 +1,71 @@
|
|||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:chatting/chatting_api_result.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'chatting_data_page.dart';
|
||||
|
||||
Dio dio = new Dio();
|
||||
|
||||
class ChattingApi {
|
||||
Options options = Options(headers: {HttpHeaders.acceptHeader: "accept: application/json"});
|
||||
String token;
|
||||
int time;
|
||||
String message;
|
||||
ChattingApiResult chattingApiResult ;
|
||||
Map<String,Object> map = new Map<String,Object>();
|
||||
List<MessageData> list;
|
||||
|
||||
//登陆提交
|
||||
loginSubmit(String username, String password) async {
|
||||
var result = await dio.get('');
|
||||
return result.data;
|
||||
print(username);
|
||||
print(password);
|
||||
FormData formData = new FormData.from({
|
||||
'username':username,
|
||||
'password':password,
|
||||
});
|
||||
var result = await dio.post(
|
||||
'http://customer.dsd361.com/login',
|
||||
data: formData,
|
||||
options: options
|
||||
);
|
||||
print(result.data);
|
||||
token=result.data['token'];
|
||||
time=result.data['loginTime'];
|
||||
message=result.data['message'];
|
||||
chattingApiResult= new ChattingApiResult(token,time,message,null,null,null);
|
||||
print(chattingApiResult.runtimeType);
|
||||
return chattingApiResult ;
|
||||
}
|
||||
|
||||
//获取通讯录列表
|
||||
getContactList(String id) async {
|
||||
var result = await dio
|
||||
.get('http://www.liulongbin.top:3005/api/v2/movie/subject/$id');
|
||||
return result.data;
|
||||
getContactList() async {
|
||||
}
|
||||
|
||||
//获取聊天列表
|
||||
getChattingList(String id) async {
|
||||
var result = await dio.get('');
|
||||
return result.data;
|
||||
getChattingList() async {
|
||||
token = await dataManipulation_get('token');
|
||||
|
||||
FormData formData = new FormData.from({
|
||||
'token':token
|
||||
});
|
||||
var response = await dio.post('http://customer.dsd361.com/newchattings/selectChattingeFriebdList',data: formData);
|
||||
List result=response.data;
|
||||
list = new List();
|
||||
result.forEach((item) {
|
||||
int sendId =int.parse(item['send_id']);
|
||||
int receiveId =item['receiveId'];
|
||||
String photoUrl =item['photoUrl'];
|
||||
String user_name =item['user_name'];
|
||||
String content =item['lastOne_chattinglog']['content'];
|
||||
int cl_addTime =item['cl_addTime'];
|
||||
MessageData messageData =new MessageData(sendId, receiveId,"http://blogimages.jspang.com/blogtouxiang1.jpg", user_name, content, DateTime.fromMillisecondsSinceEpoch(cl_addTime), MessageType.CHAT);
|
||||
list.add(messageData);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
//获取当前用户信息
|
||||
|
|
@ -28,4 +73,37 @@ class ChattingApi {
|
|||
var result = await dio.get('');
|
||||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步 数据操作
|
||||
*/
|
||||
void dataManipulation_set(String key, var value) async {
|
||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||
prefs.setString(key, value); //存储数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步 数据操作
|
||||
*/
|
||||
void dataManipulation_setint(String key, var value) async {
|
||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||
prefs.setInt(key, value); //存储数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步 数据操作
|
||||
*/
|
||||
dataManipulation_get(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||
var value = prefs.get(key); //获取数据
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步 数据操作
|
||||
*/
|
||||
void dataManipulation_remove(String key, var value) async {
|
||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||
prefs.remove(key); //删除数据
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
class ChattingApiResult extends Object{
|
||||
|
||||
String token;
|
||||
|
||||
int time;
|
||||
|
||||
String message;
|
||||
|
||||
int sendId;
|
||||
|
||||
int receiveId;
|
||||
|
||||
String content;
|
||||
|
||||
ChattingApiResult(this.token, this.time, this.message, this.sendId, this.receiveId, this.content);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChattingApiResult{token: $token, time: $time, message: $message, sendId: $sendId, receiveId: $receiveId, content: $content}';
|
||||
}
|
||||
}
|
||||
|
|
@ -12,24 +12,16 @@ class LoadingPage extends StatefulWidget {
|
|||
class _LoadingPageState extends State<LoadingPage> {
|
||||
|
||||
//0 未登录 ,1 已登录
|
||||
|
||||
void initData() async {
|
||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||
int loginStatus=prefs.getInt('loginStatus') ?? 0;
|
||||
print(prefs.getInt('current_num'));
|
||||
if(loginStatus == 0){
|
||||
if(loginStatus == 1){
|
||||
Navigator.of(context).pushReplacementNamed("login");
|
||||
}else{
|
||||
loginStatus=1;
|
||||
Navigator.of(context).pushReplacementNamed("app");
|
||||
}
|
||||
|
||||
/*prefs.setInt('current_num', 999); //存储数据
|
||||
var currentNum = prefs.getInt('current_num') ?? 0; //读取数据,默认为0
|
||||
print('读取数据 $currentNum');
|
||||
prefs.remove('current_num');//删除数据
|
||||
var delCurrentNum = prefs.getInt('current_num') ?? 0; //读取数据,默认为0
|
||||
print('删除数据 $delCurrentNum');*/
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import 'package:chatting/chatting_api_result.dart';
|
||||
import 'dart:convert' as convert;
|
||||
import 'package:date_format/date_format.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:chatting/chatting_api.dart';
|
||||
|
||||
final ChattingApi chattingApi = ChattingApi();
|
||||
|
||||
class LoginPag extends StatefulWidget {
|
||||
@override
|
||||
_LoginPagState createState() => _LoginPagState();
|
||||
|
|
@ -45,7 +49,6 @@ class _LoginPagState extends State<LoginPag> {
|
|||
),
|
||||
buildEditWidget(context),
|
||||
buildLoginButton(),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -75,8 +78,10 @@ class _LoginPagState extends State<LoginPag> {
|
|||
boxShadow: [
|
||||
BoxShadow(color: Theme.of(context).cardColor, blurRadius: 4.0)
|
||||
],
|
||||
|
||||
///形状
|
||||
shape: BoxShape.circle,
|
||||
|
||||
///图片
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
|
|
@ -211,7 +216,7 @@ class _LoginPagState extends State<LoginPag> {
|
|||
timeInSecForIos: 2,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0);
|
||||
return ChattingApi().loginSubmit(_userNameEditController.text, _pwdEditController.text);
|
||||
loginProcessing();
|
||||
}
|
||||
},
|
||||
child: Text("登录"),
|
||||
|
|
@ -245,4 +250,34 @@ class _LoginPagState extends State<LoginPag> {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void loginProcessing() async{
|
||||
String username = _userNameEditController.text;
|
||||
String password = _pwdEditController.text;
|
||||
ChattingApiResult result =await chattingApi.loginSubmit(username, password);
|
||||
String token = result.token;
|
||||
String message = result.message;
|
||||
if (token != null) {
|
||||
Fluttertoast.showToast(
|
||||
msg: "登录成功",
|
||||
gravity: ToastGravity.CENTER,
|
||||
timeInSecForIos: 2,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0);
|
||||
//存放用户信息
|
||||
chattingApi.dataManipulation_set('token', token);
|
||||
//存放用户的状态
|
||||
chattingApi.dataManipulation_setint('loginStatus', 1);
|
||||
//跳转至home页
|
||||
Navigator.of(context).pushReplacementNamed("app");
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: message,
|
||||
gravity: ToastGravity.CENTER,
|
||||
timeInSecForIos: 2,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0);
|
||||
}
|
||||
// return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,6 +121,13 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.12"
|
||||
json_annotation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: json_annotation
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.2.9+1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ dependencies:
|
|||
dio: ^1.0.9
|
||||
fluttertoast: ^3.0.3
|
||||
provider: ^3.2.0
|
||||
json_annotation: ^0.2.3
|
||||
shared_preferences: ^0.5.7+3
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Reference in New Issue