background_mode_new 1.0.3 background_mode_new: ^1.0.3 copied to clipboard
Package to perform infinite background execution (Android only).
import 'dart:async';
import 'package:background_mode/background_mode_new.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
void initPlatformState() async {
BackgroundMode.start();
Timer.periodic(Duration(seconds: 10), (timer) {
BackgroundMode.disable();
BackgroundMode.bringToForeground();
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Example'),
),
),
);
}
}