Last active
May 5, 2022 00:15
-
-
Save rizumita/93e7914e28a2c1d2d9025b9354a807c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: const Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
const MyWidget({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return ElevatedButton( | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (context) { | |
bool isChecked = false; | |
return StatefulBuilder(builder: (context, setState) { | |
return AlertDialog( | |
content: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ | |
const Text("Confirm"), | |
Checkbox( | |
value: isChecked, | |
onChanged: (checked) { | |
setState(() => isChecked = checked ?? false); | |
}) | |
]), | |
title: const Text('Stateful Dialog'), | |
actions: <Widget>[ | |
InkWell( | |
child: const Text('Cancel'), | |
onTap: () => Navigator.of(context).pop(), | |
), | |
InkWell( | |
child: const Text('OK'), | |
onTap: isChecked ? () => Navigator.of(context).pop() : null, | |
), | |
], | |
); | |
}); | |
}); | |
}, | |
child: const Text('Show alert')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment