app_killer_manager_android 0.0.1
app_killer_manager_android: ^0.0.1

Flutter Android iOS

A new Flutter project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:app_killer_manager_android/app_killer_manager_android.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<AppKillerAction> _actions;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    _actions = await AppKillerManagerAndroid.availableActions;
    print('availableActions $_actions');

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (_actions?.isEmpty == true)
              Text(
                'Don\'t have available actions',
                style: Theme.of(context).textTheme.headline4,
              ),
            if (_actions?.isNotEmpty != false)
              Text(
                'Available actions:',
                style: Theme.of(context).textTheme.headline4,
              ),
            if (_actions == null)
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: CircularProgressIndicator(),
              ),
            for (final action in _actions)
              ListTile(
                title: Text(action.toString().split('.').last),
                trailing: IconButton(
                  icon: Icon(Icons.launch),
                  onPressed: () => AppKillerManagerAndroid.startIntent(action),
                ),
              )
          ],
        ),
      ),
    );
  }
}