修改登陆页面
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:flutter/material.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'chatting_data_page.dart';
|
||||||
|
|
||||||
Dio dio = new Dio();
|
Dio dio = new Dio();
|
||||||
|
|
||||||
class ChattingApi {
|
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 {
|
loginSubmit(String username, String password) async {
|
||||||
var result = await dio.get('');
|
print(username);
|
||||||
return result.data;
|
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 {
|
getContactList() async {
|
||||||
var result = await dio
|
|
||||||
.get('http://www.liulongbin.top:3005/api/v2/movie/subject/$id');
|
|
||||||
return result.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取聊天列表
|
//获取聊天列表
|
||||||
getChattingList(String id) async {
|
getChattingList() async {
|
||||||
var result = await dio.get('');
|
token = await dataManipulation_get('token');
|
||||||
return result.data;
|
|
||||||
|
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('');
|
var result = await dio.get('');
|
||||||
return result.data;
|
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> {
|
class _LoadingPageState extends State<LoadingPage> {
|
||||||
|
|
||||||
//0 未登录 ,1 已登录
|
//0 未登录 ,1 已登录
|
||||||
|
|
||||||
void initData() async {
|
void initData() async {
|
||||||
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
|
||||||
int loginStatus=prefs.getInt('loginStatus') ?? 0;
|
int loginStatus=prefs.getInt('loginStatus') ?? 0;
|
||||||
print(prefs.getInt('current_num'));
|
print(prefs.getInt('current_num'));
|
||||||
if(loginStatus == 0){
|
if(loginStatus == 1){
|
||||||
Navigator.of(context).pushReplacementNamed("login");
|
Navigator.of(context).pushReplacementNamed("login");
|
||||||
}else{
|
}else{
|
||||||
loginStatus=1;
|
loginStatus=1;
|
||||||
Navigator.of(context).pushReplacementNamed("app");
|
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
|
@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:date_format/date_format.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:chatting/chatting_api.dart';
|
import 'package:chatting/chatting_api.dart';
|
||||||
|
|
||||||
|
final ChattingApi chattingApi = ChattingApi();
|
||||||
|
|
||||||
class LoginPag extends StatefulWidget {
|
class LoginPag extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_LoginPagState createState() => _LoginPagState();
|
_LoginPagState createState() => _LoginPagState();
|
||||||
|
|
@ -45,7 +49,6 @@ class _LoginPagState extends State<LoginPag> {
|
||||||
),
|
),
|
||||||
buildEditWidget(context),
|
buildEditWidget(context),
|
||||||
buildLoginButton(),
|
buildLoginButton(),
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -58,8 +61,8 @@ class _LoginPagState extends State<LoginPag> {
|
||||||
double width = MediaQuery.of(context).size.width;
|
double width = MediaQuery.of(context).size.width;
|
||||||
print(width);
|
print(width);
|
||||||
return Container(
|
return Container(
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
color: Colors.blue[400],
|
color: Colors.blue[400],
|
||||||
child: Stack(
|
child: Stack(
|
||||||
overflow: Overflow.visible, // 超出部分显示
|
overflow: Overflow.visible, // 超出部分显示
|
||||||
|
|
@ -75,8 +78,10 @@ class _LoginPagState extends State<LoginPag> {
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(color: Theme.of(context).cardColor, blurRadius: 4.0)
|
BoxShadow(color: Theme.of(context).cardColor, blurRadius: 4.0)
|
||||||
],
|
],
|
||||||
|
|
||||||
///形状
|
///形状
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
|
|
||||||
///图片
|
///图片
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
|
|
@ -211,7 +216,7 @@ class _LoginPagState extends State<LoginPag> {
|
||||||
timeInSecForIos: 2,
|
timeInSecForIos: 2,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
fontSize: 14.0);
|
fontSize: 14.0);
|
||||||
return ChattingApi().loginSubmit(_userNameEditController.text, _pwdEditController.text);
|
loginProcessing();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text("登录"),
|
child: Text("登录"),
|
||||||
|
|
@ -245,4 +250,34 @@ class _LoginPagState extends State<LoginPag> {
|
||||||
}
|
}
|
||||||
return true;
|
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"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.12"
|
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:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ dependencies:
|
||||||
dio: ^1.0.9
|
dio: ^1.0.9
|
||||||
fluttertoast: ^3.0.3
|
fluttertoast: ^3.0.3
|
||||||
provider: ^3.2.0
|
provider: ^3.2.0
|
||||||
|
json_annotation: ^0.2.3
|
||||||
shared_preferences: ^0.5.7+3
|
shared_preferences: ^0.5.7+3
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue