Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve initial options from a SQLite database in Flutter when configuring iOS widgets? #217

Open
disonwei opened this issue Jan 31, 2024 · 1 comment

Comments

@disonwei
Copy link

@available(iOS 16.0, *)
struct HabitEntity: AppEntity{
let id: Int
let title: String

static var typeDisplayRepresentation: TypeDisplayRepresentation="widget color"
static var defaultQuery=HabitEntityQuery()

var displayRepresentation: DisplayRepresentation{
    DisplayRepresentation(title:"\(title)")
}


static let allHabits:[HabitEntity]=[
    HabitEntity(id: 1, title: "1"),
    HabitEntity(id: 2, title: "3"),
    HabitEntity(id: 3, title: "2"),
]

}

@available(iOS 16.0, *)
struct HabitEntityQuery:EntityQuery{
func entities(for identifiers: [HabitEntity.ID]) async throws -> [HabitEntity] {
HabitEntity.allHabits.filter{
identifiers.contains($0.id)
}
}

func suggestedEntities() async throws -> [HabitEntity] {

// HabitEntity.allHabits

// HabitDao.shared.getHabitList() ?? HabitEntity.allHabits;

}


func defaultResult() async -> HabitEntity? {
    try? await suggestedEntities().first
}

}

The code for my configurable widget is as above.

I want the initial value selected by the user to come from the Flutter SQLite database.

How can I retrieve this initial value and see it in the home_widget document?

I only saw how to send data from the Flutter side to the widget and receive data from the widget.

How can the widget actively request data from Flutter when the user clicks on the configuration?

@ABausG
Copy link
Owner

ABausG commented Mar 24, 2024

home_widget on iOS works by using an app group to share data between your app and the widget. I am not sure if an AppExtension is able to retrieve data from a database on iOS.

Without knowing your specific setup generally you should be able to do the following:

  • In Flutter get the data from your database
  • Store it using home_widget

Check the docs regarding interactivity about how to update data from the widget. I have also written an article about that here: https://medium.com/@ABausG/interactive-homescreen-widgets-with-flutter-using-home-widget-83cb0706a417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants