Provider: nah, pass as arg: yah

This commit is contained in:
Filip Krawczyk 2021-11-06 18:49:45 +01:00
parent f51432d76e
commit 9d004cefd7
1 changed files with 12 additions and 14 deletions

View File

@ -8,7 +8,9 @@ import '../../../widgets/avatar.dart';
import 'blocks_store.dart'; import 'blocks_store.dart';
class BlockPersonDialog extends StatelessWidget { class BlockPersonDialog extends StatelessWidget {
const BlockPersonDialog(); final BlocksStore store;
const BlockPersonDialog(this.store);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -17,10 +19,10 @@ class BlockPersonDialog extends StatelessWidget {
content: TypeAheadField<PersonViewSafe>( content: TypeAheadField<PersonViewSafe>(
suggestionsCallback: (pattern) async { suggestionsCallback: (pattern) async {
if (pattern.trim().isEmpty) return const Iterable.empty(); if (pattern.trim().isEmpty) return const Iterable.empty();
return LemmyApiV3(context.read<BlocksStore>().instanceHost) return LemmyApiV3(store.instanceHost)
.run(Search( .run(Search(
q: pattern, q: pattern,
auth: context.read<BlocksStore>().token.raw, auth: store.token.raw,
type: SearchType.users, type: SearchType.users,
limit: 10, limit: 10,
)) ))
@ -58,16 +60,15 @@ class BlockPersonDialog extends StatelessWidget {
final store = context.read<BlocksStore>(); final store = context.read<BlocksStore>();
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => Provider.value( builder: (context) => BlockPersonDialog(store),
value: store,
child: const BlockPersonDialog(),
),
); );
} }
} }
class BlockCommunityDialog extends StatelessWidget { class BlockCommunityDialog extends StatelessWidget {
const BlockCommunityDialog(); final BlocksStore store;
const BlockCommunityDialog(this.store);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -76,10 +77,10 @@ class BlockCommunityDialog extends StatelessWidget {
content: TypeAheadField<CommunityView>( content: TypeAheadField<CommunityView>(
suggestionsCallback: (pattern) async { suggestionsCallback: (pattern) async {
if (pattern.trim().isEmpty) return const Iterable.empty(); if (pattern.trim().isEmpty) return const Iterable.empty();
return LemmyApiV3(context.read<BlocksStore>().instanceHost) return LemmyApiV3(store.instanceHost)
.run(Search( .run(Search(
q: pattern, q: pattern,
auth: context.read<BlocksStore>().token.raw, auth: store.token.raw,
type: SearchType.communities, type: SearchType.communities,
limit: 10, limit: 10,
)) ))
@ -117,10 +118,7 @@ class BlockCommunityDialog extends StatelessWidget {
final store = context.read<BlocksStore>(); final store = context.read<BlocksStore>();
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => Provider.value( builder: (context) => BlockCommunityDialog(store),
value: store,
child: const BlockCommunityDialog(),
),
); );
} }
} }