DialogBox in GetX
import "package:flutter/material.dart";
import "package:get/get.dart";
void main()
{
runApp(MyApp());
}
class MyApp extends StatelessWidget
{
MyApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "Dialog Box",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: PracticeDialog(),
);
}
}
class PracticeDialog extends StatelessWidget
{
PracticeDialog({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("DialogBox in GetX"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
Get.defaultDialog(
title: "Dialog Title",
titleStyle: const TextStyle(fontSize: 25.0, fontWeight: FontWeight.bold),
middleText: "This is middle Text",
middleTextStyle: const TextStyle(fontSize: 20.0),
backgroundColor: Colors.cyan,
radius: 50.0,
/// To customize the middle Text
/// Whenever use the "content" it will override the middleText value
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(width: 30.0),
Text("Data Loading..."),
],
),
/// Default cancel and confirm action
textCancel: "Cancel",
cancelTextColor: Colors.white,
textConfirm: "Confirm",
confirmTextColor: Colors.white,
onCancel: () {},
onConfirm: () {},
/// color for default cancel and confirm button
buttonColor: Colors.indigo,
/// Customize the default cancel and confirm
/// Override the default cancel and confirm
/// Below "cancel" and "confirm" overrides the default cancel and confirm
/// as shown below
cancel: const Text("Cancels", style: TextStyle(color: Colors.white,),),
confirm: const Text("Confirms", style: TextStyle(color: Colors.white,),),
actions: <Widget>[
ElevatedButton(
onPressed: () { Get.back(); },
child: const Text("Action-1"),
),
ElevatedButton(
onPressed: () { Get.back(); },
child: const Text("Action-2"),
),
],
barrierDismissible: false,
);
},
child: const Text("Show DialogBox"),
),
],
),
),
);
}
}
Comments
Post a Comment