mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-08 02:57:38 +08:00
feat: update setting page
This commit is contained in:
@@ -53,8 +53,8 @@ func (s *Server) Serve() error {
|
|||||||
|
|
||||||
setting := api.Group("/setting")
|
setting := api.Group("/setting")
|
||||||
{
|
{
|
||||||
setting.POST("/do", HttpHandler(s.SetSetting))
|
setting.POST("/general", HttpHandler(s.SetSetting))
|
||||||
setting.GET("/do", HttpHandler(s.GetSetting))
|
setting.GET("/general", HttpHandler(s.GetSetting))
|
||||||
setting.POST("/auth", HttpHandler(s.EnableAuth))
|
setting.POST("/auth", HttpHandler(s.EnableAuth))
|
||||||
setting.GET("/auth", HttpHandler(s.GetAuthSetting))
|
setting.GET("/auth", HttpHandler(s.GetAuthSetting))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,40 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"polaris/log"
|
"polaris/db"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type setSettingIn struct {
|
type GeneralSettings struct {
|
||||||
Key string `json:"key"`
|
TmdbApiKey string `json:"tmdb_api_key"`
|
||||||
Value string `json:"value"`
|
DownloadDir string `json:"download_dir"`
|
||||||
}
|
}
|
||||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||||
var in setSettingIn
|
var in GeneralSettings
|
||||||
if err := c.ShouldBindJSON(&in); err != nil {
|
if err := c.ShouldBindJSON(&in); err != nil {
|
||||||
return nil, errors.Wrap(err, "bind json")
|
return nil, errors.Wrap(err, "bind json")
|
||||||
}
|
}
|
||||||
err := s.db.SetSetting(in.Key, in.Value)
|
if in.TmdbApiKey != "" {
|
||||||
return nil, err
|
if err := s.db.SetSetting(db.SettingTmdbApiKey, in.TmdbApiKey); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "save tmdb api")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if in.DownloadDir == "" {
|
||||||
|
if err := s.db.SetSetting(db.SettingDownloadDir, in.DownloadDir); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "save download dir")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||||
q := c.Query("key")
|
tmdb := s.db.GetSetting(db.SettingTmdbApiKey)
|
||||||
log.Infof("query key: %v", q)
|
downloadDir := s.db.GetSetting(db.SettingDownloadDir)
|
||||||
if q == "" {
|
return &GeneralSettings{
|
||||||
return nil, nil
|
TmdbApiKey: tmdb,
|
||||||
}
|
DownloadDir: downloadDir,
|
||||||
v := s.db.GetSetting(q)
|
}, nil
|
||||||
log.Infof("get value for key %v: %v", q, v)
|
|
||||||
return gin.H{q: v}, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class _MovieDetailsPageState extends ConsumerState<MovieDetailsPage> {
|
|||||||
DataCell(Text("${torrent.size?.readableFileSize()}")),
|
DataCell(Text("${torrent.size?.readableFileSize()}")),
|
||||||
DataCell(Text("${torrent.seeders}")),
|
DataCell(Text("${torrent.seeders}")),
|
||||||
DataCell(Text("${torrent.peers}")),
|
DataCell(Text("${torrent.peers}")),
|
||||||
DataCell(IconButton.filledTonal(
|
DataCell(IconButton(
|
||||||
icon: const Icon(Icons.download),
|
icon: const Icon(Icons.download),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref
|
await ref
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class APIs {
|
|||||||
static final _baseUrl = baseUrl();
|
static final _baseUrl = baseUrl();
|
||||||
static final searchUrl = "$_baseUrl/api/v1/media/search";
|
static final searchUrl = "$_baseUrl/api/v1/media/search";
|
||||||
static final settingsUrl = "$_baseUrl/api/v1/setting/do";
|
static final settingsUrl = "$_baseUrl/api/v1/setting/do";
|
||||||
|
static final settingsGeneralUrl = "$_baseUrl/api/v1/setting/general";
|
||||||
static final watchlistTvUrl = "$_baseUrl/api/v1/media/tv/watchlist";
|
static final watchlistTvUrl = "$_baseUrl/api/v1/media/tv/watchlist";
|
||||||
static final watchlistMovieUrl = "$_baseUrl/api/v1/media/movie/watchlist";
|
static final watchlistMovieUrl = "$_baseUrl/api/v1/media/movie/watchlist";
|
||||||
static final availableMoviesUrl = "$_baseUrl/api/v1/media/movie/resources/";
|
static final availableMoviesUrl = "$_baseUrl/api/v1/media/movie/resources/";
|
||||||
|
|||||||
@@ -6,46 +6,38 @@ import 'package:quiver/strings.dart';
|
|||||||
import 'package:ui/providers/APIs.dart';
|
import 'package:ui/providers/APIs.dart';
|
||||||
import 'package:ui/providers/server_response.dart';
|
import 'package:ui/providers/server_response.dart';
|
||||||
|
|
||||||
var settingProvider =
|
var settingProvider = AsyncNotifierProvider.autoDispose
|
||||||
AsyncNotifierProvider.autoDispose.family<EditSettingData, String, String>(
|
<EditSettingData, GeneralSetting>(EditSettingData.new);
|
||||||
EditSettingData.new);
|
|
||||||
|
|
||||||
var indexersProvider =
|
var indexersProvider =
|
||||||
AsyncNotifierProvider.autoDispose<IndexerSetting, List<Indexer>>(IndexerSetting.new);
|
AsyncNotifierProvider.autoDispose<IndexerSetting, List<Indexer>>(
|
||||||
|
IndexerSetting.new);
|
||||||
|
|
||||||
var dwonloadClientsProvider =
|
var dwonloadClientsProvider = AsyncNotifierProvider.autoDispose<
|
||||||
AsyncNotifierProvider.autoDispose<DownloadClientSetting, List<DownloadClient>>(
|
DownloadClientSetting, List<DownloadClient>>(DownloadClientSetting.new);
|
||||||
DownloadClientSetting.new);
|
|
||||||
|
|
||||||
var storageSettingProvider =
|
var storageSettingProvider =
|
||||||
AsyncNotifierProvider.autoDispose<StorageSettingData, List<Storage>>(
|
AsyncNotifierProvider.autoDispose<StorageSettingData, List<Storage>>(
|
||||||
StorageSettingData.new);
|
StorageSettingData.new);
|
||||||
|
|
||||||
class EditSettingData extends AutoDisposeFamilyAsyncNotifier<String, String> {
|
class EditSettingData extends AutoDisposeAsyncNotifier<GeneralSetting> {
|
||||||
String? key;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOr<String> build(String arg) async {
|
FutureOr<GeneralSetting> build() async {
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
key = arg;
|
|
||||||
var resp = await dio.get(APIs.settingsUrl, queryParameters: {"key": arg});
|
var resp = await dio.get(APIs.settingsGeneralUrl);
|
||||||
var rrr = ServerResponse.fromJson(resp.data);
|
var rrr = ServerResponse.fromJson(resp.data);
|
||||||
if (rrr.code != 0) {
|
if (rrr.code != 0) {
|
||||||
throw rrr.message;
|
throw rrr.message;
|
||||||
}
|
}
|
||||||
var data = rrr.data as Map<String, dynamic>;
|
final ss = GeneralSetting.fromJson(rrr.data);
|
||||||
var value = data[arg] as String;
|
return ss;
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateSettings(String v) async {
|
Future<void> updateSettings(GeneralSetting gs) async {
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
var resp = await dio.post(APIs.settingsUrl, data: {
|
var resp = await dio.post(APIs.settingsGeneralUrl, data: gs.toJson());
|
||||||
"key": key,
|
var sp = ServerResponse.fromJson(resp.data);
|
||||||
"value": v,
|
|
||||||
});
|
|
||||||
var sp = ServerResponse.fromJson(resp.data as Map<String, dynamic>);
|
|
||||||
if (sp.code != 0) {
|
if (sp.code != 0) {
|
||||||
throw sp.message;
|
throw sp.message;
|
||||||
}
|
}
|
||||||
@@ -53,6 +45,25 @@ class EditSettingData extends AutoDisposeFamilyAsyncNotifier<String, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GeneralSetting {
|
||||||
|
String? tmdbApiKey;
|
||||||
|
String? downloadDIr;
|
||||||
|
|
||||||
|
GeneralSetting({this.tmdbApiKey, this.downloadDIr});
|
||||||
|
|
||||||
|
factory GeneralSetting.fromJson(Map<String, dynamic> json) {
|
||||||
|
return GeneralSetting(
|
||||||
|
tmdbApiKey: json["tmdb_api_key"], downloadDIr: json["download_dir"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['tmdb_api_key'] = tmdbApiKey;
|
||||||
|
data['download_dir'] = downloadDIr;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class IndexerSetting extends AutoDisposeAsyncNotifier<List<Indexer>> {
|
class IndexerSetting extends AutoDisposeAsyncNotifier<List<Indexer>> {
|
||||||
@override
|
@override
|
||||||
FutureOr<List<Indexer>> build() async {
|
FutureOr<List<Indexer>> build() async {
|
||||||
@@ -121,7 +132,8 @@ class Indexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadClientSetting extends AutoDisposeAsyncNotifier<List<DownloadClient>> {
|
class DownloadClientSetting
|
||||||
|
extends AutoDisposeAsyncNotifier<List<DownloadClient>> {
|
||||||
@override
|
@override
|
||||||
FutureOr<List<DownloadClient>> build() async {
|
FutureOr<List<DownloadClient>> build() async {
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
@@ -247,7 +259,8 @@ class StorageSettingData extends AutoDisposeAsyncNotifier<List<Storage>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
Storage({this.id, this.name, this.implementation, this.settings, this.isDefault});
|
Storage(
|
||||||
|
{this.id, this.name, this.implementation, this.settings, this.isDefault});
|
||||||
|
|
||||||
final int? id;
|
final int? id;
|
||||||
final String? name;
|
final String? name;
|
||||||
@@ -257,12 +270,11 @@ class Storage {
|
|||||||
|
|
||||||
factory Storage.fromJson(Map<String, dynamic> json1) {
|
factory Storage.fromJson(Map<String, dynamic> json1) {
|
||||||
return Storage(
|
return Storage(
|
||||||
id: json1["id"],
|
id: json1["id"],
|
||||||
name: json1["name"],
|
name: json1["name"],
|
||||||
implementation: json1["implementation"],
|
implementation: json1["implementation"],
|
||||||
settings: json.decode(json1["settings"]),
|
settings: json.decode(json1["settings"]),
|
||||||
isDefault: json1["default"]
|
isDefault: json1["default"]);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import 'package:ui/providers/login.dart';
|
|||||||
import 'package:ui/providers/settings.dart';
|
import 'package:ui/providers/settings.dart';
|
||||||
import 'package:ui/utils.dart';
|
import 'package:ui/utils.dart';
|
||||||
import 'package:ui/widgets/progress_indicator.dart';
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
import 'package:ui/widgets/widgets.dart';
|
||||||
import 'providers/APIs.dart';
|
|
||||||
|
|
||||||
class SystemSettingsPage extends ConsumerStatefulWidget {
|
class SystemSettingsPage extends ConsumerStatefulWidget {
|
||||||
static const route = "/settings";
|
static const route = "/settings";
|
||||||
@@ -19,227 +18,134 @@ class SystemSettingsPage extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
||||||
final GlobalKey _formKey = GlobalKey<FormState>();
|
final GlobalKey _formKey = GlobalKey<FormState>();
|
||||||
Future<void>? _pendingTmdb;
|
|
||||||
Future<void>? _pendingIndexer;
|
|
||||||
Future<void>? _pendingDownloadClient;
|
|
||||||
Future<void>? _pendingStorage;
|
|
||||||
final _tmdbApiController = TextEditingController();
|
final _tmdbApiController = TextEditingController();
|
||||||
final _downloadDirController = TextEditingController();
|
final _downloadDirController = TextEditingController();
|
||||||
bool? _enableAuth;
|
bool? _enableAuth;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var tmdbKey = ref.watch(settingProvider(APIs.tmdbApiKey));
|
var settings = ref.watch(settingProvider);
|
||||||
var dirKey = ref.watch(settingProvider(APIs.downloadDirKey));
|
|
||||||
|
|
||||||
var tmdbSetting = FutureBuilder(
|
var tmdbSetting = settings.when(
|
||||||
// We listen to the pending operation, to update the UI accordingly.
|
data: (v) {
|
||||||
future: _pendingTmdb,
|
_tmdbApiController.text = v.tmdbApiKey!;
|
||||||
builder: (context, snapshot) {
|
_downloadDirController.text = v.downloadDIr!;
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.fromLTRB(40, 10, 40, 0),
|
padding: const EdgeInsets.fromLTRB(40, 10, 40, 0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
tmdbKey.when(
|
TextFormField(
|
||||||
data: (value) {
|
autofocus: true,
|
||||||
_tmdbApiController.text = value;
|
controller: _tmdbApiController,
|
||||||
return TextFormField(
|
decoration: Commons.requiredTextFieldStyle(
|
||||||
autofocus: true,
|
text: "TMDB Api Key", icon: const Icon(Icons.key)),
|
||||||
controller: _tmdbApiController,
|
//
|
||||||
decoration: const InputDecoration(
|
validator: (v) {
|
||||||
labelText: "TMDB Api Key",
|
return v!.trim().isNotEmpty ? null : "ApiKey 不能为空";
|
||||||
icon: Icon(Icons.key),
|
|
||||||
),
|
|
||||||
//
|
|
||||||
validator: (v) {
|
|
||||||
return v!.trim().isNotEmpty ? null : "ApiKey 不能为空";
|
|
||||||
},
|
|
||||||
onSaved: (newValue) {},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
error: (err, trace) => Text("$err"),
|
onSaved: (newValue) {},
|
||||||
loading: () => const MyProgressIndicator()),
|
|
||||||
dirKey.when(
|
|
||||||
data: (data) {
|
|
||||||
_downloadDirController.text = data;
|
|
||||||
return TextFormField(
|
|
||||||
autofocus: true,
|
|
||||||
controller: _downloadDirController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: "下载路径",
|
|
||||||
icon: Icon(Icons.folder),
|
|
||||||
),
|
|
||||||
//
|
|
||||||
validator: (v) {
|
|
||||||
return v!.trim().isNotEmpty ? null : "ApiKey 不能为空";
|
|
||||||
},
|
|
||||||
onSaved: (newValue) {},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
error: (err, trace) => Text("$err"),
|
|
||||||
loading: () => const MyProgressIndicator()),
|
|
||||||
Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 28.0),
|
|
||||||
child: ElevatedButton(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(16.0),
|
|
||||||
child: Text("保存"),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
// 通过_formKey.currentState 获取FormState后,
|
|
||||||
// 调用validate()方法校验用户名密码是否合法,校验
|
|
||||||
// 通过后再提交数据。
|
|
||||||
if ((_formKey.currentState as FormState).validate()) {
|
|
||||||
var furture = ref
|
|
||||||
.read(settingProvider(APIs.tmdbApiKey).notifier)
|
|
||||||
.updateSettings(_tmdbApiController.text);
|
|
||||||
ref
|
|
||||||
.read(settingProvider(APIs.downloadDirKey)
|
|
||||||
.notifier)
|
|
||||||
.updateSettings(_downloadDirController.text);
|
|
||||||
setState(() {
|
|
||||||
_pendingTmdb = furture;
|
|
||||||
});
|
|
||||||
showError(snapshot);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
TextFormField(
|
||||||
],
|
autofocus: true,
|
||||||
),
|
controller: _downloadDirController,
|
||||||
),
|
decoration: Commons.requiredTextFieldStyle(
|
||||||
);
|
text: "下载路径", icon: const Icon(Icons.folder)),
|
||||||
});
|
//
|
||||||
|
validator: (v) {
|
||||||
|
return v!.trim().isNotEmpty ? null : "下载路径不能为空";
|
||||||
|
},
|
||||||
|
onSaved: (newValue) {},
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 28.0),
|
||||||
|
child: ElevatedButton(
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(16.0),
|
||||||
|
child: Text("保存"),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
if ((_formKey.currentState as FormState)
|
||||||
|
.validate()) {
|
||||||
|
var f = ref
|
||||||
|
.read(settingProvider.notifier)
|
||||||
|
.updateSettings(GeneralSetting(
|
||||||
|
tmdbApiKey: _tmdbApiController.text,
|
||||||
|
downloadDIr:
|
||||||
|
_downloadDirController.text));
|
||||||
|
f.whenComplete(() {
|
||||||
|
Utils.showSnakeBar("更新成功");
|
||||||
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("更新失败:$e");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
error: (err, trace) => Text("$err"),
|
||||||
|
loading: () => const MyProgressIndicator());
|
||||||
|
|
||||||
var indexers = ref.watch(indexersProvider);
|
var indexers = ref.watch(indexersProvider);
|
||||||
var indexerSetting = FutureBuilder(
|
var indexerSetting = indexers.when(
|
||||||
// We listen to the pending operation, to update the UI accordingly.
|
data: (value) => Wrap(
|
||||||
future: _pendingIndexer,
|
children: List.generate(value.length + 1, (i) {
|
||||||
builder: (context, snapshot) {
|
if (i < value.length) {
|
||||||
return indexers.when(
|
var indexer = value[i];
|
||||||
data: (value) => GridView.builder(
|
return SettingsCard(
|
||||||
itemCount: value.length + 1,
|
onTap: () => showIndexerDetails(indexer),
|
||||||
scrollDirection: Axis.vertical,
|
child: Text(indexer.name!));
|
||||||
shrinkWrap: true,
|
}
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
return SettingsCard(
|
||||||
crossAxisCount: 6),
|
onTap: () => showIndexerDetails(Indexer()),
|
||||||
itemBuilder: (context, i) {
|
child: const Icon(Icons.add));
|
||||||
if (i < value.length) {
|
}),
|
||||||
var indexer = value[i];
|
),
|
||||||
return Card(
|
error: (err, trace) => Text("$err"),
|
||||||
margin: const EdgeInsets.all(4),
|
loading: () => const MyProgressIndicator());
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showIndexerDetails(snapshot, context, indexer);
|
|
||||||
},
|
|
||||||
child: Center(child: Text(indexer.name!))));
|
|
||||||
}
|
|
||||||
return Card(
|
|
||||||
margin: const EdgeInsets.all(4),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showIndexerDetails(snapshot, context, Indexer());
|
|
||||||
},
|
|
||||||
child: const Center(
|
|
||||||
child: Icon(Icons.add),
|
|
||||||
)));
|
|
||||||
}),
|
|
||||||
error: (err, trace) => Text("$err"),
|
|
||||||
loading: () => const MyProgressIndicator());
|
|
||||||
});
|
|
||||||
|
|
||||||
var downloadClients = ref.watch(dwonloadClientsProvider);
|
var downloadClients = ref.watch(dwonloadClientsProvider);
|
||||||
var downloadSetting = FutureBuilder(
|
var downloadSetting = downloadClients.when(
|
||||||
// We listen to the pending operation, to update the UI accordingly.
|
data: (value) => Wrap(
|
||||||
future: _pendingDownloadClient,
|
children: List.generate(value.length + 1, (i) {
|
||||||
builder: (context, snapshot) {
|
if (i < value.length) {
|
||||||
return downloadClients.when(
|
var client = value[i];
|
||||||
data: (value) => GridView.builder(
|
return SettingsCard(
|
||||||
itemCount: value.length + 1,
|
onTap: () => showDownloadClientDetails(client),
|
||||||
scrollDirection: Axis.vertical,
|
child: Text(client.name!));
|
||||||
shrinkWrap: true,
|
}
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
return SettingsCard(
|
||||||
crossAxisCount: 6),
|
onTap: () => showDownloadClientDetails(DownloadClient()),
|
||||||
itemBuilder: (context, i) {
|
child: const Icon(Icons.add));
|
||||||
if (i < value.length) {
|
})),
|
||||||
var client = value[i];
|
error: (err, trace) => Text("$err"),
|
||||||
return Card(
|
loading: () => const MyProgressIndicator());
|
||||||
margin: const EdgeInsets.all(4),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showDownloadClientDetails(
|
|
||||||
snapshot, context, client);
|
|
||||||
},
|
|
||||||
child: Center(child: Text(client.name!))));
|
|
||||||
}
|
|
||||||
return Card(
|
|
||||||
margin: const EdgeInsets.all(4),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showDownloadClientDetails(
|
|
||||||
snapshot, context, DownloadClient());
|
|
||||||
},
|
|
||||||
child: const Center(
|
|
||||||
child: Icon(Icons.add),
|
|
||||||
)));
|
|
||||||
}),
|
|
||||||
error: (err, trace) => Text("$err"),
|
|
||||||
loading: () => const MyProgressIndicator());
|
|
||||||
});
|
|
||||||
|
|
||||||
var storageSettingData = ref.watch(storageSettingProvider);
|
var storageSettingData = ref.watch(storageSettingProvider);
|
||||||
var storageSetting = FutureBuilder(
|
var storageSetting = storageSettingData.when(
|
||||||
// We listen to the pending operation, to update the UI accordingly.
|
data: (value) => Wrap(
|
||||||
future: _pendingStorage,
|
children: List.generate(value.length + 1, (i) {
|
||||||
builder: (context, snapshot) {
|
if (i < value.length) {
|
||||||
return storageSettingData.when(
|
var storage = value[i];
|
||||||
data: (value) => GridView.builder(
|
return SettingsCard(
|
||||||
itemCount: value.length + 1,
|
onTap: () => showStorageDetails(storage),
|
||||||
scrollDirection: Axis.vertical,
|
child: Text(storage.name!));
|
||||||
shrinkWrap: true,
|
}
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
return SettingsCard(
|
||||||
crossAxisCount: 6),
|
onTap: () => showStorageDetails(Storage()),
|
||||||
itemBuilder: (context, i) {
|
child: const Icon(Icons.add));
|
||||||
if (i < value.length) {
|
}),
|
||||||
var storage = value[i];
|
),
|
||||||
return Card(
|
error: (err, trace) => Text("$err"),
|
||||||
margin: const EdgeInsets.all(4),
|
loading: () => const MyProgressIndicator());
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showStorageDetails(snapshot, context, storage);
|
|
||||||
},
|
|
||||||
child: Center(child: Text(storage.name!))));
|
|
||||||
}
|
|
||||||
return Card(
|
|
||||||
margin: const EdgeInsets.all(4),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: InkWell(
|
|
||||||
//splashColor: Colors.blue.withAlpha(30),
|
|
||||||
onTap: () {
|
|
||||||
showStorageDetails(snapshot, context, Storage());
|
|
||||||
},
|
|
||||||
child: const Center(
|
|
||||||
child: Icon(Icons.add),
|
|
||||||
)));
|
|
||||||
}),
|
|
||||||
error: (err, trace) => Text("$err"),
|
|
||||||
loading: () => const MyProgressIndicator());
|
|
||||||
});
|
|
||||||
|
|
||||||
var authData = ref.watch(authSettingProvider);
|
var authData = ref.watch(authSettingProvider);
|
||||||
TextEditingController userController = TextEditingController();
|
TextEditingController userController = TextEditingController();
|
||||||
@@ -267,15 +173,18 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: userController,
|
controller: userController,
|
||||||
decoration: const InputDecoration(
|
decoration: Commons.requiredTextFieldStyle(
|
||||||
labelText: "用户名",
|
text: "用户名",
|
||||||
icon: Icon(Icons.verified_user),
|
icon: const Icon(Icons.account_box),
|
||||||
)),
|
)),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
obscureText: true,
|
||||||
|
enableSuggestions: false,
|
||||||
|
autocorrect: false,
|
||||||
controller: passController,
|
controller: passController,
|
||||||
decoration: const InputDecoration(
|
decoration: Commons.requiredTextFieldStyle(
|
||||||
labelText: "密码",
|
text: "密码",
|
||||||
icon: Icon(Icons.verified_user),
|
icon: const Icon(Icons.password),
|
||||||
))
|
))
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -284,10 +193,15 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
child: const Text("保存"),
|
child: const Text("保存"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ref
|
var f = ref
|
||||||
.read(authSettingProvider.notifier)
|
.read(authSettingProvider.notifier)
|
||||||
.updateAuthSetting(_enableAuth!,
|
.updateAuthSetting(_enableAuth!,
|
||||||
userController.text, passController.text);
|
userController.text, passController.text);
|
||||||
|
f.whenComplete(() {
|
||||||
|
Utils.showSnakeBar("更新成功");
|
||||||
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("更新失败:$e");
|
||||||
|
});
|
||||||
}))
|
}))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -298,6 +212,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
|
expandedAlignment: Alignment.centerLeft,
|
||||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: true,
|
||||||
@@ -305,23 +220,26 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
children: [tmdbSetting],
|
children: [tmdbSetting],
|
||||||
),
|
),
|
||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
|
expandedAlignment: Alignment.centerLeft,
|
||||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: false,
|
||||||
title: const Text("索引器设置"),
|
title: const Text("索引器设置"),
|
||||||
children: [indexerSetting],
|
children: [indexerSetting],
|
||||||
),
|
),
|
||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
|
expandedAlignment: Alignment.centerLeft,
|
||||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: false,
|
||||||
title: const Text("下载客户端设置"),
|
title: const Text("下载客户端设置"),
|
||||||
children: [downloadSetting],
|
children: [downloadSetting],
|
||||||
),
|
),
|
||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
|
expandedAlignment: Alignment.centerLeft,
|
||||||
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||||
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: false,
|
||||||
title: const Text("存储设置"),
|
title: const Text("存储设置"),
|
||||||
children: [storageSetting],
|
children: [storageSetting],
|
||||||
),
|
),
|
||||||
@@ -336,8 +254,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showIndexerDetails(
|
Future<void> showIndexerDetails(Indexer indexer) {
|
||||||
AsyncSnapshot<void> snapshot, BuildContext context, Indexer indexer) {
|
|
||||||
var nameController = TextEditingController(text: indexer.name);
|
var nameController = TextEditingController(text: indexer.name);
|
||||||
var urlController = TextEditingController(text: indexer.url);
|
var urlController = TextEditingController(text: indexer.url);
|
||||||
var apiKeyController = TextEditingController(text: indexer.apiKey);
|
var apiKeyController = TextEditingController(text: indexer.apiKey);
|
||||||
@@ -351,15 +268,15 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
child: ListBody(
|
child: ListBody(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: "名称"),
|
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: "地址"),
|
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||||
controller: urlController,
|
controller: urlController,
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: "API Key"),
|
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||||
controller: apiKeyController,
|
controller: apiKeyController,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -373,14 +290,17 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
var f = ref
|
var f = ref
|
||||||
.read(indexersProvider.notifier)
|
.read(indexersProvider.notifier)
|
||||||
.deleteIndexer(indexer.id!);
|
.deleteIndexer(indexer.id!);
|
||||||
setState(() {
|
f.whenComplete(() {
|
||||||
_pendingIndexer = f;
|
Utils.showSnakeBar("操作成功");
|
||||||
});
|
|
||||||
if (!showError(snapshot)) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: const Text('删除')),
|
child: const Text(
|
||||||
|
'删除',
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
)),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('取消')),
|
child: const Text('取消')),
|
||||||
@@ -392,13 +312,12 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
name: nameController.text,
|
name: nameController.text,
|
||||||
url: urlController.text,
|
url: urlController.text,
|
||||||
apiKey: apiKeyController.text));
|
apiKey: apiKeyController.text));
|
||||||
setState(() {
|
f.whenComplete(() {
|
||||||
_pendingIndexer = f;
|
Utils.showSnakeBar("操作成功");
|
||||||
});
|
|
||||||
|
|
||||||
if (!showError(snapshot)) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -406,8 +325,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showDownloadClientDetails(AsyncSnapshot<void> snapshot,
|
Future<void> showDownloadClientDetails(DownloadClient client) {
|
||||||
BuildContext context, DownloadClient client) {
|
|
||||||
var nameController = TextEditingController(text: client.name);
|
var nameController = TextEditingController(text: client.name);
|
||||||
var urlController = TextEditingController(text: client.url);
|
var urlController = TextEditingController(text: client.url);
|
||||||
|
|
||||||
@@ -421,11 +339,11 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
child: ListBody(
|
child: ListBody(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: "名称"),
|
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: "地址"),
|
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||||
controller: urlController,
|
controller: urlController,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -439,14 +357,17 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
var f = ref
|
var f = ref
|
||||||
.read(dwonloadClientsProvider.notifier)
|
.read(dwonloadClientsProvider.notifier)
|
||||||
.deleteDownloadClients(client.id!);
|
.deleteDownloadClients(client.id!);
|
||||||
setState(() {
|
f.whenComplete(() {
|
||||||
_pendingDownloadClient = f;
|
Utils.showSnakeBar("操作成功");
|
||||||
});
|
|
||||||
if (!showError(snapshot)) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: const Text('删除')),
|
child: const Text(
|
||||||
|
'删除',
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
)),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('取消')),
|
child: const Text('取消')),
|
||||||
@@ -457,12 +378,12 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
.read(dwonloadClientsProvider.notifier)
|
.read(dwonloadClientsProvider.notifier)
|
||||||
.addDownloadClients(
|
.addDownloadClients(
|
||||||
nameController.text, urlController.text);
|
nameController.text, urlController.text);
|
||||||
setState(() {
|
f.whenComplete(() {
|
||||||
_pendingDownloadClient = f;
|
Utils.showSnakeBar("操作成功");
|
||||||
});
|
|
||||||
if (!showError(snapshot)) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -470,8 +391,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showStorageDetails(
|
Future<void> showStorageDetails(Storage s) {
|
||||||
AsyncSnapshot<void> snapshot, BuildContext context, Storage s) {
|
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true, // user must tap button!
|
barrierDismissible: true, // user must tap button!
|
||||||
@@ -483,9 +403,9 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
var userController = TextEditingController();
|
var userController = TextEditingController();
|
||||||
var passController = TextEditingController();
|
var passController = TextEditingController();
|
||||||
if (s.settings != null) {
|
if (s.settings != null) {
|
||||||
tvPathController.text = s.settings!["tv_path"] ?? "";
|
tvPathController.text = s.settings!["tv_path"] ?? "";
|
||||||
moviePathController.text = s.settings!["movie_path"] ?? "";
|
moviePathController.text = s.settings!["movie_path"] ?? "";
|
||||||
urlController.text = s.settings!["url"]?? "";
|
urlController.text = s.settings!["url"] ?? "";
|
||||||
userController.text = s.settings!["user"] ?? "";
|
userController.text = s.settings!["user"] ?? "";
|
||||||
passController.text = s.settings!["password"] ?? "";
|
passController.text = s.settings!["password"] ?? "";
|
||||||
}
|
}
|
||||||
@@ -516,8 +436,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
controller: nameController,
|
controller: nameController,
|
||||||
),
|
),
|
||||||
selectImpl != "local"
|
selectImpl != "local"
|
||||||
?
|
? Column(
|
||||||
Column(
|
|
||||||
children: [
|
children: [
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
@@ -535,15 +454,16 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
controller: passController,
|
controller: passController,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
): Container(),
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "电视剧路径"),
|
|
||||||
controller: tvPathController,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "电影路径"),
|
|
||||||
controller: moviePathController,
|
|
||||||
)
|
)
|
||||||
|
: Container(),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "电视剧路径"),
|
||||||
|
controller: tvPathController,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "电影路径"),
|
||||||
|
controller: moviePathController,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -555,12 +475,12 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
var f = ref
|
var f = ref
|
||||||
.read(storageSettingProvider.notifier)
|
.read(storageSettingProvider.notifier)
|
||||||
.deleteStorage(s.id!);
|
.deleteStorage(s.id!);
|
||||||
setState(() {
|
f.whenComplete(() {
|
||||||
_pendingStorage = f;
|
Utils.showSnakeBar("操作成功");
|
||||||
});
|
|
||||||
if (!showError(snapshot)) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: const Text('删除')),
|
child: const Text('删除')),
|
||||||
TextButton(
|
TextButton(
|
||||||
@@ -569,7 +489,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('确定'),
|
child: const Text('确定'),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
ref
|
final f = ref
|
||||||
.read(storageSettingProvider.notifier)
|
.read(storageSettingProvider.notifier)
|
||||||
.addStorage(Storage(
|
.addStorage(Storage(
|
||||||
name: nameController.text,
|
name: nameController.text,
|
||||||
@@ -582,9 +502,12 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
"password": passController.text
|
"password": passController.text
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
if (!showError(snapshot)) {
|
f.whenComplete(() {
|
||||||
|
Utils.showSnakeBar("操作成功");
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}).onError((e, s) {
|
||||||
|
Utils.showSnakeBar("操作失败:$e");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -597,7 +520,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
final isErrored = snapshot.hasError &&
|
final isErrored = snapshot.hasError &&
|
||||||
snapshot.connectionState != ConnectionState.waiting;
|
snapshot.connectionState != ConnectionState.waiting;
|
||||||
if (isErrored) {
|
if (isErrored) {
|
||||||
Utils.showSnakeBar(context, "当前操作出错: ${snapshot.error}");
|
Utils.showSnakeBar("当前操作出错: ${snapshot.error}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
? const Icon(Icons.downloading)
|
? const Icon(Icons.downloading)
|
||||||
: (ep.status == "downloaded"
|
: (ep.status == "downloaded"
|
||||||
? const Icon(Icons.download_done)
|
? const Icon(Icons.download_done)
|
||||||
: const Icon(Icons.cloud_off))),
|
: const Icon(Icons.warning_rounded))),
|
||||||
),
|
),
|
||||||
DataCell(Row(
|
DataCell(Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton.filledTonal(
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var f = ref
|
var f = ref
|
||||||
.read(
|
.read(
|
||||||
@@ -78,14 +78,12 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
});
|
});
|
||||||
if (!Utils.showError(context, snapshot)) {
|
if (!Utils.showError(context, snapshot)) {
|
||||||
var name = await f;
|
var name = await f;
|
||||||
if (context.mounted) {
|
Utils.showSnakeBar("开始下载: $name");
|
||||||
Utils.showSnakeBar(context, "开始下载: $name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.search)),
|
icon: const Icon(Icons.search)),
|
||||||
const SizedBox(width: 10,),
|
const SizedBox(width: 10,),
|
||||||
IconButton.filledTonal(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
icon: const Icon(Icons.manage_search))
|
icon: const Icon(Icons.manage_search))
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:ui/providers/APIs.dart';
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
static Future<void> showAlertDialog(BuildContext context, String msg) async {
|
static Future<void> showAlertDialog(BuildContext context, String msg) async {
|
||||||
@@ -31,22 +32,27 @@ class Utils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static showSnakeBar(BuildContext context, String msg) {
|
static showSnakeBar(String msg) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg), showCloseIcon: true,));
|
final context = APIs.navigatorKey.currentContext;
|
||||||
|
if (context != null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(msg),
|
||||||
|
showCloseIcon: true,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool showError(BuildContext context, AsyncSnapshot snapshot) {
|
static bool showError(BuildContext context, AsyncSnapshot snapshot) {
|
||||||
final isErrored = snapshot.hasError &&
|
final isErrored = snapshot.hasError &&
|
||||||
snapshot.connectionState != ConnectionState.waiting;
|
snapshot.connectionState != ConnectionState.waiting;
|
||||||
if (isErrored) {
|
if (isErrored) {
|
||||||
Utils.showSnakeBar(context, "当前操作出错: ${snapshot.error}");
|
Utils.showSnakeBar("当前操作出错: ${snapshot.error}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extension FileFormatter on num {
|
extension FileFormatter on num {
|
||||||
String readableFileSize({bool base1024 = true}) {
|
String readableFileSize({bool base1024 = true}) {
|
||||||
final base = base1024 ? 1024 : 1000;
|
final base = base1024 ? 1024 : 1000;
|
||||||
|
|||||||
41
ui/lib/widgets/widgets.dart
Normal file
41
ui/lib/widgets/widgets.dart
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Commons {
|
||||||
|
static InputDecoration requiredTextFieldStyle({
|
||||||
|
required String text,
|
||||||
|
Widget? icon,
|
||||||
|
}) {
|
||||||
|
return InputDecoration(
|
||||||
|
label: Row(
|
||||||
|
children: [
|
||||||
|
Text(text),
|
||||||
|
const Text(
|
||||||
|
"*",
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
icon: icon,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsCard extends StatelessWidget {
|
||||||
|
final Widget? child;
|
||||||
|
final GestureTapCallback? onTap;
|
||||||
|
|
||||||
|
const SettingsCard({super.key, required this.child, this.onTap});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Card(
|
||||||
|
margin: const EdgeInsets.all(4),
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
child: InkWell(
|
||||||
|
//splashColor: Colors.blue.withAlpha(30),
|
||||||
|
onTap: onTap,
|
||||||
|
child:
|
||||||
|
SizedBox(width: 150, height: 150, child: Center(child: child))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user