fix
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
|
||||
// import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:momo/fluent/login.dart';
|
||||
import 'package:momo/fluent/router.dart';
|
||||
import 'package:momo/provider/token.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class MyFluentApp extends ConsumerWidget {
|
||||
const MyFluentApp({Key? key}) : super(key: key);
|
||||
@ -10,16 +13,31 @@ class MyFluentApp extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final String token = ref.watch(tokenProvider);
|
||||
return token.isNotEmpty
|
||||
? FluentApp.router(
|
||||
routeInformationParser:
|
||||
MyFluentRouterConfig.router.routeInformationParser,
|
||||
routerDelegate: MyFluentRouterConfig.router.routerDelegate,
|
||||
color: Colors.blue,
|
||||
)
|
||||
: FluentApp(
|
||||
color: Colors.blue,
|
||||
home: LoginPage(),
|
||||
);
|
||||
Future<String?> loadToken() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String? tk = await 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,19 +1,26 @@
|
||||
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 StatefulWidget {
|
||||
class HomePage extends ConsumerStatefulWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
ConsumerState<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
class _HomePageState extends ConsumerState<HomePage> {
|
||||
int _selected = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
) {
|
||||
// String token = ref.watch(tokenProvider);
|
||||
|
||||
return MediaQuery.of(context).size.width > 640
|
||||
? NavigationView(
|
||||
appBar: NavigationAppBar(title: Text('momo')),
|
||||
@ -46,6 +53,15 @@ class _HomePageState extends State<HomePage> {
|
||||
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
|
||||
|
@ -1,4 +1,12 @@
|
||||
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:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class LoginPage extends StatelessWidget {
|
||||
const LoginPage({Key? key}) : super(key: key);
|
||||
@ -8,25 +16,69 @@ class LoginPage extends StatelessWidget {
|
||||
return Container(
|
||||
// padding: EdgeInsets.all(100),
|
||||
color: Colors.white,
|
||||
child: ScaffoldPage(
|
||||
child: const ScaffoldPage(
|
||||
header: PageHeader(
|
||||
title: Text("登录"),
|
||||
),
|
||||
content: Container(
|
||||
padding: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
child: ListView(
|
||||
children: [
|
||||
TextBox(
|
||||
header: "账号",
|
||||
placeholder: "请输入账号",
|
||||
),
|
||||
TextBox(
|
||||
header: "密码",
|
||||
placeholder: "请输入密码",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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://localhost:8080/user/login"),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"username": usernameController.text,
|
||||
"password": passwordController.text
|
||||
}))
|
||||
.then((resp) {
|
||||
if (resp.statusCode == HttpStatus.ok) {
|
||||
LoginResp loginResp =
|
||||
LoginResp.fromJson(jsonDecode(resp.body));
|
||||
SharedPreferences.getInstance().then((prefs) {
|
||||
return prefs.setString("token", loginResp.token);
|
||||
}).then((value) {
|
||||
context.go("/");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,26 +1,49 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/fluent/home.dart';
|
||||
import 'package:momo/provider/token.dart';
|
||||
import 'package:momo/fluent/login.dart';
|
||||
|
||||
class MyFluentRouterConfig {
|
||||
static GoRouter router = GoRouter(
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return HomePage();
|
||||
},
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
print(tokenProvider);
|
||||
return null;
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: "/login",
|
||||
late GoRouter router;
|
||||
|
||||
MyFluentRouterConfig(String? token) {
|
||||
router = GoRouter(
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return ScaffoldPage();
|
||||
})
|
||||
],
|
||||
);
|
||||
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("/");
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,30 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:momo/fluent/app.dart';
|
||||
import 'package:momo/material/app.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'package:tray_manager/tray_manager.dart';
|
||||
|
||||
void main() {
|
||||
print(defaultTargetPlatform);
|
||||
runApp(ProviderScope(child: const MyApp()));
|
||||
void main() async {
|
||||
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// Must add this line.
|
||||
await windowManager.ensureInitialized();
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
size: Size(800, 600),
|
||||
center: true,
|
||||
minimumSize: Size(300, 400),
|
||||
// backgroundColor: Colors.transparent,
|
||||
// skipTaskbar: false,
|
||||
// titleBarStyle: TitleBarStyle.hidden,
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
}
|
||||
runApp(const ProviderScope(child: MyApp()));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@ -16,10 +32,6 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (Platform.isWindows) {
|
||||
return const MyFluentApp();
|
||||
} else {
|
||||
return const MyMaterialApp();
|
||||
}
|
||||
return const MyMaterialApp();
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:momo/material/router.dart';
|
||||
import 'package:momo/provider/token.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class MyMaterialApp extends StatelessWidget {
|
||||
class MyMaterialApp extends ConsumerWidget {
|
||||
const MyMaterialApp({Key? key}) : super(key: key);
|
||||
|
||||
Future<String?> loadToken() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String? tk = await prefs.getString("token");
|
||||
return tk;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
routerConfig: MyMaterialRouterConfig.router,
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
);
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return FutureBuilder(
|
||||
future: loadToken(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
String? token = snapshot.data;
|
||||
if (token != null) {
|
||||
// ref
|
||||
// .watch(
|
||||
// tokenProvider.notifier,
|
||||
// )
|
||||
// .setToken(token);
|
||||
}
|
||||
MyMaterialRouterConfig myMaterialRouterConfig =
|
||||
MyMaterialRouterConfig(token);
|
||||
|
||||
return MaterialApp.router(
|
||||
routerConfig: myMaterialRouterConfig.router,
|
||||
theme: ThemeData(
|
||||
useMaterial3: true, scaffoldBackgroundColor: Colors.white),
|
||||
);
|
||||
} else {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
useMaterial3: true, scaffoldBackgroundColor: Colors.white),
|
||||
home: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
27
lib/material/gallery.dart
Normal file
27
lib/material/gallery.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/provider/token.dart';
|
||||
|
||||
class Gallery extends ConsumerStatefulWidget {
|
||||
const Gallery({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
ConsumerState<Gallery> createState() => _GalleryState();
|
||||
}
|
||||
|
||||
class _GalleryState extends ConsumerState<Gallery> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String token = ref.watch(tokenProvider);
|
||||
print(token);
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
// ref.watch(tokenProvider.notifier).removeToken();
|
||||
context.go("/login");
|
||||
},
|
||||
child: Text("exit")),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/material/gallery.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
@ -14,16 +16,21 @@ class _HomePageState extends State<HomePage> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.pinkAccent,
|
||||
title: const Text("APP"),
|
||||
title: const Text(
|
||||
"App Header",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
elevation: 10,
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
MediaQuery.of(context).size.width > 640
|
||||
? NavigationRail(
|
||||
elevation: 10,
|
||||
backgroundColor: const Color(0xffebf6f5),
|
||||
leading: MediaQuery.of(context).size.width >= 1008
|
||||
? const Text(
|
||||
"Header",
|
||||
"Side Header",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 36),
|
||||
)
|
||||
@ -43,11 +50,13 @@ class _HomePageState extends State<HomePage> {
|
||||
selectedIndex: selectedIndex)
|
||||
: const SizedBox(
|
||||
width: 0,
|
||||
)
|
||||
),
|
||||
Expanded(child: pageList[selectedIndex])
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: MediaQuery.of(context).size.width <= 640
|
||||
? BottomNavigationBar(
|
||||
elevation: 10,
|
||||
currentIndex: selectedIndex,
|
||||
onTap: (idx) {
|
||||
setState(() {
|
||||
@ -63,3 +72,10 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> pageList = [
|
||||
Gallery(),
|
||||
Scaffold(
|
||||
body: Placeholder(),
|
||||
)
|
||||
];
|
||||
|
101
lib/material/login.dart
Normal file
101
lib/material/login.dart
Normal file
@ -0,0 +1,101 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.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/provider/token.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 Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("登录"),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
|
||||
child: LoginForm(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class LoginForm extends ConsumerStatefulWidget {
|
||||
const LoginForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
ConsumerState<LoginForm> createState() => _LoginFormState();
|
||||
}
|
||||
|
||||
class _LoginFormState extends ConsumerState<LoginForm> {
|
||||
TextEditingController usernameController =
|
||||
TextEditingController(text: "kencho");
|
||||
TextEditingController passwordController =
|
||||
TextEditingController(text: "169482");
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
children: [
|
||||
Form(
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: usernameController,
|
||||
decoration: const InputDecoration(
|
||||
enabledBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||
focusedBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||
hintText: 'Enter your username',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
TextFormField(
|
||||
controller: passwordController,
|
||||
decoration: const InputDecoration(
|
||||
enabledBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||
focusedBorder: OutlineInputBorder(borderSide: BorderSide()),
|
||||
hintText: 'Enter your password',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
)),
|
||||
ElevatedButton(
|
||||
child: const Text("登录"),
|
||||
onPressed: () async {
|
||||
if (usernameController.text.isNotEmpty &&
|
||||
passwordController.text.isNotEmpty) {
|
||||
http.Response resp = await http.post(
|
||||
Uri.parse("http://localhost:8080/user/login"),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"username": usernameController.text,
|
||||
"password": passwordController.text
|
||||
}));
|
||||
|
||||
if (resp.statusCode == HttpStatus.ok) {
|
||||
LoginResp loginResp =
|
||||
LoginResp.fromJson(jsonDecode(resp.body));
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
// ref.watch(tokenProvider.notifier).setToken(loginResp.token);
|
||||
prefs.setString("token", loginResp.token).then((value) {
|
||||
context.go("/");
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,16 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/material/home.dart';
|
||||
import 'package:momo/material/login.dart';
|
||||
|
||||
class MyMaterialRouterConfig {
|
||||
static GoRouter router = GoRouter(
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return HomePage();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
late GoRouter router;
|
||||
|
||||
MyMaterialRouterConfig(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();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
/// This allows the `User` class to access private members in
|
||||
/// the generated file. The value for this is *.g.dart, where
|
||||
/// the star denotes the source file name.
|
||||
part 'configs.g.dart';
|
||||
|
||||
/// An annotation for the code generator to know that this class needs the
|
||||
/// JSON serialization logic to be generated.
|
||||
@JsonSerializable()
|
||||
class Configs {
|
||||
Configs(
|
||||
this.port,
|
||||
this.socksPort,
|
||||
this.tproxyPort,
|
||||
this.redirPort,
|
||||
this.mixedPort,
|
||||
this.authentication,
|
||||
this.allowLan,
|
||||
this.bindAddress,
|
||||
this.mode,
|
||||
this.logLevel,
|
||||
this.ipv6);
|
||||
|
||||
int port;
|
||||
@JsonKey(name: 'socks-port')
|
||||
int socksPort;
|
||||
@JsonKey(name: 'redir-port')
|
||||
int redirPort;
|
||||
@JsonKey(name: 'tproxy-port')
|
||||
int tproxyPort;
|
||||
@JsonKey(name: 'mixed-port')
|
||||
int mixedPort;
|
||||
List authentication;
|
||||
@JsonKey(name: 'allow-lan')
|
||||
bool allowLan;
|
||||
@JsonKey(name: 'bind-address')
|
||||
String bindAddress;
|
||||
String mode;
|
||||
@JsonKey(name: 'log-level')
|
||||
String logLevel;
|
||||
bool ipv6;
|
||||
|
||||
/// A necessary factory constructor for creating a new Configs instance
|
||||
/// from a map. Pass the map to the generated `_$ConfigsFromJson()` constructor.
|
||||
/// The constructor is named after the source class, in this case, Configs.
|
||||
factory Configs.fromJson(Map<String, dynamic> json) =>
|
||||
_$ConfigsFromJson(json);
|
||||
|
||||
/// `toJson` is the convention for a class to declare support for serialization
|
||||
/// to JSON. The implementation simply calls the private, generated
|
||||
/// helper method `_$ConfigsToJson`.
|
||||
Map<String, dynamic> toJson() => _$ConfigsToJson(this);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'configs.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Configs _$ConfigsFromJson(Map<String, dynamic> json) => Configs(
|
||||
json['port'] as int,
|
||||
json['socks-port'] as int,
|
||||
json['tproxy-port'] as int,
|
||||
json['redir-port'] as int,
|
||||
json['mixed-port'] as int,
|
||||
json['authentication'] as List<dynamic>,
|
||||
json['allow-lan'] as bool,
|
||||
json['bind-address'] as String,
|
||||
json['mode'] as String,
|
||||
json['log-level'] as String,
|
||||
json['ipv6'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ConfigsToJson(Configs instance) => <String, dynamic>{
|
||||
'port': instance.port,
|
||||
'socks-port': instance.socksPort,
|
||||
'redir-port': instance.redirPort,
|
||||
'tproxy-port': instance.tproxyPort,
|
||||
'mixed-port': instance.mixedPort,
|
||||
'authentication': instance.authentication,
|
||||
'allow-lan': instance.allowLan,
|
||||
'bind-address': instance.bindAddress,
|
||||
'mode': instance.mode,
|
||||
'log-level': instance.logLevel,
|
||||
'ipv6': instance.ipv6,
|
||||
};
|
27
lib/models/login_resp.dart
Normal file
27
lib/models/login_resp.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
/// This allows the `User` class to access private members in
|
||||
/// the generated file. The value for this is *.g.dart, where
|
||||
/// the star denotes the source file name.
|
||||
part 'login_resp.g.dart';
|
||||
|
||||
/// An annotation for the code generator to know that this class needs the
|
||||
/// JSON serialization logic to be generated.
|
||||
@JsonSerializable()
|
||||
class LoginResp {
|
||||
LoginResp(this.token, this.msg);
|
||||
|
||||
String token;
|
||||
String msg;
|
||||
|
||||
/// A necessary factory constructor for creating a new Configs instance
|
||||
/// from a map. Pass the map to the generated `_$ConfigsFromJson()` constructor.
|
||||
/// The constructor is named after the source class, in this case, Configs.
|
||||
factory LoginResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$LoginRespFromJson(json);
|
||||
|
||||
/// `toJson` is the convention for a class to declare support for serialization
|
||||
/// to JSON. The implementation simply calls the private, generated
|
||||
/// helper method `_$LoginRespToJson`.
|
||||
Map<String, dynamic> toJson() => _$LoginRespToJson(this);
|
||||
}
|
17
lib/models/login_resp.g.dart
Normal file
17
lib/models/login_resp.g.dart
Normal file
@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'login_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
LoginResp _$LoginRespFromJson(Map<String, dynamic> json) => LoginResp(
|
||||
json['token'] as String,
|
||||
json['msg'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$LoginRespToJson(LoginResp instance) => <String, dynamic>{
|
||||
'token': instance.token,
|
||||
'msg': instance.msg,
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class TokenNotifier extends Notifier<String> {
|
||||
@override
|
||||
@ -8,6 +9,16 @@ class TokenNotifier extends Notifier<String> {
|
||||
|
||||
setToken(String token) {
|
||||
state = token;
|
||||
SharedPreferences.getInstance().then((prefs) {
|
||||
prefs.setString("token", token);
|
||||
});
|
||||
}
|
||||
|
||||
removeToken() {
|
||||
state = '';
|
||||
SharedPreferences.getInstance().then((prefs) {
|
||||
prefs.setString("token", "");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
11
lib/request/http_client.dart
Normal file
11
lib/request/http_client.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class HttpClient {
|
||||
HttpClient(this.header);
|
||||
|
||||
Map<String, String>? header;
|
||||
|
||||
Future post(Uri url) {
|
||||
return http.post(url);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Login> createState() => _LoginState();
|
||||
}
|
||||
|
||||
class _LoginState extends State<Login> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
@ -6,6 +6,18 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <screen_retriever/screen_retriever_plugin.h>
|
||||
#include <tray_manager/tray_manager_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
|
||||
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
|
||||
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) window_manager_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
|
||||
window_manager_plugin_register_with_registrar(window_manager_registrar);
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
screen_retriever
|
||||
tray_manager
|
||||
window_manager
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
@ -5,8 +5,14 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import screen_retriever
|
||||
import shared_preferences_foundation
|
||||
import tray_manager
|
||||
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"))
|
||||
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
|
||||
}
|
||||
|
40
pubspec.lock
40
pubspec.lock
@ -437,6 +437,14 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
menu_base:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: menu_base
|
||||
sha256: "820368014a171bd1241030278e6c2617354f492f5c703d7b7d4570a6b8b84405"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.1.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -581,6 +589,14 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
screen_retriever:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever
|
||||
sha256: "4931f226ca158123ccd765325e9fbf360bfed0af9b460a10f960f9bb13d58323"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.1.6"
|
||||
scroll_pos:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -661,6 +677,14 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
shortid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shortid
|
||||
sha256: d0b40e3dbb50497dad107e19c54ca7de0d1a274eb9b4404991e443dadb9ebedb
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.1.2"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -754,6 +778,14 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
tray_manager:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: tray_manager
|
||||
sha256: b1975a05e0c6999e983cf9a58a6a098318c896040ccebac5398a3cc9e43b9c69
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -794,6 +826,14 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
window_manager:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: window_manager
|
||||
sha256: "5bdd29dc5f1f3185fc90696373a571d77968e03e5e820fb1ecdbdade3f5d8fff"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -44,6 +44,8 @@ dependencies:
|
||||
flutter_launcher_icons: ^0.11.0
|
||||
shared_preferences: ^2.0.17
|
||||
flutter_riverpod: ^2.1.3
|
||||
window_manager: ^0.3.0
|
||||
tray_manager: ^0.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
@ -6,6 +6,15 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <screen_retriever/screen_retriever_plugin.h>
|
||||
#include <tray_manager/tray_manager_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
ScreenRetrieverPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
|
||||
TrayManagerPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
|
||||
WindowManagerPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
screen_retriever
|
||||
tray_manager
|
||||
window_manager
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
Reference in New Issue
Block a user