英文:
Undefined class 'DragSelectionUpdateCallback' in flutter
问题
'DragSelectionUpdateCallback' 在 Flutter 版本 3.10.0 中已从 text_selection.dart 中移除。有什么替代方法?
英文:
From flutter version 3.10.0 'DragSelectionUpdateCallback' has been removed from text_selection.dart
What is the alternative to this function?
答案1
得分: 0
Instead of DragSelectionUpdateCallback, you can use the new TextSelectionGestureDetector class to handle text selection gestures.
import 'package:flutter/material.dart';
class MyTextSelectionGestureDetector extends StatelessWidget {
final TextEditingController controller;
final Function(TextSelection) onSelectionChanged;
MyTextSelectionGestureDetector({required this.controller, required this.onSelectionChanged});
@override
Widget build(BuildContext context) {
return TextSelectionGestureDetector(
behavior: HitTestBehavior.translucent,
onTapDown: (_) => controller.selection = TextSelection.collapsed(offset: controller.text.length),
onSelectionChanged: onSelectionChanged,
child: TextField(
controller: controller,
),
);
}
}
英文:
Instead of DragSelectionUpdateCallback, you can use the new TextSelectionGestureDetector class to handle text selection gestures.
import 'package:flutter/material.dart';
class MyTextSelectionGestureDetector extends StatelessWidget {
final TextEditingController controller;
final Function(TextSelection) onSelectionChanged;
MyTextSelectionGestureDetector({required this.controller, required this.onSelectionChanged});
@override
Widget build(BuildContext context) {
return TextSelectionGestureDetector(
behavior: HitTestBehavior.translucent,
onTapDown: (_) => controller.selection = TextSelection.collapsed(offset: controller.text.length),
onSelectionChanged: onSelectionChanged,
child: TextField(
controller: controller,
),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论