app_to_foreground 0.0.3
app_to_foreground: ^0.0.3 copied to clipboard
A plugin to bring the app to the foreground when it is in the background.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:app_to_foreground/app_to_foreground.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> {
int _counter = 0;
@override
void initState() {
super.initState();
toForegroundEvery10Secs();
}
/// Bring app to foreground every 10 seconds
Future<void> toForegroundEvery10Secs() async {
Timer.periodic(const Duration(seconds: 10), (t) async {
AppToForeground.appToForeground();
setState(() {
_counter = _counter+=1;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Forgrounded $_counter times'),
),
),
);
}
}