dio
This commit is contained in:
@ -1,39 +0,0 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:momo/fluent/router.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class MyFluentApp extends ConsumerWidget {
|
|
||||||
const MyFluentApp({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
// final String token = ref.watch(tokenProvider);
|
|
||||||
Future<String?> loadToken() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
String? tk = prefs.getString("token");
|
|
||||||
return tk;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FutureBuilder(
|
|
||||||
future: loadToken(),
|
|
||||||
builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
|
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
|
||||||
MyFluentRouterConfig myFluentRouterConfig =
|
|
||||||
MyFluentRouterConfig(snapshot.data);
|
|
||||||
return FluentApp.router(
|
|
||||||
routeInformationParser:
|
|
||||||
myFluentRouterConfig.router.routeInformationParser,
|
|
||||||
routerDelegate: myFluentRouterConfig.router.routerDelegate,
|
|
||||||
color: Colors.blue,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return const FluentApp(
|
|
||||||
home: ScaffoldPage(
|
|
||||||
content: Placeholder(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,172 +0,0 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
import 'package:fluentui_system_icons/fluentui_system_icons.dart'
|
|
||||||
as fluentui_system_icons;
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:momo/provider/token.dart';
|
|
||||||
|
|
||||||
class HomePage extends ConsumerStatefulWidget {
|
|
||||||
const HomePage({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
ConsumerState<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends ConsumerState<HomePage> {
|
|
||||||
int _selected = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(
|
|
||||||
BuildContext context,
|
|
||||||
) {
|
|
||||||
// String token = ref.watch(tokenProvider);
|
|
||||||
|
|
||||||
return MediaQuery.of(context).size.width > 640
|
|
||||||
? NavigationView(
|
|
||||||
appBar: NavigationAppBar(title: Text('momo')),
|
|
||||||
pane: NavigationPane(
|
|
||||||
displayMode: PaneDisplayMode.auto,
|
|
||||||
selected: _selected,
|
|
||||||
leading: const Icon(
|
|
||||||
fluentui_system_icons.FluentIcons.backpack_12_filled),
|
|
||||||
header: const Text("111"),
|
|
||||||
onChanged: (idx) {
|
|
||||||
setState(() {
|
|
||||||
_selected = idx;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
autoSuggestBox: const AutoSuggestBox(
|
|
||||||
placeholder: "查找",
|
|
||||||
trailingIcon: Center(
|
|
||||||
child: Icon(
|
|
||||||
fluentui_system_icons.FluentIcons.search_12_filled),
|
|
||||||
),
|
|
||||||
items: [],
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
PaneItem(
|
|
||||||
icon: const Icon(fluentui_system_icons
|
|
||||||
.FluentIcons.network_adapter_16_regular),
|
|
||||||
title: const Text('代理'),
|
|
||||||
// body: DeferredWidget
|
|
||||||
body: ScaffoldPage(
|
|
||||||
header: PageHeader(
|
|
||||||
title: Text("213"),
|
|
||||||
),
|
|
||||||
content: Center(
|
|
||||||
child: FilledButton(
|
|
||||||
onPressed: () {
|
|
||||||
// ref.watch(tokenProvider.notifier).removeToken();
|
|
||||||
GoRouter.of(context).go("/login");
|
|
||||||
},
|
|
||||||
child: Text("退出"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
PaneItem(
|
|
||||||
icon: const Icon(fluentui_system_icons
|
|
||||||
.FluentIcons.settings_48_regular),
|
|
||||||
title: const Text('用户'),
|
|
||||||
body: ScaffoldPage(
|
|
||||||
header: const PageHeader(
|
|
||||||
title: Text("用户"),
|
|
||||||
),
|
|
||||||
// bottomBar: BottomNavigationBarItem(),
|
|
||||||
// header: HeadingElement.h1(),
|
|
||||||
content: ListView.separated(
|
|
||||||
itemCount: 2,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return const Card(
|
|
||||||
margin: EdgeInsets.fromLTRB(12, 0, 12, 0),
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
child: ListTile(
|
|
||||||
// tileColor:
|
|
||||||
// ButtonState.all(const Color(0xffeeeeee)),
|
|
||||||
leading: Icon(fluentui_system_icons
|
|
||||||
.FluentIcons
|
|
||||||
.serial_port_24_regular),
|
|
||||||
title: Text("端口"),
|
|
||||||
trailing: SizedBox(
|
|
||||||
width: 100,
|
|
||||||
child: TextBox(
|
|
||||||
placeholder: "端口",
|
|
||||||
),
|
|
||||||
)));
|
|
||||||
},
|
|
||||||
separatorBuilder: (context, index) =>
|
|
||||||
const SizedBox(
|
|
||||||
height: 2,
|
|
||||||
))))
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: ScaffoldPage(
|
|
||||||
header: PageHeader(
|
|
||||||
leading: IconButton(
|
|
||||||
icon: const Icon(fluentui_system_icons
|
|
||||||
.FluentIcons.arrow_hook_up_left_28_filled),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
title: Text("用户"),
|
|
||||||
),
|
|
||||||
content: Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ListView(),
|
|
||||||
),
|
|
||||||
BottomNavigation(
|
|
||||||
index: _selected,
|
|
||||||
onChanged: (idx) {
|
|
||||||
setState(() {
|
|
||||||
_selected = idx;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
items: const [
|
|
||||||
BottomNavigationItem(
|
|
||||||
title: Text("相册"),
|
|
||||||
icon: Icon(fluentui_system_icons
|
|
||||||
.FluentIcons.fingerprint_48_regular)),
|
|
||||||
BottomNavigationItem(
|
|
||||||
title: Text("用户"),
|
|
||||||
icon: Icon(fluentui_system_icons
|
|
||||||
.FluentIcons.person_48_regular))
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Column(
|
|
||||||
// children: [
|
|
||||||
// Expanded(
|
|
||||||
// child: ScaffoldPage(
|
|
||||||
// header: PageHeader(
|
|
||||||
// title: Text("用户"),
|
|
||||||
// ),
|
|
||||||
// content: Container(
|
|
||||||
// color: Colors.white,
|
|
||||||
// ),
|
|
||||||
// )),
|
|
||||||
// BottomNavigation(
|
|
||||||
// index: _selected,
|
|
||||||
// onChanged: (idx) {
|
|
||||||
// setState(() {
|
|
||||||
// _selected = idx;
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// items: const [
|
|
||||||
// BottomNavigationItem(
|
|
||||||
// title: Text("相册"),
|
|
||||||
// icon: Icon(fluentui_system_icons
|
|
||||||
// .FluentIcons.fingerprint_48_regular)),
|
|
||||||
// BottomNavigationItem(
|
|
||||||
// title: Text("用户"),
|
|
||||||
// icon: Icon(
|
|
||||||
// fluentui_system_icons.FluentIcons.person_48_regular))
|
|
||||||
// ],
|
|
||||||
// )
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:momo/models/login_resp.dart';
|
|
||||||
import 'package:momo/provider/token.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class LoginPage extends StatelessWidget {
|
|
||||||
const LoginPage({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
// padding: EdgeInsets.all(100),
|
|
||||||
color: Colors.white,
|
|
||||||
child: const ScaffoldPage(
|
|
||||||
header: PageHeader(
|
|
||||||
title: Text("登录"),
|
|
||||||
),
|
|
||||||
content: LoginForm(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoginForm extends StatefulWidget {
|
|
||||||
const LoginForm({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<LoginForm> createState() => _LoginFormState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _LoginFormState extends State<LoginForm> {
|
|
||||||
TextEditingController usernameController = TextEditingController();
|
|
||||||
TextEditingController passwordController = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
|
||||||
child: ListView(
|
|
||||||
children: [
|
|
||||||
TextBox(
|
|
||||||
controller: usernameController,
|
|
||||||
header: "账号",
|
|
||||||
placeholder: "请输入账号",
|
|
||||||
),
|
|
||||||
TextBox(
|
|
||||||
controller: passwordController,
|
|
||||||
header: "密码",
|
|
||||||
placeholder: "请输入密码",
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
child: Text('登录'),
|
|
||||||
onPressed: () {
|
|
||||||
if (usernameController.text.isNotEmpty &&
|
|
||||||
passwordController.text.isNotEmpty) {
|
|
||||||
http
|
|
||||||
.post(Uri.parse("http://192.168.110.156:8080/user/login"),
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: jsonEncode({
|
|
||||||
"username": usernameController.text,
|
|
||||||
"password": passwordController.text
|
|
||||||
}))
|
|
||||||
.then((resp) {
|
|
||||||
print(resp.body);
|
|
||||||
if (resp.statusCode == HttpStatus.ok) {
|
|
||||||
LoginResp loginResp =
|
|
||||||
LoginResp.fromJson(jsonDecode(resp.body));
|
|
||||||
print(loginResp.token);
|
|
||||||
// Provider.of<Secret>(context).setToken(loginResp.token);
|
|
||||||
context.go("/");
|
|
||||||
// SharedPreferences.getInstance().then((prefs) {
|
|
||||||
// prefs.setString("token", loginResp.token);
|
|
||||||
// });
|
|
||||||
// .then((value) {
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:momo/fluent/home.dart';
|
|
||||||
import 'package:momo/fluent/login.dart';
|
|
||||||
|
|
||||||
class MyFluentRouterConfig {
|
|
||||||
late GoRouter router;
|
|
||||||
|
|
||||||
MyFluentRouterConfig(String? token) {
|
|
||||||
router = GoRouter(
|
|
||||||
routes: <RouteBase>[
|
|
||||||
GoRoute(
|
|
||||||
path: '/',
|
|
||||||
builder: (BuildContext context, GoRouterState state) {
|
|
||||||
return const HomePage();
|
|
||||||
},
|
|
||||||
redirect: (BuildContext context, GoRouterState state) {
|
|
||||||
if (token == null || token.isEmpty) {
|
|
||||||
return "/login";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: "/login",
|
|
||||||
builder: (BuildContext context, GoRouterState state) {
|
|
||||||
return const LoginPage();
|
|
||||||
})
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TextLogin extends StatelessWidget {
|
|
||||||
const TextLogin({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ScaffoldPage(
|
|
||||||
content: Center(
|
|
||||||
child: FilledButton(
|
|
||||||
child: Text("logi"),
|
|
||||||
onPressed: () {
|
|
||||||
context.go("/");
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -38,17 +38,6 @@ void main() async {
|
|||||||
child: const MyApp(),
|
child: const MyApp(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// runApp((child: MyApp(token: tk)));
|
|
||||||
// runApp(MultiProvider(
|
|
||||||
// providers: [
|
|
||||||
// ChangeNotifierProvider(
|
|
||||||
// create: (context) => Secret(),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// child: MyApp(
|
|
||||||
// token: tk,
|
|
||||||
// ),
|
|
||||||
// ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@ -58,8 +47,6 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Provider.of<Secret>(context, listen: false).setToken(token);
|
|
||||||
|
|
||||||
return const MyMaterialApp();
|
return const MyMaterialApp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:momo/material/router.dart';
|
import 'package:momo/material/router.dart';
|
||||||
import 'package:momo/provider/token.dart';
|
import 'package:momo/provider/token.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class MyMaterialApp extends ConsumerWidget {
|
class MyMaterialApp extends ConsumerWidget {
|
||||||
const MyMaterialApp({Key? key}) : super(key: key);
|
const MyMaterialApp({Key? key}) : super(key: key);
|
||||||
|
15
lib/material/detail.dart
Normal file
15
lib/material/detail.dart
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ImageDetail extends StatefulWidget {
|
||||||
|
const ImageDetail({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ImageDetail> createState() => _ImageDetailState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ImageDetailState extends State<ImageDetail> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Placeholder();
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,9 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:momo/models/image_list_resp.dart';
|
import 'package:momo/models/image_list_resp.dart';
|
||||||
import 'package:momo/models/image_resp.dart';
|
import 'package:momo/models/image_resp.dart';
|
||||||
import 'package:momo/provider/token.dart';
|
import 'package:momo/request/http_client.dart';
|
||||||
|
|
||||||
// import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
// import 'package:go_router/go_router.dart';
|
|
||||||
// import 'package:momo/provider/token.dart';
|
|
||||||
// import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class Gallery extends ConsumerStatefulWidget {
|
class Gallery extends ConsumerStatefulWidget {
|
||||||
const Gallery({Key? key}) : super(key: key);
|
const Gallery({Key? key}) : super(key: key);
|
||||||
@ -20,15 +12,17 @@ class Gallery extends ConsumerStatefulWidget {
|
|||||||
ConsumerState<Gallery> createState() => _GalleryState();
|
ConsumerState<Gallery> createState() => _GalleryState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GalleryState extends ConsumerState<Gallery> {
|
List<ImageResp> imageList = [];
|
||||||
Future<dynamic> loadImages(tk) async {
|
|
||||||
http.Response resp = await http.get(
|
|
||||||
Uri.parse("http://192.168.110.156:8080/image/history"),
|
|
||||||
headers: {"Authorization": tk});
|
|
||||||
return resp.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ImageResp> imageList = [];
|
class _GalleryState extends ConsumerState<Gallery> {
|
||||||
|
Future<dynamic> loadImages() async {
|
||||||
|
var resp = await dio.get("/image/history");
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
imageList = ImageListResp.fromJson(resp.data).list;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -36,18 +30,15 @@ class _GalleryState extends ConsumerState<Gallery> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
loadImages();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String? tk = ref.watch(tokenProvider);
|
|
||||||
if (tk != null) {
|
|
||||||
loadImages(tk).then((bd) {
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
imageList = ImageListResp.fromJson(jsonDecode(bd)).list;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return GridView.builder(
|
return GridView.builder(
|
||||||
itemCount: imageList.length,
|
itemCount: imageList.length,
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
@ -58,7 +49,7 @@ class _GalleryState extends ConsumerState<Gallery> {
|
|||||||
context.go("/detail");
|
context.go("/detail");
|
||||||
},
|
},
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
"http://192.168.110.156:8080/image/thumbnail/${imageList[index].file_path}",
|
"${dio.options.baseUrl}/image/thumbnail/${imageList[index].file_path}",
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
import 'package:momo/provider/token.dart';
|
import 'package:momo/request/http_client.dart';
|
||||||
|
|
||||||
class HomePage extends ConsumerStatefulWidget {
|
class HomePage extends ConsumerStatefulWidget {
|
||||||
const HomePage({Key? key, required this.content}) : super(key: key);
|
const HomePage({Key? key, required this.content}) : super(key: key);
|
||||||
@ -18,29 +18,31 @@ class HomePage extends ConsumerStatefulWidget {
|
|||||||
class _HomePageState extends ConsumerState<HomePage> {
|
class _HomePageState extends ConsumerState<HomePage> {
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
final tabList = [
|
final tabList = [
|
||||||
{
|
{"path": "/", "title": "相册"},
|
||||||
"path": "/",
|
{"path": "/profile", "title": "用户"}
|
||||||
},
|
|
||||||
{"path": "/profile"}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String? token = ref.watch(tokenProvider);
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(
|
leading: ["/", "/profile"].contains(GoRouterState.of(context).location)
|
||||||
"App Header",
|
? null
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
: IconButton(
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_left),
|
||||||
|
onPressed: () {
|
||||||
|
context.go("/");
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
tabList[selectedIndex]["title"] ?? "",
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
elevation: 10,
|
elevation: 10,
|
||||||
),
|
),
|
||||||
floatingActionButton: selectedIndex == 0
|
floatingActionButton: selectedIndex == 0
|
||||||
? FloatingActionButton(
|
? FloatingActionButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (token == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FilePickerResult? result =
|
FilePickerResult? result =
|
||||||
await FilePicker.platform.pickFiles(type: FileType.image);
|
await FilePicker.platform.pickFiles(type: FileType.image);
|
||||||
|
|
||||||
@ -49,7 +51,6 @@ class _HomePageState extends ConsumerState<HomePage> {
|
|||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Dio dio = Dio();
|
|
||||||
String? mimeType = lookupMimeType(filePath);
|
String? mimeType = lookupMimeType(filePath);
|
||||||
FormData data = FormData.fromMap({
|
FormData data = FormData.fromMap({
|
||||||
"pic": await MultipartFile.fromFile(filePath,
|
"pic": await MultipartFile.fromFile(filePath,
|
||||||
@ -57,10 +58,23 @@ class _HomePageState extends ConsumerState<HomePage> {
|
|||||||
contentType: MediaType(mimeType!.split("/").first,
|
contentType: MediaType(mimeType!.split("/").first,
|
||||||
mimeType.split("/").last))
|
mimeType.split("/").last))
|
||||||
});
|
});
|
||||||
Response resp = await dio.post(
|
await dio.post("/image/upload", data: data);
|
||||||
"http://192.168.110.156:8080/image/upload",
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
data: data,
|
content: Row(
|
||||||
options: Options(headers: {"Authorization": token}));
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: const [
|
||||||
|
Icon(
|
||||||
|
Icons.check_circle,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
Text("上传成功")
|
||||||
|
],
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.lightGreen,
|
||||||
|
));
|
||||||
} else {}
|
} else {}
|
||||||
|
|
||||||
// context.go("/login");
|
// context.go("/login");
|
||||||
@ -109,6 +123,7 @@ class _HomePageState extends ConsumerState<HomePage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
selectedIndex = idx;
|
selectedIndex = idx;
|
||||||
});
|
});
|
||||||
|
context.go(tabList[idx]["path"] ?? "");
|
||||||
},
|
},
|
||||||
items: const [
|
items: const [
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
// import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:momo/models/login_resp.dart';
|
import 'package:momo/models/login_resp.dart';
|
||||||
import 'package:momo/provider/token.dart';
|
import 'package:momo/provider/token.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:momo/request/http_client.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class LoginPage extends StatelessWidget {
|
class LoginPage extends StatelessWidget {
|
||||||
const LoginPage({Key? key}) : super(key: key);
|
const LoginPage({Key? key}) : super(key: key);
|
||||||
@ -61,7 +56,9 @@ class _LoginFormState extends ConsumerState<LoginForm> {
|
|||||||
height: 20,
|
height: 20,
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
obscureText: true,
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
|
// keyboardType: TextInputType.,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
enabledBorder: OutlineInputBorder(borderSide: BorderSide()),
|
enabledBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||||
focusedBorder: OutlineInputBorder(borderSide: BorderSide()),
|
focusedBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||||
@ -76,26 +73,29 @@ class _LoginFormState extends ConsumerState<LoginForm> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
child: const Text("登录"),
|
child: const Text("登录"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (usernameController.text.isNotEmpty &&
|
if (usernameController.text.isEmpty ||
|
||||||
passwordController.text.isNotEmpty) {
|
passwordController.text.isEmpty) {
|
||||||
http
|
return;
|
||||||
.post(Uri.parse("http://192.168.110.156:8080/user/login"),
|
}
|
||||||
headers: {"Content-Type": "application/json"},
|
try {
|
||||||
body: jsonEncode({
|
Response resp = await dio.post("/user/login", data: {
|
||||||
"username": usernameController.text,
|
"username": usernameController.text,
|
||||||
"password": passwordController.text
|
"password": passwordController.text
|
||||||
}))
|
|
||||||
.then((resp) {
|
|
||||||
if (resp.statusCode == HttpStatus.ok) {
|
|
||||||
LoginResp loginResp =
|
|
||||||
LoginResp.fromJson(jsonDecode(resp.body));
|
|
||||||
ref.watch(tokenProvider.notifier).setToken(loginResp.token);
|
|
||||||
// context.go("/");
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}).catchError((err) {
|
|
||||||
print(err.toString());
|
|
||||||
});
|
});
|
||||||
|
if (resp.statusCode == HttpStatus.ok) {
|
||||||
|
LoginResp loginResp = LoginResp.fromJson(resp.data);
|
||||||
|
ref.watch(tokenProvider.notifier).setToken(loginResp.token);
|
||||||
|
} else {
|
||||||
|
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"] ?? "请求错误");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:momo/material/detail.dart';
|
||||||
import 'package:momo/material/gallery.dart';
|
import 'package:momo/material/gallery.dart';
|
||||||
import 'package:momo/material/home.dart';
|
import 'package:momo/material/home.dart';
|
||||||
import 'package:momo/material/login.dart';
|
import 'package:momo/material/login.dart';
|
||||||
@ -35,10 +36,7 @@ class MyMaterialRouterConfig {
|
|||||||
GoRoute(
|
GoRoute(
|
||||||
path: "/detail",
|
path: "/detail",
|
||||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||||
const NoTransitionPage(
|
const NoTransitionPage(child: ImageDetail())),
|
||||||
child: Center(
|
|
||||||
child: Text("detail"),
|
|
||||||
)))
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
@ -52,24 +50,6 @@ class MyMaterialRouterConfig {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
// ShellRoute(
|
|
||||||
// builder: (BuildContext context, GoRouterState state, Widget child) {
|
|
||||||
// return Scaffold(
|
|
||||||
// appBar: AppBar(
|
|
||||||
// title: Text("nest"),
|
|
||||||
// ),
|
|
||||||
// body: child,
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// routes: [
|
|
||||||
// GoRoute(
|
|
||||||
// path: '/',
|
|
||||||
// builder: (BuildContext context, GoRouterState state) {
|
|
||||||
// return Center(
|
|
||||||
// child: Text("login"),
|
|
||||||
// );
|
|
||||||
// })
|
|
||||||
// ]),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:momo/request/http_client.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class TokenNotifier extends Notifier<String?> {
|
class TokenNotifier extends Notifier<String?> {
|
||||||
@ -9,6 +10,7 @@ class TokenNotifier extends Notifier<String?> {
|
|||||||
|
|
||||||
setToken(String? token) {
|
setToken(String? token) {
|
||||||
state = token;
|
state = token;
|
||||||
|
dio.options.headers["Authorization"] = token;
|
||||||
SharedPreferences.getInstance().then((prefs) {
|
SharedPreferences.getInstance().then((prefs) {
|
||||||
prefs.setString("token", token ?? "");
|
prefs.setString("token", token ?? "");
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
class HttpClient {
|
var dio = Dio(BaseOptions(
|
||||||
HttpClient(this.header);
|
baseUrl: "http://localhost:8080",
|
||||||
|
));
|
||||||
Map<String, String>? header;
|
|
||||||
|
|
||||||
Future post(Uri url) {
|
|
||||||
return http.post(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -16,7 +16,7 @@ class MyRouterConfig {
|
|||||||
// drawer: Drawer(),
|
// drawer: Drawer(),
|
||||||
bottomNavigationBar: MediaQuery.of(context).size.width <= 640
|
bottomNavigationBar: MediaQuery.of(context).size.width <= 640
|
||||||
? BottomNavigationBar(
|
? BottomNavigationBar(
|
||||||
items: [
|
items: const [
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.add), label: "333333333"),
|
icon: Icon(Icons.add), label: "333333333"),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
@ -28,7 +28,7 @@ class MyRouterConfig {
|
|||||||
children: [
|
children: [
|
||||||
MediaQuery.of(context).size.width > 640
|
MediaQuery.of(context).size.width > 640
|
||||||
? NavigationRail(
|
? NavigationRail(
|
||||||
destinations: [
|
destinations: const [
|
||||||
NavigationRailDestination(
|
NavigationRailDestination(
|
||||||
icon: Icon(Icons.add), label: Text("123")),
|
icon: Icon(Icons.add), label: Text("123")),
|
||||||
NavigationRailDestination(
|
NavigationRailDestination(
|
||||||
|
Reference in New Issue
Block a user