Hesham desires to attract extra consideration to this query.
I’ve 2 WidgetKit widgets which are created utilizing an AppIntentConfiguration:
var physique: some WidgetConfiguration {
AppIntentConfiguration(form: form, intent: SelectValueTrackerIntent.self, supplier: TrackerTimelineProvider(trackerType: .worth)) { entry in
TracKitWidgetEntryView(timelineEntry: entry)
.containerBackground(Colour.tk_mainBackgroundColor, for: .widget)
}
.configurationDisplayName(“My Widget”)
.description(“That is an instance widget.”)
}
Every widget makes use of an intent to offer widget configuration with dynamic values. Each widgets fetch the identical knowledge by way of the community, however every one in every of them filters the info barely in a different way to offer a distinct checklist of attainable values.
I have never been capable of finding a approach to make this setup work with out duplicating all of the code used for the app intent.
This is the remainder of the code used:
struct SelectValueTrackerIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource = “Choose Tracker”
static var description = IntentDescription(“Selects the tracker to show info for.”)
@Parameter(title: “Tracker”)
var tracker: ValueTrackerAppEntity
}
struct ValueTrackerAppEntity: AppEntity {
static var defaultQuery = ValueTrackerQuery()
static var typeDisplayRepresentation: TypeDisplayRepresentation = “Tracker”
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: “(title)”)
}
var id: String
let title: String
}
struct ValueTrackerQuery: EntityQuery {
func entities(for identifiers: [String]) async throws -> [ValueTrackerAppEntity] {
return strive await entitiesForAllTrackers().filter {
identifiers.incorporates($0.id)
}
}
func suggestedEntities() async throws -> [ValueTrackerAppEntity] {
return strive await entitiesForAllTrackers()
}
func defaultResult() async -> ValueTrackerAppEntity? {
if let tracker = strive? await entitiesForAllTrackers().first {
return tracker
}
return nil
}
}
Is there a manner of with the ability to move a configuration parameter to SelectValueTrackerIntent, ValueTrackerAppEntity or ValueTrackerQuery to have the ability to present totally different knowledge, provided that WidgetConfigurationIntent and AppEntity are initialized internally by WidgetKit?