Skip to main content

How to filter feed based on values in the custom widget?

Introduction

In this guide, you'll learn how to filter feed based on values in the custom widget using the LikeMinds Feed Flutter SDK. LMFeedList widget can be used to render feed with a particular custom widget id.

Prerequisites

Before you begin, ensure the following:

  • LikeMinds Feed Flutter SDK: The SDK must be properly installed and initialized in your Flutter project. Refer to the installation guide if needed.
  • Feed Enabled: Ensure that Feed is enabled on the dashboard for your project.
  • Basic Understanding of Flutter Widgets: Familiarity with Flutter widgets and layout concepts.
  • Knowledge of Builder Pattern: Understanding of the builder pattern in Dart, as it is used to customize and create widgets dynamically.
  • Familiarity with copyWith Method: Knowledge of the copyWith method, which allows you to create modified copies of objects while retaining their original properties.

Steps

Step 1: Get widget id using getWidgets() method from LikeMinds-Feed-SDK

// variable to store widgetIds
List<String>? widgetIds;

// create GetWidgetRequest object
GetWidgetRequest request = (GetWidgetRequestBuilder()
..searchKey("metadata.YOUR_CUSTOM_KEY")
..searchValue("YOUR_CUSTOM_VALUE")
..page(1)
..pageSize(10))
.build();

// fetch widgets data
GetWidgetResponse response =
await LMFeedCore.instance.lmFeedClient.getWidgets(request);

// assign widgetIds in case of successful response
if (response.success) {
widgetIds = response.widgets?.map((widget) => widget.id).toList();
}

Step 2: Create a new screen using Scaffold widget to utilize LMFeedList widget.

class LMCustomFeed extends StatelessWidget {
LMCustomFeed({
super.key,
required this.widgetIds,
});
// List to store custom widget ids
final List<String> widgetIds;

// create a pagingController to pass in LMFeedList
final pagingController =
PagingController<int, LMPostViewData>(firstPageKey: 1);

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Custom Widget Feed'),
),
body: CustomScrollView(
slivers: [
LMFeedList(
widgetIds: widgetIds,
pagingController: pagingController,
),
],
),
);
}
}

Step 3: Navigate to above create Custom Widget Feed Screen

// create a route to custom widget feed with widget ids
final customFeedRoute = MaterialPageRoute(
builder: (context) => LMCustomFeed(
// replace the ids with the specific widget IDs
// based on which you want to filter the feed
widgetIds: [widgetIds.first],
),
);

// navigate to custom widget feed screen
Navigator.push(context, customFeedRoute);