Home-screen widgets
watchlist and portfolio.
Two widgets on Android and iOS: the watchlist and the selected portfolio. They refresh themselves about every 30 minutes from your API.
01The two widgets
| Widget | Shows | Tap |
|---|---|---|
| Watchlist | Prices and changes for tickers from the user's watchlist | Opens the app; a stock row opens that company (stockmaster://stock?symbol=…) |
| Portfolio | The selected portfolio's value | Opens the app |
They follow the system light or dark mode and are translated into the 9 app languages. The example build and the web build have no widgets.
02How they get data
- The app writes the watchlist, the selected portfolio and your
API_BASE_URLto storage the widgets can read (app/lib/services/widget_sync.dart, packagehome_widget): SharedPreferences on Android, the App Group on iOS. - Between app launches the widgets fetch fresh prices themselves from
<API_BASE_URL>/v1/quotes?symbols=…every 30 minutes: Android with WorkManager (WidgetRefreshWorker.kt), iOS with a WidgetKit timeline (WidgetStore.swift). The operating system decides the exact moment. - No key and no account are involved, but the quotes endpoint is a price endpoint: without the display licence the widgets have no prices (Market data).
03Switch widgets off, or make them Pro-only
| Console setting | Default | Effect |
|---|---|---|
| Features → Home-screen widgets off | On | The widgets show a notice that the operator switched widgets off. |
| Pro and purchases → Widgets for Pro only on | Off | Users without Pro see a Pro notice. Applies only while Pro is on sale. |
A widget changes after the app has started once with the new configuration. Settings → Home-screen widgets explains the state to the user.
04Android files
| File | What |
|---|---|
app/android/app/src/main/kotlin/com/yourcompany/stockmaster/ | WatchlistWidgetProvider.kt, PortfolioWidgetProvider.kt, WidgetViews.kt, WidgetStore.kt, WidgetRefreshWorker.kt |
app/android/app/src/main/res/layout/sm_widget_*.xml | Layouts |
app/android/app/src/main/res/xml/sm_widget_*_info.xml | Sizes and preview |
app/android/app/src/main/res/values*/sm_widget_*.xml | Texts per language, colours (light and values-night), dimensions |
The receivers are declared in AndroidManifest.xml. The Dart side refers to the providers by the Kotlin package (androidPackage in widget_sync.dart). If you move the Kotlin files to your own package, change both together.
05iOS widget extension
| File | What |
|---|---|
app/ios/StockMasterWidget/StockMasterWidget.swift | The two widgets (kinds StockMasterWatchlist and StockMasterPortfolio) and their timeline |
app/ios/StockMasterWidget/WidgetStore.swift | Reads the App Group and refreshes prices |
app/ios/StockMasterWidget/*.lproj/ | Texts in 9 languages |
app/ios/StockMasterWidget/StockMasterWidget.entitlements | The App Group |
app/ios/scripts/add_widget_extension.rb | Adds or repairs the extension target in the Xcode project |
The extension target is already in Runner.xcodeproj, with bundle id <app bundle id>.StockMasterWidget and iOS 15.0. Sign it with your team. Run the script only if the target got lost: cd app/ios && ruby scripts/add_widget_extension.rb.
06The App Group must match in four places
The app and the widget share data through the App Group group.com.yourcompany.stockmaster. When you change the bundle id, change the group in all of these, register it in your Apple Developer account and enable it for both App IDs:
app/ios/Runner/Runner.entitlementsapp/ios/StockMasterWidget/StockMasterWidget.entitlementsapp/ios/StockMasterWidget/WidgetStore.swift(appGroup)app/lib/services/widget_sync.dart(WidgetSync.appGroup)
A mismatch shows as an iOS widget in its empty state although the app has data.
07Change the look
Widget colours are native and are not taken from the app's theme tokens: edit the colours in StockMasterWidget.swift and values/sm_widget_colors.xml plus values-night/sm_widget_colors.xml on Android.