должно работать.Смотрите очень простой пример:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@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> {
Login userLogin = Login();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Simple exception test',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
try {
await userLogin.signInWithGoogle();
} on PlatformException catch (e) {
print('Error ...:');
print(e);
}
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
class Login {
Future<void> signInWithGoogle() async {
throw PlatformException(code: 'Test Exception');
}
}