fix
This commit is contained in:
@ -1,19 +1,32 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/material/gallery.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
import 'package:momo/provider/token.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
class HomePage extends ConsumerStatefulWidget {
|
||||
const HomePage({Key? key, required this.content}) : super(key: key);
|
||||
final Widget content;
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
ConsumerState<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
class _HomePageState extends ConsumerState<HomePage> {
|
||||
int selectedIndex = 0;
|
||||
final tabList = [
|
||||
{
|
||||
"path": "/",
|
||||
},
|
||||
{"path": "/profile"}
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String? token = ref.watch(tokenProvider);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
@ -22,6 +35,39 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
elevation: 10,
|
||||
),
|
||||
floatingActionButton: selectedIndex == 0
|
||||
? FloatingActionButton(
|
||||
onPressed: () async {
|
||||
if (token == null) {
|
||||
return;
|
||||
}
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(type: FileType.image);
|
||||
|
||||
if (result != null) {
|
||||
String? filePath = result.files.first.path;
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
Dio dio = Dio();
|
||||
String? mimeType = lookupMimeType(filePath);
|
||||
FormData data = FormData.fromMap({
|
||||
"pic": await MultipartFile.fromFile(filePath,
|
||||
filename: result.files.first.name,
|
||||
contentType: MediaType(mimeType!.split("/").first,
|
||||
mimeType.split("/").last))
|
||||
});
|
||||
Response resp = await dio.post(
|
||||
"http://192.168.110.156:8080/image/upload",
|
||||
data: data,
|
||||
options: Options(headers: {"Authorization": token}));
|
||||
} else {}
|
||||
|
||||
// context.go("/login");
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
body: Row(
|
||||
children: [
|
||||
MediaQuery.of(context).size.width > 640
|
||||
@ -39,6 +85,7 @@ class _HomePageState extends State<HomePage> {
|
||||
setState(() {
|
||||
selectedIndex = idx;
|
||||
});
|
||||
context.go(tabList[idx]["path"] ?? "");
|
||||
},
|
||||
destinations: const [
|
||||
NavigationRailDestination(
|
||||
@ -51,7 +98,7 @@ class _HomePageState extends State<HomePage> {
|
||||
: const SizedBox(
|
||||
width: 0,
|
||||
),
|
||||
Expanded(child: pageList[selectedIndex])
|
||||
Expanded(child: widget.content)
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: MediaQuery.of(context).size.width <= 640
|
||||
@ -72,10 +119,3 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> pageList = [
|
||||
Gallery(),
|
||||
Scaffold(
|
||||
body: Placeholder(),
|
||||
)
|
||||
];
|
||||
|
Reference in New Issue
Block a user