Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
9c6fe63b
提交
9c6fe63b
authored
4月 24, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
格式化代码
上级
9254a4f2
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
110 行增加
和
126 行删除
+110
-126
global.dart
lib/global.dart
+21
-24
main.dart
lib/main.dart
+44
-46
storage.dart
lib/services/storage.dart
+3
-11
config.dart
lib/store/config.dart
+2
-4
user.dart
lib/store/user.dart
+19
-18
theme.dart
lib/theme.dart
+21
-23
没有找到文件。
lib/global.dart
浏览文件 @
9c6fe63b
...
...
@@ -9,6 +9,7 @@ import 'package:flutter_book/utils/index.dart';
import
'package:get/get.dart'
;
import
'apis/index.dart'
;
class
Global
{
static
Future
<
void
>
init
()
async
{
// 确保 Flutter 绑定已经初始化
...
...
@@ -20,7 +21,7 @@ class Global {
// 检测网络变化
Connectivity
().
onConnectivityChanged
.
listen
((
ConnectivityResult
result
)
{
Console
.
log
(
'网络变化--------------------------------
$result
'
);
if
(
result
!=
ConnectivityResult
.
none
&&
UserStore
.
to
.
isLogin
)
{
if
(
result
!=
ConnectivityResult
.
none
&&
UserStore
.
to
.
isLogin
)
{
upload
();
}
});
...
...
@@ -31,54 +32,53 @@ class Global {
// 配置存储
Get
.
putAsync
<
StorageService
>(()
=>
StorageService
().
init
()),
]).
whenComplete
(()
{
// 网络
Get
.
put
<
HttpService
>(
HttpService
());
//配置基本设置
Get
.
put
<
ConfigStore
>(
ConfigStore
());
//
Get
.
put
<
UserStore
>(
UserStore
());
});
}
static
void
upload
()
async
{
static
void
upload
()
async
{
List
<
Map
<
String
,
dynamic
>>
data
=
await
SqlManager
.
queryNoUploadData
();
List
<
Map
<
String
,
dynamic
>>
finalData
=
List
<
Map
<
String
,
dynamic
>>.
from
(
data
);
List
<
Map
<
String
,
dynamic
>>
finalData
=
List
<
Map
<
String
,
dynamic
>>.
from
(
data
);
Console
.
log
(
'Sql-----查询到的数据-----------------------
$data
'
);
if
(
data
.
isNotEmpty
)
{
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
if
(
data
.
isNotEmpty
)
{
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
Map
<
String
,
dynamic
>
temp
=
data
[
i
];
// for (Map<String, dynamic> temp in data){
// 如果是笔记
if
(
temp
[
'types'
]
==
3
){
if
(
temp
[
'types'
]
==
3
)
{
// 存储url的数组
List
<
String
>
finalAudios
=
[];
// 存储url的数组
List
<
String
>
finalImages
=
[];
Map
<
String
,
dynamic
>
contentMap
=
jsonDecode
(
temp
[
'note_content'
]);
Map
<
String
,
dynamic
>
contentMap
=
jsonDecode
(
temp
[
'note_content'
]);
List
<
dynamic
>
audios
=
contentMap
[
'audio'
];
if
(
audios
.
isNotEmpty
)
{
for
(
String
path
in
audios
)
{
if
(
audios
.
isNotEmpty
)
{
for
(
String
path
in
audios
)
{
final
url
=
await
uploadSource
(
path:
path
);
finalAudios
.
add
(
url
);
}
}
List
<
dynamic
>
images
=
contentMap
[
'image'
];
if
(
images
.
isNotEmpty
)
{
for
(
String
path
in
images
)
{
if
(
images
.
isNotEmpty
)
{
for
(
String
path
in
images
)
{
final
url
=
await
uploadSource
(
path:
path
);
finalImages
.
add
(
url
);
}
}
Map
<
String
,
dynamic
>
finalContentMap
=
{
'text'
:
contentMap
[
'text'
],
Map
<
String
,
dynamic
>
finalContentMap
=
{
'text'
:
contentMap
[
'text'
],
'audio'
:
finalAudios
,
'image'
:
finalImages
};
finalData
[
i
]
=
Map
<
String
,
dynamic
>.
from
(
temp
);
finalData
[
i
]
=
Map
<
String
,
dynamic
>.
from
(
temp
);
finalData
[
i
][
'note_content'
]
=
jsonEncode
(
finalContentMap
);
}
}
...
...
@@ -90,12 +90,10 @@ class Global {
SqlManager
.
updateNotesId
(
result
);
}
}
}
// 上传文件
static
Future
<
String
>
uploadSource
({
required
String
path
})
async
{
static
Future
<
String
>
uploadSource
({
required
String
path
})
async
{
// String result = await CommonAPI.upload(path:path,fileTypes: 'comment');
// return result;
OssTool
tool
=
OssTool
(
'zxts-comment-file'
);
...
...
@@ -103,15 +101,15 @@ class Global {
Console
.
log
(
'------response--------------------------
${response.realUri}
'
);
return
response
.
realUri
.
toString
();
}
}
/// 生命周期类
class
AppLifecycleObserver
extends
WidgetsBindingObserver
{
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
if
(
state
==
AppLifecycleState
.
paused
||
state
==
AppLifecycleState
.
detached
)
{
if
(
state
==
AppLifecycleState
.
paused
||
state
==
AppLifecycleState
.
detached
)
{
SqlManager
.
closeDatabase
();
// 应用进入后台时关闭数据库连接
}
}
}
\ No newline at end of file
}
lib/main.dart
浏览文件 @
9c6fe63b
...
...
@@ -36,62 +36,62 @@ void main() {
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
}):
super
(
key:
key
);
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
// This widget is the root of your application.
@override
Widget
build
(
BuildContext
context
)
{
return
ScreenUtilInit
(
designSize:
const
Size
(
375
,
667
),
builder:
(
context
,
child
)
=>
GetBuilder
<
ConfigStore
>(
builder:
(
config
)
=>
MaterialApp
.
router
(
debugShowCheckedModeBanner:
false
,
title:
'紫荆数智学堂'
,
theme:
AppTheme
.
light
,
darkTheme:
AppTheme
.
dark
,
themeMode:
ThemeMode
.
light
,
routerConfig:
Routes
.
config
,
builder:
CustomToast
.
init
(
context:
context
,
builder:
(
context
,
child
)
{
return
ScrollConfiguration
(
behavior:
_NoShadowScrollBehavior
(),
child:
OKToast
(
radius:
8.0
,
backgroundColor:
const
Color
(
0xFF000000
).
withOpacity
(
0.2
),
textPadding:
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
,
vertical:
10.0
),
position:
ToastPosition
.
bottom
,
// textStyle: ,
child:
child
??
const
Material
(),
),
);
},
return
ScreenUtilInit
(
designSize:
const
Size
(
375
,
667
),
builder:
(
context
,
child
)
=>
GetBuilder
<
ConfigStore
>(
builder:
(
config
)
=>
MaterialApp
.
router
(
debugShowCheckedModeBanner:
false
,
title:
'紫荆数智学堂'
,
theme:
AppTheme
.
light
,
darkTheme:
AppTheme
.
dark
,
themeMode:
ThemeMode
.
light
,
routerConfig:
Routes
.
config
,
builder:
CustomToast
.
init
(
context:
context
,
builder:
(
context
,
child
)
{
return
ScrollConfiguration
(
behavior:
_NoShadowScrollBehavior
(),
child:
OKToast
(
radius:
8.0
,
backgroundColor:
const
Color
(
0xFF000000
).
withOpacity
(
0.2
),
textPadding:
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
,
vertical:
10.0
),
position:
ToastPosition
.
bottom
,
// textStyle: ,
child:
child
??
const
Material
(),
),
supportedLocales:
const
[
Locale
.
fromSubtags
(
languageCode:
'zh'
),
],
localizationsDelegates:
const
[
GlobalMaterialLocalizations
.
delegate
,
GlobalWidgetsLocalizations
.
delegate
,
GlobalCupertinoLocalizations
.
delegate
,
// S.delegate,
],
locale:
PlatformDispatcher
.
instance
.
locale
,
// supportedLocales: S.delegate.supportedLocales,
),
);
},
),
);
supportedLocales:
const
[
Locale
.
fromSubtags
(
languageCode:
'zh'
),
],
localizationsDelegates:
const
[
GlobalMaterialLocalizations
.
delegate
,
GlobalWidgetsLocalizations
.
delegate
,
GlobalCupertinoLocalizations
.
delegate
,
// S.delegate,
],
locale:
PlatformDispatcher
.
instance
.
locale
,
// supportedLocales: S.delegate.supportedLocales,
),
),
);
}
}
class
_NoShadowScrollBehavior
extends
ScrollBehavior
{
@override
Widget
buildOverscrollIndicator
(
BuildContext
context
,
Widget
child
,
ScrollableDetails
details
,
)
{
BuildContext
context
,
Widget
child
,
ScrollableDetails
details
,
)
{
switch
(
getPlatform
(
context
))
{
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
macOS
:
...
...
@@ -117,5 +117,3 @@ class _NoShadowScrollBehavior extends ScrollBehavior {
}
}
}
lib/services/storage.dart
浏览文件 @
9c6fe63b
...
...
@@ -22,7 +22,7 @@ class StorageService extends GetxService {
}
///存储list类型
Future
<
bool
>
setList
(
String
key
,
List
<
String
>
value
)
async
{
Future
<
bool
>
setList
(
String
key
,
List
<
String
>
value
)
async
{
return
await
_prefs
.
setStringList
(
key
,
value
);
}
...
...
@@ -45,6 +45,7 @@ class StorageService extends GetxService {
List
<
String
>
getList
(
String
key
)
{
return
_prefs
.
getStringList
(
key
)
??
[];
}
/// 获取object
Map
?
getObject
(
String
key
)
{
String
?
data
=
_prefs
.
getString
(
key
);
...
...
@@ -55,12 +56,4 @@ class StorageService extends GetxService {
Future
<
bool
>
remove
(
String
key
)
async
{
return
await
_prefs
.
remove
(
key
);
}
}
\ No newline at end of file
}
lib/store/config.dart
浏览文件 @
9c6fe63b
...
...
@@ -7,9 +7,8 @@ class ConfigStore extends GetxController {
void
onInit
()
{
super
.
onInit
();
_initThemeMode
();
}
/// 主题模式
void
_initThemeMode
()
{
final
theme
=
StorageService
.
to
.
getString
(
C
.
localThemeMode
);
...
...
@@ -26,4 +25,4 @@ class ConfigStore extends GetxController {
}
AppTheme
.
setSystemStyle
();
}
}
\ No newline at end of file
}
lib/store/user.dart
浏览文件 @
9c6fe63b
part of
store
;
class
UserStore
extends
GetxController
{
class
UserStore
extends
GetxController
{
// 获取 UserStore 实例
static
UserStore
get
to
=>
Get
.
find
();
// 是否登录
bool
_isLogin
=
false
;
String
_token
=
''
;
String
get
token
=>
_token
;
String
get
token
=>
_token
;
String
_accessToken
=
''
;
String
get
accessToken
=>
_accessToken
;
bool
get
isLogin
=>
_isLogin
;
bool
get
isLogin
=>
_isLogin
;
bool
get
hasToken
=>
_token
.
isNotEmpty
;
UserModel
_info
=
UserModel
();
UserModel
get
info
=>
_info
;
// 是否需要登录
final
ValueNotifier
<
bool
>
_needLogin
=
ValueNotifier
<
bool
>(
false
);
ValueNotifier
<
bool
>
get
needLogin
=>
_needLogin
;
@override
void
onInit
()
{
super
.
onInit
();
_token
=
StorageService
.
to
.
getString
(
kLocalToken
);
}
Future
<
void
>
login
(
UserModel
value
)
async
{
_token
=
value
.
token
??
''
;
_accessToken
=
value
.
accessToken
??
''
;
await
StorageService
.
to
.
setString
(
kLocalToken
,
_token
);
await
StorageService
.
to
.
setString
(
kLocalAccessToken
,
value
.
accessToken
??
''
);
await
StorageService
.
to
.
setString
(
kLocalUserInfo
,
jsonEncode
(
value
.
toJson
()));
Future
<
void
>
login
(
UserModel
value
)
async
{
_token
=
value
.
token
??
''
;
_accessToken
=
value
.
accessToken
??
''
;
await
StorageService
.
to
.
setString
(
kLocalToken
,
_token
);
await
StorageService
.
to
.
setString
(
kLocalAccessToken
,
value
.
accessToken
??
''
);
await
StorageService
.
to
.
setString
(
kLocalUserInfo
,
jsonEncode
(
value
.
toJson
()));
_needLogin
.
value
=
false
;
_info
=
value
;
_isLogin
=
true
;
update
();
}
Future
<
void
>
setToken
(
String
value
)
async
{
await
StorageService
.
to
.
setString
(
kLocalToken
,
value
);
_token
=
value
;
...
...
@@ -55,7 +59,8 @@ class UserStore extends GetxController{
}
Future
<
void
>
setInfo
(
UserModel
value
)
async
{
await
StorageService
.
to
.
setString
(
kLocalUserInfo
,
jsonEncode
(
value
.
toJson
()));
await
StorageService
.
to
.
setString
(
kLocalUserInfo
,
jsonEncode
(
value
.
toJson
()));
_needLogin
.
value
=
false
;
_info
=
value
;
}
...
...
@@ -71,11 +76,8 @@ class UserStore extends GetxController{
}
Future
<
void
>
profile
()
async
{
if
(!
hasToken
)
return
;
_isLogin
=
true
;
update
();
}
}
\ No newline at end of file
}
lib/theme.dart
浏览文件 @
9c6fe63b
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_book/utils/index.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
abstract
class
AppTheme
{
// 应用程序默认边距
static
final
margin
=
10.0
.
w
;
// 主要/主题颜色的常量
static
const
primary
=
Color
(
0xFFAB1941
);
// 成功状态的颜色
static
const
success
=
Color
(
0xFF23A757
);
// 警告状态的颜色
static
const
warning
=
Color
(
0xFFFF1843
);
// 错误状态的颜色
static
const
error
=
Color
(
0xFFDA1414
);
// 信息/提示状态的颜色
static
const
info
=
Color
(
0xFF2E5AAC
);
...
...
@@ -31,24 +33,23 @@ abstract class AppTheme {
statusBarIconBrightness:
Brightness
.
dark
,
systemNavigationBarDividerColor:
Colors
.
transparent
,
systemNavigationBarColor:
Colors
.
white
,
systemNavigationBarIconBrightness:
Brightness
.
dark
);
systemNavigationBarIconBrightness:
Brightness
.
dark
);
// 亮色主题
static
SystemUiOverlayStyle
get
systemStyleLight
=>
systemStyle
.
copyWith
(
systemNavigationBarColor:
const
Color
(
0xFF000000
),
systemNavigationBarIconBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
light
,
statusBarBrightness:
Brightness
.
dark
,
);
systemNavigationBarColor:
const
Color
(
0xFF000000
),
systemNavigationBarIconBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
light
,
statusBarBrightness:
Brightness
.
dark
,
);
// 暗色主题
static
SystemUiOverlayStyle
get
systemStyleDark
=>
systemStyle
.
copyWith
(
systemNavigationBarColor:
const
Color
(
0xFF000000
),
systemNavigationBarIconBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
dark
,
statusBarBrightness:
Brightness
.
light
,
);
systemNavigationBarColor:
const
Color
(
0xFF000000
),
systemNavigationBarIconBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
dark
,
statusBarBrightness:
Brightness
.
light
,
);
/// 设置主题
static
void
setSystemStyle
()
{
...
...
@@ -87,6 +88,7 @@ abstract class AppTheme {
);
return
_getTheme
(
scheme
);
}
static
ThemeData
get
dark
{
var
scheme
=
ColorScheme
.
dark
(
background:
const
Color
(
0xFF0D0D0D
),
...
...
@@ -141,7 +143,7 @@ abstract class AppTheme {
),
appBarTheme:
AppBarTheme
(
systemOverlayStyle:
SystemUiOverlayStyle
.
dark
,
backgroundColor:
const
Color
(
0xFFAB1941
).
withOpacity
(
0.02
),
backgroundColor:
const
Color
(
0xFFAB1941
).
withOpacity
(
0.02
),
scrolledUnderElevation:
0
,
elevation:
0
,
centerTitle:
true
,
...
...
@@ -186,8 +188,9 @@ abstract class AppTheme {
backgroundColor:
Colors
.
white
,
unselectedItemColor:
const
Color
(
0xFF666666
),
selectedItemColor:
scheme
.
primary
,
unselectedLabelStyle:
TextStyle
(
fontSize:
11
.
w
,
fontWeight:
Fonts
.
medium
),
selectedLabelStyle:
TextStyle
(
fontSize:
11
.
w
,
fontWeight:
Fonts
.
medium
),
unselectedLabelStyle:
TextStyle
(
fontSize:
11
.
w
,
fontWeight:
Fonts
.
medium
),
selectedLabelStyle:
TextStyle
(
fontSize:
11
.
w
,
fontWeight:
Fonts
.
medium
),
unselectedIconTheme:
IconThemeData
(
size:
15
.
w
,
color:
scheme
.
onBackground
.
withOpacity
(
0.5
),
...
...
@@ -269,8 +272,4 @@ abstract class AppTheme {
),
);
}
}
\ No newline at end of file
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论