We will work with a new file in our project, called platform_alert.dart. Let's get started:
- Open this new file and create a constructor that will accept a title and message body. This class is just going to be a simple dart object:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class PlatformAlert {
final String title;
final String message;
const PlatformAlert({@required this.title, @required
this.message})
: assert(title != null),
assert(message != null);
}
- PlatformAlert is going to need a show method that will look at the app's context to determine what type of device it's running on and then show the appropriate dialog widget.
- Add this method just after the constructor:
void show(BuildContext context) {
final platform = Theme.of(context).platform;
if (platform == TargetPlatform.iOS) {
_buildCupertinoAlert(context);
} else {
_buildMaterialAlert...