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 = 37 (so AGP 9), and MainActivity extending FlutterFragmentActivity
iOS 15.0, with Swift Package Manager; no CocoaPods
Google Maps (iOS) 9.x - an app using Google Maps itself must be on 9.x too (see Package.swift at the repository root)

Swift Package Manager on Flutter 3.41. It uses CocoaPods by default; turn SPM on for your app in its pubspec.yaml (or for every app with flutter config --enable-swift-package-manager):

flutter:
  config:
    enable-swift-package-manager: true

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-sdk from the Maven repository https://download.day.io/sdk/maven, which the plugin adds to the app's repositories. An app whose settings.gradle.kts sets repositoriesMode to FAIL_ON_PROJECT_REPOS adds it there itself: maven("https://download.day.io/sdk/maven").
  • iOS - DaySDK.xcframework from https://download.day.io/sdk/ios/<version>/, with Google Maps 9.x and SQLCipher from their Swift packages.

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, as example/ios/Flutter/*.xcconfig has.

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.swift finds the repository and depends on its root Package.swift, which uses the debug xcframework. 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.

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 AppBar or in a SafeArea.
  • 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/.