Added create tag
This commit is contained in:
@@ -93,7 +93,7 @@ class AddBookmark extends _$AddBookmark {
|
||||
final processModal = ProcessModal();
|
||||
processModal.open(t.bookmarks.addBookmark.savingBookmark);
|
||||
|
||||
final result = await ref.watch(apiClientProvider)!.fetchPostBookmark(newBookmark);
|
||||
final result = await ref.watch(apiClientProvider)!.postBookmark(newBookmark);
|
||||
|
||||
processModal.close();
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ final getTagsProvider =
|
||||
);
|
||||
|
||||
typedef GetTagsRef = AutoDisposeFutureProviderRef<ApiResponse<TagsResponse>>;
|
||||
String _$addBookmarkHash() => r'2953a4223fe70809fbcf37af23b4f61a62f0de9f';
|
||||
String _$addBookmarkHash() => r'7a2a1c6c6597aa28fa478d2ef9dc3bc4d71c143d';
|
||||
|
||||
/// See also [AddBookmark].
|
||||
@ProviderFor(AddBookmark)
|
||||
|
||||
9
lib/screens/tags/models/add_tag.modal.dart
Normal file
9
lib/screens/tags/models/add_tag.modal.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AddTagModel {
|
||||
final TextEditingController nameController;
|
||||
|
||||
const AddTagModel({
|
||||
required this.nameController,
|
||||
});
|
||||
}
|
||||
47
lib/screens/tags/provider/add_tag.provider.dart
Normal file
47
lib/screens/tags/provider/add_tag.provider.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/tags/ui/add_tag_error_modal.dart';
|
||||
import 'package:linkdy/screens/tags/provider/tags.provider.dart';
|
||||
import 'package:linkdy/screens/tags/models/add_tag.modal.dart';
|
||||
|
||||
import 'package:linkdy/router/routes.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/utils/process_modal.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
part 'add_tag.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
class AddTag extends _$AddTag {
|
||||
@override
|
||||
AddTagModel build() {
|
||||
return AddTagModel(
|
||||
nameController: TextEditingController(),
|
||||
);
|
||||
}
|
||||
|
||||
void notifyOnWrite() {
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void onAddTag() async {
|
||||
final processModal = ProcessModal();
|
||||
processModal.open(t.tags.createTag.creatingTag);
|
||||
|
||||
final result = await ref.watch(apiClientProvider)!.postTag(state.nameController.text);
|
||||
|
||||
processModal.close();
|
||||
if (result.successful == true) {
|
||||
ref.invalidate(tagsRequestProvider);
|
||||
ref.watch(routerProvider).pop();
|
||||
} else {
|
||||
if (rootNavigatorKey.currentContext == null) return;
|
||||
showDialog(
|
||||
context: rootNavigatorKey.currentContext!,
|
||||
builder: (context) => const AddTagErrorModal(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
lib/screens/tags/provider/add_tag.provider.g.dart
Normal file
25
lib/screens/tags/provider/add_tag.provider.g.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'add_tag.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$addTagHash() => r'8157bc7911ae64627adabbe1528f519a4b1cb913';
|
||||
|
||||
/// See also [AddTag].
|
||||
@ProviderFor(AddTag)
|
||||
final addTagProvider =
|
||||
AutoDisposeNotifierProvider<AddTag, AddTagModel>.internal(
|
||||
AddTag.new,
|
||||
name: r'addTagProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$addTagHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$AddTag = AutoDisposeNotifier<AddTagModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
24
lib/screens/tags/ui/add_tag_error_modal.dart
Normal file
24
lib/screens/tags/ui/add_tag_error_modal.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class AddTagErrorModal extends StatelessWidget {
|
||||
const AddTagErrorModal({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(t.generic.error),
|
||||
content: Text(t.tags.createTag.errorCreatingTag),
|
||||
actions: [
|
||||
Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(t.generic.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
90
lib/screens/tags/ui/add_tag_modal.dart
Normal file
90
lib/screens/tags/ui/add_tag_modal.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/tags/provider/add_tag.provider.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class AddTagModal extends ConsumerWidget {
|
||||
const AddTagModal({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = ref.watch(addTagProvider);
|
||||
|
||||
return Padding(
|
||||
padding: MediaQuery.of(context).viewInsets,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(28),
|
||||
topRight: Radius.circular(28),
|
||||
),
|
||||
color: Theme.of(context).dialogBackgroundColor,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add_rounded,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
t.tags.createTag.createTag,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextFormField(
|
||||
controller: provider.nameController,
|
||||
onChanged: (_) => ref.read(addTagProvider.notifier).notifyOnWrite(),
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.label_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.tags.createTag.name,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 24),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(t.generic.cancel),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: provider.nameController.text != ""
|
||||
? () => ref.read(addTagProvider.notifier).onAddTag()
|
||||
: null,
|
||||
child: Text(t.generic.confirm),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/tags/provider/tags.provider.dart';
|
||||
import 'package:linkdy/screens/tags/ui/add_tag_modal.dart';
|
||||
import 'package:linkdy/utils/date_to_string.dart';
|
||||
import 'package:linkdy/widgets/error_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
@@ -17,22 +18,13 @@ class TagsScreen extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tags = ref.watch(tagsRequestProvider);
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
void openAddModal() {
|
||||
// showGeneralDialog(
|
||||
// context: context,
|
||||
// barrierColor: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)) ? Colors.transparent : Colors.black54,
|
||||
// transitionBuilder: (context, anim1, anim2, child) {
|
||||
// return SlideTransition(
|
||||
// position: Tween(begin: const Offset(0, 1), end: const Offset(0, 0)).animate(
|
||||
// CurvedAnimation(parent: anim1, curve: Curves.easeInOutCubicEmphasized),
|
||||
// ),
|
||||
// child: child,
|
||||
// );
|
||||
// },
|
||||
// pageBuilder: (context, animation, secondaryAnimation) => AddBookmarkModal(fullscreen: width <= 700),
|
||||
// );
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => const AddTagModal(),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -101,7 +93,7 @@ class TagsScreen extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
dateToString(tag.dateAdded!),
|
||||
t.tags.created(created: dateToString(tag.dateAdded!)),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
|
||||
Reference in New Issue
Block a user