text stringlengths 1 474 |
|---|
icon: const Icon(Icons.copy), |
onPressed: |
Actions.handler<CopyIntent>(context, const CopyIntent()), |
), |
IconButton( |
icon: const Icon(Icons.select_all), |
onPressed: Actions.handler<SelectAllIntent>( |
context, const SelectAllIntent()), |
), |
const Spacer(), |
], |
), |
), |
); |
}), |
); |
} |
} |
/// A ShortcutManager that logs all keys that it handles. |
class LoggingShortcutManager extends ShortcutManager { |
@override |
KeyEventResult handleKeypress(BuildContext context, KeyEvent event) { |
final KeyEventResult result = super.handleKeypress(context, event); |
if (result == KeyEventResult.handled) { |
print('Handled shortcut $event in $context'); |
} |
return result; |
} |
} |
/// An ActionDispatcher that logs all the actions that it invokes. |
class LoggingActionDispatcher extends ActionDispatcher { |
@override |
Object? invokeAction( |
covariant Action<Intent> action, |
covariant Intent intent, [ |
BuildContext? context, |
]) { |
print('Action invoked: $action($intent) from $context'); |
super.invokeAction(action, intent, context); |
return null; |
} |
} |
/// An intent that is bound to ClearAction in order to clear its |
/// TextEditingController. |
class ClearIntent extends Intent { |
const ClearIntent(); |
} |
/// An action that is bound to ClearIntent that clears its |
/// TextEditingController. |
class ClearAction extends Action<ClearIntent> { |
ClearAction(this.controller); |
final TextEditingController controller; |
@override |
Object? invoke(covariant ClearIntent intent) { |
controller.clear(); |
return null; |
} |
} |
/// An intent that is bound to CopyAction to copy from its |
/// TextEditingController. |
class CopyIntent extends Intent { |
const CopyIntent(); |
} |
/// An action that is bound to CopyIntent that copies the text in its |
/// TextEditingController to the clipboard. |
class CopyAction extends Action<CopyIntent> { |
CopyAction(this.controller); |
final TextEditingController controller; |
@override |
Object? invoke(covariant CopyIntent intent) { |
final String selectedString = controller.text.substring( |
controller.selection.baseOffset, |
controller.selection.extentOffset, |
); |
Clipboard.setData(ClipboardData(text: selectedString)); |
return null; |
} |
} |
/// An intent that is bound to SelectAllAction to select all the text in its |
/// controller. |
class SelectAllIntent extends Intent { |
const SelectAllIntent(); |
} |
/// An action that is bound to SelectAllAction that selects all text in its |
/// TextEditingController. |
class SelectAllAction extends Action<SelectAllIntent> { |
SelectAllAction(this.controller); |
final TextEditingController controller; |
@override |
Object? invoke(covariant SelectAllIntent intent) { |
controller.selection = controller.selection.copyWith( |
baseOffset: 0, |
extentOffset: controller.text.length, |
affinity: controller.selection.affinity, |
); |
return null; |
} |
} |
/// The top level application class. |
/// |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.