扑中的样式剪贴板 [英] Style clipboard in flutter

查看:115
本文介绍了扑中的样式剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种样式化剪贴板动作的方式,而又无需触摸主样式主题的textTheme/button属性.这有可能吗?

I am looking for a way to style the clipboard actions without touching textTheme/button property of the main style theme. Is this even possible?

推荐答案

样式似乎与主题直接相关.不是最好的主意,但是如果您确实想要,则需要创建一个自定义弹出窗口并自己处理所有操作.

Seems like the style is directly tied to the theme. Not the best idea but if you really wanted to you would need to create a custom popup and handle all the actions yourself.

这应该让您入门...

This should get you started...

输出:

代码:

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<MyHomePage> {
  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: <Widget>[
            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: <Widget>[
                            // 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,
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

这篇关于扑中的样式剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