A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.2 KiB

part of '../neon_news.dart';
3 years ago
class NewsAddFeedDialog extends StatefulWidget {
const NewsAddFeedDialog({
required this.bloc,
this.folderID,
super.key,
});
final NewsBloc bloc;
final int? folderID;
@override
State<NewsAddFeedDialog> createState() => _NewsAddFeedDialogState();
}
class _NewsAddFeedDialogState extends State<NewsAddFeedDialog> {
final formKey = GlobalKey<FormState>();
final controller = TextEditingController();
news.Folder? folder;
3 years ago
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop((controller.text, widget.folderID ?? folder?.id));
3 years ago
}
}
@override
void initState() {
super.initState();
unawaited(
Clipboard.getData(Clipboard.kTextPlain).then((final clipboardContent) {
if (clipboardContent != null && clipboardContent.text != null) {
final uri = Uri.tryParse(clipboardContent.text!);
if (uri != null && (uri.scheme == 'http' || uri.scheme == 'https')) {
controller.text = clipboardContent.text!;
}
}
}),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
3 years ago
@override
Widget build(final BuildContext context) => ResultBuilder<List<news.Folder>>.behaviorSubject(
subject: widget.bloc.folders,
builder: (final context, final folders) => NeonDialog(
title: Text(NewsLocalizations.of(context).feedAdd),
3 years ago
children: [
Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
TextFormField(
autofocus: true,
controller: controller,
decoration: const InputDecoration(
hintText: 'https://...',
),
keyboardType: TextInputType.url,
3 years ago
validator: (final input) => validateHttpUrl(context, input),
onFieldSubmitted: (final _) {
submit();
},
),
if (widget.folderID == null) ...[
Center(
child: NeonError(
folders.error,
onRetry: widget.bloc.refresh,
3 years ago
),
),
Center(
child: NeonLinearProgressIndicator(
visible: folders.isLoading,
3 years ago
),
),
if (folders.hasData) ...[
3 years ago
NewsFolderSelect(
folders: folders.requireData,
3 years ago
value: folder,
onChanged: (final f) {
setState(() {
folder = f;
});
},
),
],
],
ElevatedButton(
onPressed: folders.hasData ? submit : null,
child: Text(NewsLocalizations.of(context).feedAdd),
3 years ago
),
],
),
),
],
),
);
}