import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import '../core/keyboard/key_modifier_sync.dart'; import 'clipboard_failures.dart'; /// The app's binding: Flutter's, with clipboard failures reported /// ([ClipboardReportingMessenger]) and, on the web, key events carrying the /// modifiers their browser events hold ([KeyModifierSync]). /// /// An entry point calls [ensureInitialized] before anything else creates a /// binding. class PipelinesBinding extends WidgetsFlutterBinding { PipelinesBinding._(); static bool _created = false; /// The binding, created on the first call. static WidgetsBinding ensureInitialized() { if (!_created) { _created = true; PipelinesBinding._(); } return WidgetsBinding.instance; } @override void initInstances() { super.initInstances(); // The services binding hands key data to the framework only once the // keyboard state is synced; the modifier sync goes in front of it then. keyboard.syncKeyboardState().then((_) => installKeyModifierSync()); } @override BinaryMessenger createBinaryMessenger() => ClipboardReportingMessenger(super.createBinaryMessenger()); }