Flutter can't read from Clipboard

前端 未结 4 1323
耶瑟儿~
耶瑟儿~ 2021-01-07 07:52

I come asking for quite a specific question regarding Flutter and the Future and await mechanism, which seems to be working, but my Clipboard does not really function while

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 08:36

    First create a method

    Future getClipBoardData() async {
            ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
            return data.text;
          }
    

    Then in build method

    FutureBuilder(
                    future: getClipBoardData(),
                    initialData: 'nothing',
                    builder: (context, snapShot){
                      return Text(snapShot.data.toString());
                    },
                  ),
    

提交回复
热议问题