我是靠谱客的博主 高高刺猬,最近开发中收集的这篇文章主要介绍flutter 全选_如何在Flutter中更改文本选择选项?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I tried to add text editing format option like in the gmail app. But when highlight the text there' is not a format option. Is it possible to handle selecting alert? (Copy/cut/paste). Or is there a way to add format bar like gmail?

TextField(

controller: _categoryController,

decoration: InputDecoration(

border: InputBorder.none,

hintText: "Enter Category Name",

),

),

I added screenshot and gif files to better understanding my question.

Selecting option on my Flutter application

Selecting option on Gmail App

解决方案

Output:

You can check the code below:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Flutter Demo',

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: MyHomePage(title: 'Flutter Demo Home Page'),

);

}

}

class MyHomePage extends StatefulWidget {

MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override

_MyHomePageState createState() => _MyHomePageState();

}

class _MyHomePageState extends State {

final _controller = new TextEditingController();

final _textfieldFocusNode = new FocusNode();

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text(widget.title),

),

body: Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,

children: [

Padding(

padding: EdgeInsets.all(20.0),

child: GestureDetector(

// intercept all pointer calls

behavior: HitTestBehavior.opaque,

onTap: () {

FocusScope.of(context).requestFocus(_textfieldFocusNode);

},

onLongPress: () {

showMenu(

context: context,

// TODO: Position dynamically based on cursor or textfield

position: RelativeRect.fromLTRB(0.0, 300.0, 300.0, 0.0),

items: [

PopupMenuItem(

child: Row(

children: [

// TODO: Dynamic items / handle click

PopupMenuItem(

child: Text(

"Paste",

style: Theme.of(context)

.textTheme

.body2

.copyWith(color: Colors.red),

),

),

PopupMenuItem(

child: Text("Select All"),

),

],

),

),

],

);

},

child: IgnorePointer(

// ensures textfield doesn't overrule GestureDetector

child: TextField(

focusNode: _textfieldFocusNode,

controller: _controller,

),

),

),

)

],

),

),

);

}

}

最后

以上就是高高刺猬为你收集整理的flutter 全选_如何在Flutter中更改文本选择选项?的全部内容,希望文章能够帮你解决flutter 全选_如何在Flutter中更改文本选择选项?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部