buttonhandler 0.0.4 copy "buttonhandler: ^0.0.4" to clipboard
buttonhandler: ^0.0.4 copied to clipboard

PlatformAndroid

This package helps handle physical or hardware buttons including and not limited to volume and power buttons

example/lib/main.dart

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


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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  late int sumResult;
  late Future<int> sumAsyncResult;
  bool onLongPress = false;

  @override
  void initState() {
    super.initState();
    PhysicalButtonsHandler.listen(handleKey);
  }

  void handleKey(var key) {
    print(key);
    setState(() {
      switch (key) {
        case "shmaker.android.intent.action.SCANER_KEYEVENT_LONG":
          onLongPress = true;
          showDialog(
              context: context,
              builder: (context) {
                return const AlertDialog(
                  icon: Icon(Icons.ice_skating),
                );
              });

          break;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 25);
    const spacerSmall = SizedBox(height: 10);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Hardware buttons find'),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.all(10),
            child: const Column(
              children: [
                Text(
                  'This calls a native function through FFI that is shipped as source in the package. '
                  'The native code is built as part of the Flutter Runner build.',
                  style: textStyle,
                  textAlign: TextAlign.center,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
150
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

This package helps handle physical or hardware buttons including and not limited to volume and power buttons

Homepage
Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on buttonhandler