-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
221 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'dart:async'; | ||
import 'dart:developer'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:fluttertoast/fluttertoast.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:transfer_client/main.dart'; | ||
import 'package:transfer_client/page/home/config/page.dart'; | ||
|
||
class DownloadPath extends StatelessWidget implements ConfigWiget { | ||
DownloadPath({super.key}) { | ||
textEditingController = TextEditingController(); | ||
textEditingController.text = GlobalConfig.download_path.toString(); | ||
fToast = FToast(); | ||
fToast.init(navigatorKey.currentContext!); | ||
} | ||
|
||
Config global = GlobalConfig; | ||
static const String PrefKey = "config.download_path"; | ||
late FToast fToast; | ||
|
||
static void setConfig(Config global, String val) { | ||
log("donwload path: $val"); | ||
global.download_path = val; | ||
} | ||
|
||
Widget toast = Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(0.0), | ||
color: Colors.greenAccent, | ||
), | ||
child: const Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon(Icons.check), | ||
SizedBox( | ||
width: 12.0, | ||
), | ||
Text("Download path saved"), | ||
], | ||
), | ||
); | ||
|
||
late TextEditingController textEditingController; | ||
Timer timer = Timer(const Duration(microseconds: 0), () {}); | ||
void onHostCommit(String p) async { | ||
timer?.cancel(); | ||
timer = Timer(const Duration(seconds: 1), () async { | ||
setConfig(global, p); | ||
(await SharedPreferences.getInstance()).setString(PrefKey, p); | ||
fToast.showToast(child: toast, gravity: ToastGravity.TOP_RIGHT); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ListTile( | ||
textColor: Colors.white, | ||
leading: const Icon( | ||
Icons.lens_blur, | ||
size: 40, | ||
color: Colors.white, | ||
), | ||
title: const Text("Download Path"), | ||
subtitle: TextField( | ||
// keyboardType: TextInputType.text, | ||
controller: textEditingController, | ||
// inputFormatters: <TextInputFormatter>[ | ||
// FilteringTextInputFormatter.digitsOnly | ||
// ], | ||
onSubmitted: onHostCommit, | ||
onChanged: onHostCommit, | ||
cursorColor: Colors.white, | ||
decoration: const InputDecoration( | ||
enabledBorder: UnderlineInputBorder( | ||
borderSide: BorderSide(color: Colors.white)), | ||
focusedBorder: UnderlineInputBorder( | ||
borderSide: BorderSide(color: Colors.white))), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
static Future<void> initConfig(Config global, SharedPreferences prefs) async { | ||
String a; | ||
try { | ||
a = prefs.getString(PrefKey)!; | ||
} catch (err) { | ||
var ddir = await getDownloadsDirectory(); | ||
if (ddir == null) { | ||
throw Exception("Download dir not found!"); | ||
} | ||
var dir = Directory("${ddir.absolute.path}/transfer_client"); | ||
if (!dir.existsSync()) dir.createSync(); | ||
a = dir.absolute.path; | ||
} | ||
setConfig(global, a); | ||
} | ||
|
||
static String getDownloadPath() { | ||
var path = GlobalConfig.download_path; | ||
if (path == "") { | ||
throw Exception("Download path not set!"); | ||
} | ||
var dir = Directory(path); | ||
if (!dir.existsSync()) dir.createSync(); | ||
return GlobalConfig.download_path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:transfer_client/page/home/custom_component.dart'; | ||
import 'package:transfer_client/page/home/homepage.dart'; | ||
|
||
import 'download_path.dart'; | ||
|
||
class DownloadConfig extends StatelessWidget { | ||
List<Widget> getDownloadConfig() { | ||
List<Widget> b = []; | ||
var temp = <Widget>[ | ||
DownloadPath(), | ||
]; | ||
for (Widget a in temp) { | ||
// b.add(Card(color: actionColor, child: SizedBox.expand(child: a))); | ||
b.add(Card(color: actionColor, child: a)); | ||
} | ||
return b; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CustomConfigSec( | ||
context, | ||
"Download Config", | ||
Column( | ||
children: getDownloadConfig(), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.