Undefined class 'DragSelectionUpdateCallback' in flutter

huangapple go评论54阅读模式
英文:

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,
      ),
    );
  }
}

huangapple
  • 本文由 发表于 2023年5月13日 23:05:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定