This commit is contained in:
cxc
2023-02-09 17:07:14 +08:00
parent 1b88c226ad
commit 2aa59649a8
16 changed files with 156 additions and 41 deletions

View File

@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
78876org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

View File

@ -1,9 +1,7 @@
import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:momo/material/app.dart';
import 'package:momo/provider/token.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -41,12 +39,11 @@ void main() async {
}
class MyApp extends StatelessWidget {
const MyApp({super.key, this.token});
final String? token;
const MyApp({super.key});
@override
Widget build(BuildContext context) {
print("build my app");
return const MyMaterialApp();
}
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class ImageDetail extends StatefulWidget {
const ImageDetail({Key? key}) : super(key: key);
@ -10,6 +11,8 @@ class ImageDetail extends StatefulWidget {
class _ImageDetailState extends State<ImageDetail> {
@override
Widget build(BuildContext context) {
return const Placeholder();
return Center(
child: Text(GoRouterState.of(context).queryParams["id"] ?? ""),
);
}
}

View File

@ -12,45 +12,73 @@ class Gallery extends ConsumerStatefulWidget {
ConsumerState<Gallery> createState() => _GalleryState();
}
List<ImageResp> imageList = [];
class _GalleryState extends ConsumerState<Gallery> {
List<ImageResp> imageList = [];
int pageNum = 1;
int pageSize = 10;
bool hasMore = false;
bool loading = true;
Future<dynamic> loadImages() async {
var resp = await dio.get("/image/history");
loading = true;
print(pageNum);
var resp = await dio.get("/image/history",
queryParameters: {"page": pageNum, "size": pageSize});
ImageListResp imageListResp = ImageListResp.fromJson(resp.data);
hasMore = imageListResp.hasNext;
pageNum = pageNum + 1;
if (mounted) {
setState(() {
imageList = ImageListResp.fromJson(resp.data).list;
imageList.addAll(imageListResp.list);
});
loading = false;
}
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
void resetState() {
imageList = [];
pageNum = 1;
hasMore = false;
loading = true;
}
@override
void initState() {
// TODO: implement initState
super.initState();
print("init");
// resetState();
loadImages();
}
@override
Widget build(BuildContext context) {
return GridView.builder(
// controller: ,
itemCount: imageList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
itemBuilder: (BuildContext context, int index) {
if (index == imageList.length - 1 && imageList.length < 200) {
if (hasMore && pageNum != 1 && !loading) {
loadImages();
} else {
print("没有了");
}
}
return InkWell(
onTap: () {
context.go("/detail");
context.go(Uri(
path: "/detail",
queryParameters: {"id": "${imageList[index].id}"})
.toString());
},
child: Image.network(
"${dio.options.baseUrl}/image/thumbnail/${imageList[index].file_path}",
fit: BoxFit.cover,
errorBuilder: (BuildContext context, o, err) {
return const Icon(Icons.error_outline);
},
),
);
});

View File

@ -21,6 +21,7 @@ class _HomePageState extends ConsumerState<HomePage> {
{"path": "/", "title": "相册"},
{"path": "/profile", "title": "用户"}
];
int key = 0;
@override
Widget build(BuildContext context) {
@ -58,26 +59,25 @@ class _HomePageState extends ConsumerState<HomePage> {
contentType: MediaType(mimeType!.split("/").first,
mimeType.split("/").last))
});
await dio.post("/image/upload", data: data);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Icon(
Icons.check_circle,
color: Colors.white,
),
SizedBox(
width: 10,
),
Text("上传成功")
],
),
backgroundColor: Colors.lightGreen,
));
await dio.post("/image/upload", data: data).then((value) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Icon(
Icons.check_circle,
color: Colors.white,
),
SizedBox(
width: 10,
),
Text("上传成功")
],
),
backgroundColor: Colors.lightGreen,
));
});
} else {}
// context.go("/login");
},
child: const Icon(Icons.add),
)
@ -99,7 +99,9 @@ class _HomePageState extends ConsumerState<HomePage> {
setState(() {
selectedIndex = idx;
});
context.go(tabList[idx]["path"] ?? "");
context.go(Uri(
path: tabList[idx]["path"] ?? "",
).toString());
},
destinations: const [
NavigationRailDestination(

View File

@ -89,12 +89,9 @@ class _LoginFormState extends ConsumerState<LoginForm> {
print(resp.statusCode);
}
} catch (e) {
// print(e is DioError);
// DioError err = e;
if (e is DioError) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(e.response?.data["msg"] ?? "请求错误")));
// print(e.response?.data["msg"] ?? "请求错误");
}
}
}),

