RawDialogRoute
is a class in Flutter that represents a raw dialog route, providing a way to display custom dialogs or popups. This class is typically used internally by the framework to create and manage dialog routes.
Here's an example of how you might use RawDialogRoute
to display a custom dialog:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('RawDialogRoute Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return RawDialogRoute(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Custom Dialog'),
content: Text('This is a custom dialog using RawDialogRoute.'),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Close'),
),
],
);
},
);
},
);
},
child: Text('Open Dialog'),
),
),
);
}
}
In this example, when the button is pressed, the showDialog
function is used to display a custom dialog using the RawDialogRoute
as the builder. Inside the builder
, you can provide your custom content for the dialog.
Please note that RawDialogRoute
might be considered a low-level class, and you might find it more convenient to use the built-in AlertDialog
or SimpleDialog
classes for creating dialogs in most cases.