Skip to content

Instantly share code, notes, and snippets.

@rizumita
Last active May 5, 2022 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizumita/93e7914e28a2c1d2d9025b9354a807c8 to your computer and use it in GitHub Desktop.
Save rizumita/93e7914e28a2c1d2d9025b9354a807c8 to your computer and use it in GitHub Desktop.
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