use_of_void_result
このようなエラーメッセージが出ます。
This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
詳細は下記に書いてはありますが、わかりづらいです。
https://dart.dev/tools/diagnostic-messages#use_of_void_result
具体的にはこんなソースコードで発生します。
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: Home(), )); } class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( floatingActionButton: FloatingActionButton( onPressed: () async { await _onPressed(context); }, ), ); } void _onPressed(context) async { await Future.delayed(Duration(seconds: 1)); ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text("hello"), )); } }
こんな感じに修正すればOKです。
FloatingActionButton(onPressed: () => _onPressed(context)),