✨ Support new feed API
✨ Able to add tag onto post
This commit is contained in:
56
lib/widgets/posts/feed_list.dart
Normal file
56
lib/widgets/posts/feed_list.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import 'package:solian/models/feed.dart';
|
||||
import 'package:solian/models/post.dart';
|
||||
import 'package:solian/widgets/centered_container.dart';
|
||||
import 'package:solian/widgets/posts/post_list.dart';
|
||||
|
||||
class FeedListWidget extends StatelessWidget {
|
||||
final bool isShowEmbed;
|
||||
final bool isClickable;
|
||||
final bool isNestedClickable;
|
||||
final PagingController<int, FeedRecord> controller;
|
||||
|
||||
const FeedListWidget({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.isShowEmbed = true,
|
||||
this.isClickable = true,
|
||||
this.isNestedClickable = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PagedSliverList<int, FeedRecord>.separated(
|
||||
pagingController: controller,
|
||||
builderDelegate: PagedChildBuilderDelegate<FeedRecord>(
|
||||
itemBuilder: (context, item, index) {
|
||||
return RepaintBoundary(
|
||||
child: CenteredContainer(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (item.type) {
|
||||
case 'post':
|
||||
final data = Post.fromJson(item.data);
|
||||
return PostListEntryWidget(
|
||||
isShowEmbed: isShowEmbed,
|
||||
isNestedClickable: isNestedClickable,
|
||||
isClickable: isClickable,
|
||||
item: data,
|
||||
onUpdate: () {
|
||||
controller.refresh();
|
||||
},
|
||||
);
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
separatorBuilder: (_, __) => const Divider(thickness: 0.3, height: 0.3),
|
||||
);
|
||||
}
|
||||
}
|
@ -29,28 +29,13 @@ class PostListWidget extends StatelessWidget {
|
||||
itemBuilder: (context, item, index) {
|
||||
return RepaintBoundary(
|
||||
child: CenteredContainer(
|
||||
child: GestureDetector(
|
||||
child: PostItem(
|
||||
key: Key('p${item.alias}'),
|
||||
item: item,
|
||||
isShowEmbed: isShowEmbed,
|
||||
isClickable: isNestedClickable,
|
||||
).paddingSymmetric(vertical: 8),
|
||||
onTap: () {
|
||||
if (!isClickable) return;
|
||||
AppRouter.instance.pushNamed(
|
||||
'postDetail',
|
||||
pathParameters: {'alias': item.alias},
|
||||
);
|
||||
},
|
||||
onLongPress: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) => PostAction(item: item),
|
||||
).then((value) {
|
||||
if (value != null) controller.refresh();
|
||||
});
|
||||
child: PostListEntryWidget(
|
||||
isShowEmbed: isShowEmbed,
|
||||
isNestedClickable: isNestedClickable,
|
||||
isClickable: isClickable,
|
||||
item: item,
|
||||
onUpdate: () {
|
||||
controller.refresh();
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -61,3 +46,48 @@ class PostListWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PostListEntryWidget extends StatelessWidget {
|
||||
final bool isShowEmbed;
|
||||
final bool isNestedClickable;
|
||||
final bool isClickable;
|
||||
final Post item;
|
||||
final Function onUpdate;
|
||||
|
||||
const PostListEntryWidget({
|
||||
super.key,
|
||||
required this.isShowEmbed,
|
||||
required this.isNestedClickable,
|
||||
required this.isClickable,
|
||||
required this.item,
|
||||
required this.onUpdate,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
child: PostItem(
|
||||
key: Key('p${item.alias}'),
|
||||
item: item,
|
||||
isShowEmbed: isShowEmbed,
|
||||
isClickable: isNestedClickable,
|
||||
).paddingSymmetric(vertical: 8),
|
||||
onTap: () {
|
||||
if (!isClickable) return;
|
||||
AppRouter.instance.pushNamed(
|
||||
'postDetail',
|
||||
pathParameters: {'alias': item.alias},
|
||||
);
|
||||
},
|
||||
onLongPress: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) => PostAction(item: item),
|
||||
).then((value) {
|
||||
if (value != null) onUpdate();
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
91
lib/widgets/posts/tags_field.dart
Normal file
91
lib/widgets/posts/tags_field.dart
Normal file
@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:textfield_tags/textfield_tags.dart';
|
||||
|
||||
class TagsField extends StatelessWidget {
|
||||
final String hintText;
|
||||
|
||||
const TagsField({
|
||||
super.key,
|
||||
required this.hintText,
|
||||
required StringTagController<String> tagsController,
|
||||
}) : _tagsController = tagsController;
|
||||
|
||||
final StringTagController<String> _tagsController;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
child: TextFieldTags<String>(
|
||||
letterCase: LetterCase.small,
|
||||
textfieldTagsController: _tagsController,
|
||||
textSeparators: const [' ', ','],
|
||||
inputFieldBuilder: (context, inputFieldValues) {
|
||||
return TextField(
|
||||
controller: inputFieldValues.textEditingController,
|
||||
focusNode: inputFieldValues.focusNode,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
hintText: hintText,
|
||||
border: InputBorder.none,
|
||||
prefixIconConstraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.8,
|
||||
),
|
||||
prefixIcon: inputFieldValues.tags.isNotEmpty
|
||||
? SingleChildScrollView(
|
||||
controller: inputFieldValues.tagScrollController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: inputFieldValues.tags.map((String tag) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(20.0),
|
||||
),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
margin: const EdgeInsets.only(right: 10.0),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0, vertical: 4.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
InkWell(
|
||||
child: Text(
|
||||
'#$tag',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
onTap: () {
|
||||
//print("$tag selected");
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
InkWell(
|
||||
child: const Icon(
|
||||
Icons.cancel,
|
||||
size: 14.0,
|
||||
color: Color.fromARGB(255, 233, 233, 233),
|
||||
),
|
||||
onTap: () {
|
||||
inputFieldValues.onTagRemoved(tag);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
onChanged: inputFieldValues.onTagChanged,
|
||||
onSubmitted: inputFieldValues.onTagSubmitted,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user