ui_background_task 0.1.3 copy "ui_background_task: ^0.1.3" to clipboard
ui_background_task: ^0.1.3 copied to clipboard

PlatformiOS

A Flutter iOS plugin to begin and end a UI Background task. It helps finishing long tasks up to 30s after the app is pushed to background.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ui_background_task/ui_background_task.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  int? _taskId;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Background Task Example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ElevatedButton(
                  onPressed: () async {
                    _taskId =
                        await UiBackgroundTask.instance.beginBackgroundTask();
                    setState(() {});
                  },
                  child: const Text('Begin background task')),
              const SizedBox(
                width: 24,
              ),
              if (_taskId != null)
                ElevatedButton(
                  onPressed: () {
                    UiBackgroundTask.instance.endBackgroundTask(_taskId!);
                    setState(() {
                      _taskId = null;
                    });
                  },
                  child: Text(
                    'End background task: $_taskId',
                  ),
                )
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    UiBackgroundTask.instance.appLifeCycleUpdate(state);
  }
}
1
likes
130
pub points
74%
popularity

Publisher

unverified uploader

A Flutter iOS plugin to begin and end a UI Background task. It helps finishing long tasks up to 30s after the app is pushed to background.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface, stop_watch_timer

More

Packages that depend on ui_background_task