Skip to content

mixin27/background_runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

background_runtime

CI

A production-grade federated Flutter plugin for long-running background execution.

Supports background downloads, audio playback, native notifications, and task execution across all major platforms.


AI-Generated Code Notice

This codebase is substantially generated by AI coding agents (opencode), acting on human-authored instructions in a human-in-the-loop workflow. Every commit goes through the same pipeline: specification by a human, generation by an AI agent, human review, and automated CI checks.

For Contributors

  • You are welcome — human contributions are valued and encouraged. Do not let the AI origin of the codebase discourage you from opening issues or submitting PRs.
  • Your review matters — the code may contain patterns an AI considers optimal but are non-idiomatic or incorrect. Calling them out in review helps the whole project.
  • Follow the same rules — PR standards in CONTRIBUTING.md and AGENTS.md apply to everyone, human or AI. No shortcuts.

For Consumers

  • Audit before depending on it — treat each file as a draft written by an enthusiastic but fallible developer. The tests pass, the analysis is clean, but edge-case bugs may exist.
  • CI is the floor, not the ceiling — the project passes dart analyze and flutter test, but that does not guarantee production readiness in your specific environment.
  • File issues — if you find something wrong, open a bug report. The AI will learn from it on the next iteration.

Features

  • Background Downloads — Download files in the background with progress tracking, pause/resume/cancel support
  • Audio Playback — Background audio playback with state reporting, seek support, and lock screen controls
  • Native Notifications — Foreground service notifications (Android), system notifications (iOS/macOS)
  • State Persistence — Runtime state saved across app restarts via platform-native storage
  • Unified API — Single Dart API that works identically across all platforms

Platform Support

Platform Status Key Technologies
Android ✅ Production Foreground Service, Media3 ExoPlayer, OkHttp, Room
iOS ✅ Production Background URLSession, AVAudioPlayer, MPRemoteCommandCenter
macOS ✅ Production Background URLSession, AVAudioPlayer
Windows 🚧 Stub WinRT (planned)
Linux 🚧 Stub libcurl, GStreamer (planned)
Web ⚠️ Best-effort Limited capabilities

Getting Started

Prerequisites

  • Flutter >=3.22.0
  • Dart ^3.5.0
  • Android: minSdk 24
  • iOS: 15.0+
  • macOS: 12.0+

Installation

dependencies:
  background_runtime: ^0.1.0

Android Setup

Add the following permissions to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

iOS Setup

Add Background Modes to your Info.plist:

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
  <string>download</string>
</array>

Also enable UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace for public file access.

macOS Setup

Add the following entitlements to your Runner.entitlements:

<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>

Quick Start

import 'package:background_runtime/background_runtime.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await BackgroundRuntime.initialize(
    BackgroundRuntimeConfig(
      enableDownloads: true,
      enableAudio: true,
      enableNotifications: true,
    ),
  );

  // Start a download
  final taskId = await BackgroundRuntime.download(
    DownloadRequest(
      url: 'https://example.com/file.zip',
      destinationPath: 'downloads/file.zip',
    ),
  );

  // Observe progress
  BackgroundRuntime.observeDownloads().listen((event) {
    print('${event.state}: ${event.progress}%');
  });

  // Play audio
  await BackgroundRuntime.play(
    AudioTrack(
      id: 'track-1',
      title: 'My Song',
      url: 'https://example.com/song.mp3',
    ),
  );

  await BackgroundRuntime.shutdown();
}

Repository Structure

Package Description
background_runtime App-facing Dart API
background_runtime_platform_interface Platform interface with models and method channel
background_runtime_android Android implementation (Kotlin)
background_runtime_ios iOS implementation (Swift)
background_runtime_macos macOS implementation (Swift)
background_runtime_windows Windows implementation stub (C++)
background_runtime_linux Linux implementation stub (C++)
background_runtime_web Web implementation stub (Dart)
example Example Flutter app

Documentation


Contributing

See CONTRIBUTING.md.

License

MIT — Copyright (c) 2026 Kyaw Zayar Tun

About

A federated Flutter plugin for long-running background execution.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors