flutter Undefined class 'Undefined class'

kzmpq1sx  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(188)

从flutter版本3.10.0中'DragSelectionUpdateCallback'已从text_selection.dart中删除此函数的替代方案是什么?

wooyq4lh

wooyq4lh1#

您可以使用新的TextSelectionGestureDetector类来处理文本选择手势,而不是DragSelectionUpdateCallback。

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

相关问题