day_sdk
Flutter plugin for the Day.io SDK: sign the employee in from your backend, then show the Day.io attendance screen (clocking in and out, breaks, punch history) in your own colors and font.
It wraps the native SDK one to one. The repository's INTEGRATION.md explains the flow, the
backend's one-time token and every state; this page covers what is Flutter-specific.
Requirements
| Minimum | |
|---|---|
| Flutter | 3.27; tested with 3.41.9 (pinned in .fvmrc) |
| Android | API 26, compileSdk = 36 or newer, and MainActivity extending FlutterFragmentActivity |
| iOS | 15.0, with CocoaPods or Swift Package Manager |
| Google Maps (iOS) | 9.x - an app using Google Maps itself must be on 9.x too (see Package.swift at the repository root) |
CocoaPods or Swift Package Manager. The plugin works with either; Flutter picks by your app's
setting, so keep the one your app uses. Flutter 3.41 uses CocoaPods unless SPM is on in the app's
pubspec.yaml (flutter: config: enable-swift-package-manager: true) or for every app
(flutter config --enable-swift-package-manager).
- CocoaPods - set the platform in
ios/Podfiletoplatform :ios, '15.0'or later and keep Flutter'suse_frameworks!. Google Maps comes from your app's pods: withgoogle_maps_flutter, both plugins share oneGoogleMapspod. - Swift Package Manager - Google Maps and SQLCipher come from their Swift packages, which SPM
shares with the rest of the app. Don't mix the two: an app on SPM whose Google Maps still comes
from CocoaPods (an older
google_maps_flutter_ios) links Google Maps twice.
Kotlin on Flutter 3.41. An app made from an older template applies Kotlin itself
(id("kotlin-android") in android/app/build.gradle.kts); the plugin applies it to itself. An app
using integration_test with AGP 9 also needs android.uniquePackageNames=false in
android/gradle.properties: 3.41's integration_test brings espresso 3.2.0, whose libraries share
a namespace.
Where the native SDK comes from
The plugin brings the Day.io SDK itself, from https://download.day.io/sdk:
- Android -
day.io:day-sdkfrom the Maven repositoryhttps://download.day.io/sdk/maven, which the plugin adds to the app's repositories. An app whosesettings.gradle.ktssetsrepositoriesModetoFAIL_ON_PROJECT_REPOSadds it there itself:maven("https://download.day.io/sdk/maven"). - iOS -
DaySDK.xcframeworkfromhttps://download.day.io/sdk/ios/<version>/, with SQLCipher 4.19.0, which it links against, and Google Maps 9.x. With SPM, all three are Swift packages. With CocoaPods,pod installdownloadsDaySDK.xcframeworkandSQLCipher.xcframework(from the SQLCipher.swift release) into the plugin'sios/Frameworksand checks their checksums. Google Maps is theGoogleMapspod. The app gets its SQLCipher from the plugin, so it can't have another SQLCipher pod (such assqflite_sqlcipher's). The plugin's folder has to be writable for the firstpod installafter a plugin update, which matters for a CI with a read-only pub cache.
The xcframework has no x86_64 simulator slice. An app built for all simulators
(flutter build ios --simulator) needs EXCLUDED_ARCHS[sdk=iphonesimulator*] = x86_64 in
ios/Flutter/Debug.xcconfig and Release.xcconfig, after #include "Generated.xcconfig", as
example/ios/Flutter/*.xcconfig has. This applies with CocoaPods and with SPM: Flutter's
Generated.xcconfig sets EXCLUDED_ARCHS itself, and the app's own line has to come after it to
win. flutter run on an Apple Silicon Mac builds only arm64 and doesn't need it.
Building it from this repository
Inside the SDK repository the plugin builds against the repository's own SDK instead:
-
Android - the example sets
daySdkMavenLocal=true(example/android/gradle.properties), so Maven local comes first. Publish the SDK there:./gradlew :library:publishAndroidPublicationToMavenLocal :library:publishKotlinMultiplatformPublicationToMavenLocal -
iOS - the plugin's
Package.swiftfinds the repository and depends on its rootPackage.swift, which uses the debug xcframework. With CocoaPods,day_sdk.podspeclinks the same debug xcframework and Gradle's SQLCipher intoios/Frameworks/repository. Build it first:./gradlew :library:assembleDaySDKDebugXCFramework
A release (scripts/release-sdk.sh at the repository root) builds both for download.day.io and
writes the iOS zip's checksum into the plugin's Package.swift. day_sdk.podspec reads the version
and checksum from there.
Platform setup
Android - android/app/src/main/kotlin/.../MainActivity.kt:
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity : FlutterFragmentActivity()
The attendance screen and the location permission dialog need an AndroidX activity; with a plain
FlutterActivity the widget shows a message instead. For the SDK's maps, add your Google Maps key
to the manifest (com.google.android.geo.API_KEY meta-data) - without it the maps are hidden.
iOS - Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location is used to verify where you clock in and out.</string>
<!-- Optional: your Google Maps key; or DaySdk.setGoogleMapsApiKey(key) at runtime -->
<key>DaySdkGoogleMapsApiKey</key>
<string>$(DAY_SDK_GOOGLE_MAPS_KEY)</string>
Usage
import 'package:day_sdk/day_sdk.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await DaySdk.initialize(
environment: DayEnvironment.prod, // or stage, matching your backend's tokens
onSessionInvalid: () { /* get a new one-time token from your backend, call DaySdk.start */ },
);
runApp(const MyApp());
}
// After the employee signs in to your app:
final last = await DaySdk.lastAuthenticatedAt; // UTC, or null
final state = last == null || DateTime.now().toUtc().difference(last).inDays > 30
? await DaySdk.start(await backend.fetchDayOneTimeToken())
: await DaySdk.resume();
switch (state) {
case DaySdkReady():
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const AttendancePage()));
case DaySdkSessionInvalid():
// after resume: no session on the device - call start with a new token
case DaySdkFailed(:final message):
// network or server error - retry later (with a new token if it was start)
default:
// DaySdkNoActiveProfile, DaySdkProfileNotFound, DaySdkMissingCompany - account setup on Day.io
}
// When the employee signs out of your app:
await DaySdk.signOut();
DaySdk.state and DaySdk.isOnline are streams that start with the current value. No method
throws: platform errors come back as DaySdkFailed.
Language
The SDK screens come in English and Brazilian Portuguese and follow the device language; a language the SDK has no translation for shows in English. If your app has its own language setting, pass it on every app start - it wins over the device language and applies right away, also to a screen already showing:
await DaySdk.setLanguage('pt-BR'); // a BCP 47 tag; 'pt_BR' works too
await DaySdk.setLanguage(null); // follow the device language again
It can be called before initialize too. The SDK doesn't store it.
The attendance screen
class AttendancePage extends StatelessWidget {
const AttendancePage({super.key});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(title: const Text('Attendance')),
body: DaySdkAttendance(
configuration: DaySdkConfiguration(
colors: DaySdkColors(primary: scheme.primary, onPrimary: scheme.onPrimary, background: scheme.surface),
font: const DaySdkFont.assets(['fonts/Inter-Regular.ttf', 'fonts/Inter-Bold.ttf']),
),
),
);
}
}
- Show it once the state is
DaySdkReady; before that it is empty. - It doesn't pad for the status bar - put it under an
AppBaror in aSafeArea. - Every color and the font are optional. A new configuration (e.g. on a theme change) shows right away.
- Fonts are Flutter assets, by the path in your pubspec; weights are read from the files.
- It is a platform view (hybrid composition on Android) and takes every touch in its area.
Example
example/ signs in with a one-time token you paste (STAGE), shows the state and connectivity, and
opens the attendance screen with a switch between the app's colors and Day.io's. Run it with
flutter run in example/.