From e2f2e45ac89aa271b828e4a1496b736324e83635 Mon Sep 17 00:00:00 2001 From: zhangmeng1334717033 Date: Tue, 9 Jun 2020 18:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E9=99=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/chatting_api.dart | 15 +++++++++------ lib/loading_page.dart | 25 +++++++++++++++++++++++-- lib/login_page.dart | 5 ++++- pubspec.lock | 41 +++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 3 ++- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/lib/chatting_api.dart b/lib/chatting_api.dart index 272304a..1e4b869 100644 --- a/lib/chatting_api.dart +++ b/lib/chatting_api.dart @@ -3,14 +3,17 @@ import 'package:dio/dio.dart'; Dio dio = new Dio(); -class ChattingApi{ - - - +class ChattingApi { + //登陆提交 + loginSubmit(String username,String password) async { + var result = await dio.get(''); + return result.data; + } //获取通讯录列表 getContactList(String id) async { - var result = await dio.get('http://www.liulongbin.top:3005/api/v2/movie/subject/$id'); + var result = await dio + .get('http://www.liulongbin.top:3005/api/v2/movie/subject/$id'); return result.data; } @@ -25,4 +28,4 @@ class ChattingApi{ var result = await dio.get(''); return result.data; } -} \ No newline at end of file +} diff --git a/lib/loading_page.dart b/lib/loading_page.dart index f1bcb47..e865738 100644 --- a/lib/loading_page.dart +++ b/lib/loading_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; /** * 首页 加载页 @@ -10,6 +11,27 @@ class LoadingPage extends StatefulWidget { class _LoadingPageState extends State { + //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){ + 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 void initState() { super.initState(); @@ -17,8 +39,7 @@ class _LoadingPageState extends State { Future.delayed(Duration(seconds: 3),(){ print("仿微信app页面正在加载中"); //判断是否登录,如果没有登陆则跳转至登录页,如果登录则跳转至聊天页 - Navigator.of(context).pushReplacementNamed("login"); - //Navigator.of(context).pushReplacementNamed("app"); + initData(); }); } diff --git a/lib/login_page.dart b/lib/login_page.dart index 87cdf53..b6b3327 100644 --- a/lib/login_page.dart +++ b/lib/login_page.dart @@ -1,6 +1,7 @@ import 'package:date_format/date_format.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:chatting/chatting_api.dart'; class LoginPag extends StatefulWidget { @override @@ -43,7 +44,8 @@ class _LoginPagState extends State { height: 80, ), buildEditWidget(context), - buildLoginButton() + buildLoginButton(), + ], ), ), @@ -209,6 +211,7 @@ class _LoginPagState extends State { timeInSecForIos: 2, textColor: Colors.white, fontSize: 14.0); + return ChattingApi().loginSubmit(_userNameEditController.text, _pwdEditController.text); } }, child: Text("登录"), diff --git a/pubspec.lock b/pubspec.lock index ad06482..9a62458 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -95,6 +95,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" flutter_webview_plugin: dependency: "direct main" description: @@ -144,6 +149,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.4.0" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.2.0" quiver: dependency: transitive description: @@ -151,6 +163,34 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.3" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.5.7+3" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+10" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.4" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2+7" sky_engine: dependency: transitive description: flutter @@ -221,3 +261,4 @@ packages: version: "3.6.1" sdks: dart: ">=2.7.0 <3.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 45e3b41..36a7c6d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,8 @@ dependencies: date_format: ^1.0.4 dio: ^1.0.9 fluttertoast: ^3.0.3 - + provider: ^3.2.0 + shared_preferences: ^0.5.7+3 dev_dependencies: flutter_test: sdk: flutter