dotup_flutter_shortcuts 2.0.2 copy "dotup_flutter_shortcuts: ^2.0.2" to clipboard
dotup_flutter_shortcuts: ^2.0.2 copied to clipboard

Widget to handle shortcuts easy. With actions and intents.

example/example.dart

// ignore_for_file: prefer_const_constructors, avoid_relative_lib_imports

import 'package:dotup_flutter_shortcuts/dotup_flutter_shortcuts.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

// https://flutter.dev/docs/development/ui/advanced/actions_and_shortcuts

// Is called with Ctrl + S
class ScreenshotAction extends Action<SingleKeyPressedIntent> {
  @override
  Object? invoke(covariant SingleKeyPressedIntent intent) {
    print('1-ScreenshotAction ${intent.key}');
  }
}

// Is called with Ctrl + R and Ctrl +A
class SingleKeyPressedAction extends Action<SingleKeyPressedIntent> {
  @override
  Object? invoke(covariant SingleKeyPressedIntent intent) {
    print('2-SingleKeyPressedAction ${intent.key}');
  }
}

void main() => runApp(const MyApp());

/// Shortcuts defined here are in effect for the whole app,
/// although different widgets may fulfill them differently.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String title = 'Shortcuts and Actions Demo';

  @override
  Widget build(BuildContext context) {
    final shortcuts = [
      SingleKeyShortcutDescriptor(
        action: SingleKeyPressedAction(),
        keySet: LogicalKeySet(LogicalKeyboardKey.keyR, LogicalKeyboardKey.keyA),
        control: true,
        // meta: true,
      ),
      SingleKeyShortcutDescriptor(
        action: ScreenshotAction(),
        keySet: LogicalKeySet(LogicalKeyboardKey.keyS),
        control: true,
      ),
    ];

    return SingleKeyShortcut(
      shortcutDescriptors: shortcuts,
      child: MaterialApp(
        title: title,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          body: Column(
            children: [
              Container(width: 50, height: 50, color: Colors.red),
              Container(width: 50, height: 50, color: Colors.blue),
              Container(width: 50, height: 50, color: Colors.yellow),
              Container(width: 50, height: 50, color: Colors.amber),
              Text('www.dotup.de'),
              Text('www.flutter-apps.ml'),
              TextField(),
            ],
          ),
        ),
      ),
    );
  }
}

/// KeyListner

class KeyUpAction extends Action<KeyUpListnerIntent> {
  @override
  Object? invoke(covariant KeyUpListnerIntent intent) {
    print('1-KeyUpAction ${intent.key}');
  }
}

class KeyDownAction extends Action<KeyDownListnerIntent> {
  @override
  Object? invoke(covariant KeyDownListnerIntent intent) {
    print('1-KeyDownAction ${intent.key}');
  }
}

class KeyListnerApp extends StatelessWidget {
  const KeyListnerApp({Key? key}) : super(key: key);

  static const String title = 'Shortcuts and Actions Demo';

  @override
  Widget build(BuildContext context) {
    return KeyListner(
      keyDownAction: KeyListnerAction(
        action: KeyUpAction(),
        intent: KeyUpListnerIntent(context, LogicalKeyboardKey.controlLeft),
      ),
      keyboardKey: LogicalKeyboardKey.controlLeft,
      child: MaterialApp(
        title: title,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          body: Column(
            children: [
              Container(width: 50, height: 50, color: Colors.red),
              Container(width: 50, height: 50, color: Colors.blue),
              Container(width: 50, height: 50, color: Colors.yellow),
              Container(width: 50, height: 50, color: Colors.amber),
              TextField(),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
70
pub points
1%
popularity

Publisher

verified publisherdotup.de

Widget to handle shortcuts easy. With actions and intents.

Homepage

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on dotup_flutter_shortcuts