bubble_head 0.0.4
bubble_head: ^0.0.4 copied to clipboard
A flutter plugin to enable you launch a bubble while putting your application to background and upon clicking the bubble brings your application back to foreground
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:bubble_head/bubble.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Bubble _bubble = new Bubble(showCloseButton: true);
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> startBubbleHead() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
await _bubble.startBubbleHead(sendAppToBackground: false);
} on PlatformException {
print('Failed to call startBubbleHead');
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> stopBubbleHead() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
await _bubble.stopBubbleHead();
} on PlatformException {
print('Failed to call stopBubbleHead');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Bubble Head App'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 50,
width: double.infinity,
margin: EdgeInsets.all(8),
child: TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.teal),
),
onPressed: () async {
await startBubbleHead();
},
child: Text(
"Start Bubble",
style: TextStyle(color: Colors.white),
),
),
),
Container(
height: 50,
width: double.infinity,
margin: EdgeInsets.all(8),
child: TextButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.redAccent),
),
onPressed: () async {
await stopBubbleHead();
},
child: Text(
"Stop Bubble",
style: TextStyle(color: Colors.white),
),
),
),
],
),
),
),
);
}
}