Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter-chat
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
songchuancai
flutter-chat
Commits
6fcbd5a6
提交
6fcbd5a6
authored
11月 08, 2024
作者:
songchuancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
对接登录接口
上级
a89b102e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
59 行增加
和
9 行删除
+59
-9
user.dart
lib/models/user.dart
+8
-1
login_page.dart
lib/pages/login_page.dart
+24
-4
api_service.dart
lib/services/api_service.dart
+24
-0
pubspec.lock
pubspec.lock
+2
-2
pubspec.yaml
pubspec.yaml
+1
-2
没有找到文件。
lib/models/user.dart
浏览文件 @
6fcbd5a6
class
User
{
class
User
{
final
String
username
;
final
String
username
;
final
String
password
;
final
String
password
;
final
String
?
token
;
User
({
required
this
.
username
,
required
this
.
password
});
User
({
required
this
.
username
,
required
this
.
password
,
this
.
token
,
});
Map
<
String
,
dynamic
>
toJson
()
{
Map
<
String
,
dynamic
>
toJson
()
{
return
{
return
{
'username'
:
username
,
'username'
:
username
,
'password'
:
password
,
'password'
:
password
,
'token'
:
token
,
};
};
}
}
...
@@ -15,6 +21,7 @@ class User {
...
@@ -15,6 +21,7 @@ class User {
return
User
(
return
User
(
username:
json
[
'username'
],
username:
json
[
'username'
],
password:
json
[
'password'
],
password:
json
[
'password'
],
token:
json
[
'token'
],
);
);
}
}
}
}
lib/pages/login_page.dart
浏览文件 @
6fcbd5a6
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:allen/models/user.dart'
;
import
'package:allen/models/user.dart'
;
import
'package:allen/services/storage_service.dart'
;
import
'package:allen/services/storage_service.dart'
;
import
'package:allen/services/api_service.dart'
;
class
LoginPage
extends
StatefulWidget
{
class
LoginPage
extends
StatefulWidget
{
const
LoginPage
({
super
.
key
});
const
LoginPage
({
super
.
key
});
...
@@ -24,11 +25,30 @@ class _LoginPageState extends State<LoginPage> {
...
@@ -24,11 +25,30 @@ class _LoginPageState extends State<LoginPage> {
return
;
return
;
}
}
final
user
=
User
(
username:
username
,
password:
password
);
try
{
await
StorageService
.
saveUser
(
user
);
final
response
=
await
ApiService
.
login
(
username
,
password
);
if
(
mounted
)
{
if
(
response
[
'result'
]
==
'success'
)
{
Navigator
.
of
(
context
).
pushReplacementNamed
(
'/home'
);
final
token
=
response
[
'data'
];
final
user
=
User
(
username:
username
,
password:
password
,
token:
token
);
await
StorageService
.
saveUser
(
user
);
if
(
mounted
)
{
Navigator
.
of
(
context
).
pushReplacementNamed
(
'/home'
);
}
}
else
{
if
(
mounted
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
'登录失败,请检查用户名和密码'
)),
);
}
}
}
catch
(
e
)
{
if
(
mounted
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
'登录失败,请稍后重试'
)),
);
}
}
}
}
}
...
...
lib/services/api_service.dart
0 → 100644
浏览文件 @
6fcbd5a6
import
'dart:convert'
;
import
'package:http/http.dart'
as
http
;
class
ApiService
{
static
const
String
baseUrl
=
'https://knowledge-web.apps.iytcloud.com/console/api'
;
static
Future
<
Map
<
String
,
dynamic
>>
login
(
String
email
,
String
password
)
async
{
final
response
=
await
http
.
post
(
Uri
.
parse
(
'
$baseUrl
/login/'
),
headers:
{
'Content-Type'
:
'application/json'
,
'Accept'
:
'application/json'
,
},
body:
jsonEncode
({
'email'
:
email
,
'password'
:
password
,
}),
);
return
jsonDecode
(
response
.
body
);
}
}
pubspec.lock
浏览文件 @
6fcbd5a6
...
@@ -132,10 +132,10 @@ packages:
...
@@ -132,10 +132,10 @@ packages:
dependency: "direct main"
dependency: "direct main"
description:
description:
name: http
name: http
sha256:
"5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
sha256:
b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "
0.13.6
"
version: "
1.2.2
"
http_parser:
http_parser:
dependency: transitive
dependency: transitive
description:
description:
...
...
pubspec.yaml
浏览文件 @
6fcbd5a6
...
@@ -30,13 +30,12 @@ environment:
...
@@ -30,13 +30,12 @@ environment:
dependencies
:
dependencies
:
flutter
:
flutter
:
sdk
:
flutter
sdk
:
flutter
http
:
^1.1.0
# The following adds the Cupertino Icons font to your application.
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons
:
^1.0.2
cupertino_icons
:
^1.0.2
speech_to_text
:
^6.1.1
speech_to_text
:
^6.1.1
http
:
^0.13.5
flutter_tts
:
^3.6.3
flutter_tts
:
^3.6.3
animate_do
:
^3.0.2
animate_do
:
^3.0.2
shared_preferences
:
^2.0.15
shared_preferences
:
^2.0.15
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论