flutter util---->常用的一些工具方法

copy text to clipboard

Clipboard.setData(ClipboardData(text: string));

since Flutter1.9, you can use SelectableText, it enable the copy feature.

get text from clipboard

final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
String content = clipboardData.text;

close the keyboard

// Flutter v1.7.8+hotfix.2
FocusScope.of(context).unfocus();

// Before
FocusScope.of(context).requestFocus(FocusNode());

fix issue ListView inside ListView

add code as follow in the nested ListView

shrinkWrap: true,
physics: ClampingScrollPhysics(),

transparent appbar

Scaffold(
  extendBodyBehindAppBar: true,
  appBar: AppBar(
    backgroundColor: Colors.transparent,
    elevation: 0,
    ....
  )
)

hide the back button in the appbar

AppBar(
  automaticallyImplyLeading: false,
)

To be continue

Everything will be alright because of you.

原文地址:https://www.cnblogs.com/huhx/p/13228565.html