Cryptocurrency Tracker docs
v2.0.0
Live demoConsole demo Get help
● Set up · Android and iOS

Home-screen widgets
watchlist and portfolio.

Two widgets on Android and iOS: the watchlist (up to 4 coins with price and 24-hour change) and the selected portfolio's value. They refresh themselves every 30 minutes from your API.

Android AppWidgetsiOS WidgetKit9 languages

01The two widgets

WidgetShowsTap
WatchlistPrice and 24-hour change of up to 4 coins from the user's watchlist, in the user's currencyOpens the app; tapping a coin row opens that coin
PortfolioThe selected portfolio's value and 24-hour changeOpens the app

They follow the system light or dark mode and are translated into the 9 app languages. The web demo has no widgets.

02How they get data

  • The app writes the watchlist, the selected portfolio and your API_BASE_URL to storage the widgets can read (app/lib/services/widget_sync.dart, package home_widget). On Android that is the HomeWidgetPreferences SharedPreferences; on iOS the App Group shared with the widget extension.
  • Between app launches the widgets fetch fresh prices themselves from <API_BASE_URL>/v1/markets?ids=… every 30 minutes: on Android with WorkManager (WidgetRefreshWorker.kt), on iOS with a WidgetKit timeline (WidgetStore.swift). The operating system decides the exact moment, so a refresh can come later.
  • No key and no account are involved: the markets endpoint is public and cached.

03Switch widgets off, or make them Pro-only

Two console switches control the widgets without a new build. The app applies them each time it loads the configuration (app/lib/bootstrap.dart, docs/CONTRACT.md §7).

Console settingDefaultWhat the user's widgets show
Features → Home-screen widgets offOn"Open the app to enable widgets"
Pro and purchases → Home-screen widgets for Pro only onOff"Widgets are a Pro feature" for users without Pro. Applies only while Offer Pro is on; otherwise nobody could unlock them, so the widgets keep showing data.
  • While a notice is shown the widgets hold no prices and do not refresh themselves. The notice is translated into the 9 languages (ct_widget_disabled_off and ct_widget_disabled_pro on Android, disabled.off and disabled.pro on iOS).
  • The app keeps the watchlist and portfolio and shows them in the widgets again as soon as the switch is turned back, or the user gets Pro.
  • The app waits until it knows whether the user has Pro, so a Pro user's widgets do not briefly show the notice at start.
  • A widget only changes after the app has started once with the new configuration.

04Android files

FileWhat
app/android/app/src/main/kotlin/com/yourcompany/cryptotracker/WatchlistWidgetProvider.kt, PortfolioWidgetProvider.kt, WidgetViews.kt, WidgetStore.kt, WidgetRefreshWorker.kt
app/android/app/src/main/res/layout/ct_widget_*.xmlLayouts
app/android/app/src/main/res/xml/ct_widget_*_info.xmlSizes and the preview
app/android/app/src/main/res/values*/ct_widget_*.xmlTexts per language, colours (light and values-night), dimensions

The receivers are declared in AndroidManifest.xml. The Dart side refers to them by the Kotlin package (com.yourcompany.cryptotracker), not by the application id, so changing applicationId alone does not break widget updates.

05iOS widget extension

FileWhat
app/ios/CryptoTrackerWidget/CryptoTrackerWidget.swiftThe two widgets, their look (accent #10B981, light and dark) and timeline
app/ios/CryptoTrackerWidget/WidgetStore.swiftReads the App Group and refreshes prices
app/ios/CryptoTrackerWidget/*.lproj/Texts in 9 languages
app/ios/CryptoTrackerWidget/CryptoTrackerWidget.entitlementsThe App Group
app/ios/scripts/add_widget_extension.rbAdds or repairs the extension target in the Xcode project

The extension target is already in Runner.xcodeproj, with bundle id <app bundle id>.CryptoTrackerWidget and iOS 15.0. Sign it with your team in Xcode. Run the script only after a rebrand or if the target got lost:

cd app/ios
ruby scripts/add_widget_extension.rb   # idempotent; uses the xcodeproj gem that ships with CocoaPods

06The App Group must match in four places

The app and the widget share data through the App Group group.com.yourcompany.cryptotracker. 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.entitlements
  • app/ios/CryptoTrackerWidget/CryptoTrackerWidget.entitlements
  • app/ios/CryptoTrackerWidget/WidgetStore.swift (appGroup)
  • app/lib/services/widget_sync.dart (appGroup)

A mismatch shows as an iOS widget in its empty state even though the app has data.

07Change the look

Widget colours are native, not taken from the console's accent: edit Theme in CryptoTrackerWidget.swift and values/ct_widget_colors.xml plus values-night/ct_widget_colors.xml on Android. See Rebranding.