mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
Update
This commit is contained in:
@@ -3,8 +3,10 @@ import 'package:cookie_jar/cookie_jar.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
final dio = Dio();
|
||||
SharedPreferences? _prefs;
|
||||
|
||||
Future<void> prepareJar() async {
|
||||
final Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||
@@ -14,3 +16,14 @@ Future<void> prepareJar() async {
|
||||
);
|
||||
dio.interceptors.add(CookieManager(jar));
|
||||
}
|
||||
|
||||
Future<void> preparePrefs() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
SharedPreferences get prefs {
|
||||
if (_prefs == null) {
|
||||
throw Exception('SharedPreferences not initialized');
|
||||
}
|
||||
return _prefs!;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'globals.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
class HomePage extends HookWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
|
||||
static const String routeName = '/';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
useEffect(() {
|
||||
String? baseUrl = prefs.getString("baseUrl");
|
||||
if (baseUrl == null) {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
context.go("/set_server");
|
||||
});
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}, []);
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Text('Hello World!'),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'globals.dart';
|
||||
import 'home.dart';
|
||||
import 'set_server.dart';
|
||||
|
||||
final _router = GoRouter(
|
||||
routes: [
|
||||
@@ -9,12 +11,17 @@ final _router = GoRouter(
|
||||
path: HomePage.routeName,
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: SetServerPage.routeName,
|
||||
builder: (context, state) => const SetServerPage(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
void main() async {
|
||||
await prepareJar();
|
||||
if (!kIsWeb) await prepareJar();
|
||||
await preparePrefs();
|
||||
runApp(const MainApp());
|
||||
}
|
||||
|
||||
|
||||
38
lib/set_server.dart
Normal file
38
lib/set_server.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SetServerPage extends StatefulWidget {
|
||||
const SetServerPage({Key? key}) : super(key: key);
|
||||
|
||||
static const String routeName = '/set_server';
|
||||
|
||||
@override
|
||||
State<SetServerPage> createState() => _SetServerPageState();
|
||||
}
|
||||
|
||||
class _SetServerPageState extends State<SetServerPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
const Text('EH Downloader server url:'),
|
||||
const TextField(
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Server URL',
|
||||
),
|
||||
),
|
||||
const Text('API path'),
|
||||
TextField(
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'API Path',
|
||||
),
|
||||
controller: TextEditingController(text: "/api"),
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -230,6 +230,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_hooks:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_hooks
|
||||
sha256: "9eab8fd7aa752c3c1c0a364f9825851d410eb935243411682f4b1b0a4c569d71"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.20.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
||||
@@ -11,6 +11,7 @@ dependencies:
|
||||
dio_cookie_manager: ^3.1.0+1
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_hooks: ^0.20.0
|
||||
go_router: ^10.1.0
|
||||
json_annotation: ^4.8.1
|
||||
path_provider: ^2.1.0
|
||||
|
||||
Reference in New Issue
Block a user