View File

@ -11,6 +11,7 @@ class MyMaterialRouterConfig {
MyMaterialRouterConfig(String? token) {
router = GoRouter(
initialLocation: "/",
routes: <RouteBase>[
ShellRoute(
builder: (BuildContext context, GoRouterState state, Widget child) {

View File

@ -7,8 +7,9 @@ part 'image_list_resp.g.dart';
class ImageListResp {
List<ImageResp> list;
int total;
bool hasNext;
ImageListResp(this.list, this.total);
ImageListResp(this.list, this.total, this.hasNext);
factory ImageListResp.fromJson(Map<String, dynamic> json) =>
_$ImageListRespFromJson(json);

View File

@ -12,10 +12,12 @@ ImageListResp _$ImageListRespFromJson(Map<String, dynamic> json) =>
.map((e) => ImageResp.fromJson(e as Map<String, dynamic>))
.toList(),
json['total'] as int,
json['hasNext'] as bool,
);
Map<String, dynamic> _$ImageListRespToJson(ImageListResp instance) =>
<String, dynamic>{
'list': instance.list,
'total': instance.total,
'hasNext': instance.hasNext,
};

View File

@ -8,6 +8,7 @@
#include <screen_retriever/screen_retriever_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) tray_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "TrayManagerPlugin");
tray_manager_plugin_register_with_registrar(tray_manager_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
tray_manager
url_launcher_linux
window_manager
)

View File

@ -8,11 +8,13 @@ import Foundation
import screen_retriever
import shared_preferences_foundation
import tray_manager
import url_launcher_macos
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
TrayManagerPlugin.register(with: registry.registrar(forPlugin: "TrayManagerPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}

View File

@ -169,6 +169,14 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "4.1.0"
context_menus:
dependency: "direct main"
description:
name: context_menus
sha256: "25313f2a17dc936f541f8012761648cb58d936c5d6f6bf7282f137a4b9dedddb"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.0.2"
convert:
dependency: transitive
description:
@ -834,6 +842,70 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.3.1"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: e8f2efc804810c0f2f5b485f49e7942179f56eabcfe81dce3387fec4bb55876b
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "6.1.9"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "3e2f6dfd2c7d9cd123296cab8ef66cfc2c1a13f5845f42c7a0f365690a8a7dd1"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "6.0.23"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "0a5af0aefdd8cf820dd739886efb1637f1f24489900204f50984634c07a54815"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "6.1.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "318c42cba924e18180c029be69caf0a1a710191b9ec49bb42b5998fdcccee3cc"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.2"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "41988b55570df53b3dd2a7fc90c76756a963de6a8c5f8e113330cb35992e2094"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.2"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "4eae912628763eb48fc214522e58e942fd16ce195407dbf45638239523c759a6"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.1"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "44d79408ce9f07052095ef1f9a693c258d6373dc3944249374e30eff7219ccb0"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.14"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: b6217370f8eb1fd85c8890c539f5a639a01ab209a36db82c921ebeacefc7a615
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.0.3"
vector_math:
dependency: transitive
description:

View File

@ -51,6 +51,7 @@ dependencies:
dio: ^4.0.6
http_parser: ^4.0.2
mime: ^1.0.4
context_menus: ^1.0.2
dev_dependencies:
flutter_test:

View File

@ -8,6 +8,7 @@
#include <screen_retriever/screen_retriever_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
TrayManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
tray_manager
url_launcher_windows
window_manager
)