123 lines
5.3 KiB
Dart
123 lines
5.3 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:downloadsfolder/downloadsfolder.dart';
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:filesystem_picker/filesystem_picker.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
|
|
class Settings extends StatefulWidget {
|
|
Settings({super.key});
|
|
|
|
@override
|
|
State<Settings> createState() => _SettingsState();
|
|
}
|
|
|
|
class _SettingsState extends State<Settings> {
|
|
late Directory downloadFolder;
|
|
late SharedPreferences prefs;
|
|
late PackageInfo packageInfo;
|
|
|
|
Future<String> _init() async {
|
|
prefs = await SharedPreferences.getInstance();
|
|
Directory defaultDownloadDirectory = await getDownloadDirectory();
|
|
downloadFolder = Directory(
|
|
prefs.getString('downloadFolder') ?? defaultDownloadDirectory.path);
|
|
packageInfo = await PackageInfo.fromPlatform();
|
|
return 'ok';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('settings').tr(),
|
|
),
|
|
body: FutureBuilder<String>(
|
|
future: _init(),
|
|
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return CircularProgressIndicator();
|
|
} else if (snapshot.hasError) {
|
|
return Center(child: Text('Error: ${snapshot.error}'));
|
|
} else if (snapshot.hasData) {
|
|
return LayoutBuilder(builder:
|
|
(BuildContext context, BoxConstraints viewportConstraints) {
|
|
return viewportConstraints.maxHeight < double.infinity
|
|
? Center(
|
|
child: Container(
|
|
constraints: viewportConstraints,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 10),
|
|
Text('settings').tr(),
|
|
SizedBox(height: 10),
|
|
Flexible(
|
|
child: ListView(
|
|
children: [
|
|
ListTile(
|
|
title: Text('download_folder').tr(),
|
|
subtitle: Text(downloadFolder.path),
|
|
trailing: IconButton(
|
|
icon: Icon(Icons.folder),
|
|
onPressed: () async {
|
|
String? selectedDirectory =
|
|
await FilePicker.platform
|
|
.getDirectoryPath();
|
|
|
|
if (selectedDirectory != null) {
|
|
prefs.setString('downloadFolder',
|
|
selectedDirectory);
|
|
setState(() {
|
|
downloadFolder =
|
|
Directory(selectedDirectory);
|
|
});
|
|
}
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text('language').tr(),
|
|
subtitle:
|
|
Text(context.locale.toString()).tr(),
|
|
trailing: DropdownButton(
|
|
items: context.supportedLocales
|
|
.map((locale) {
|
|
return DropdownMenuItem(
|
|
value: locale.toString(),
|
|
child: Text(locale.toString()).tr(),
|
|
);
|
|
}).toList(),
|
|
value: context.locale.toString(),
|
|
onChanged: (String? value) => {
|
|
if (value != null)
|
|
{
|
|
context.setLocale(Locale(
|
|
value.split("_")[0],
|
|
value.split("_")[1])),
|
|
}
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text('build_version').tr(),
|
|
subtitle: Text(packageInfo.version),
|
|
),
|
|
],
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: CircularProgressIndicator();
|
|
});
|
|
} else {
|
|
return Center(child: Text('No data'));
|
|
}
|
|
},
|
|
));
|
|
}
|
|
}
|