60 lines
1.8 KiB
Dart
60 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:enough_mail/enough_mail.dart';
|
|
|
|
class MailBoxSelect extends StatefulWidget {
|
|
static Future<Mailbox?> show(BuildContext context,
|
|
{required List<Mailbox> mailboxes}) async {
|
|
return await showDialog<Mailbox>(
|
|
context: context,
|
|
builder: (context) => MailBoxSelect(mailBoxes: mailboxes),
|
|
);
|
|
}
|
|
|
|
const MailBoxSelect({Key? key, required this.mailBoxes}) : super(key: key);
|
|
|
|
final List<Mailbox> mailBoxes;
|
|
|
|
@override
|
|
_MailBoxSelectState createState() => _MailBoxSelectState();
|
|
}
|
|
|
|
class _MailBoxSelectState extends State<MailBoxSelect> {
|
|
Mailbox? _selectedMailbox;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Boîte de réception'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
const Text('Choisissez une boîte de réception'),
|
|
DropdownButton<Mailbox>(
|
|
value: _selectedMailbox,
|
|
items: widget.mailBoxes.map((Mailbox mailBox) {
|
|
return DropdownMenuItem<Mailbox>(
|
|
value: mailBox,
|
|
child: Text(mailBox.name),
|
|
);
|
|
}).toList(),
|
|
onChanged: (Mailbox? value) {
|
|
if (value != null) {
|
|
setState(() => _selectedMailbox = value);
|
|
}
|
|
}),
|
|
TextButton(
|
|
onPressed: _selectedMailbox == null
|
|
? null
|
|
: () {
|
|
Navigator.pop(context, _selectedMailbox!);
|
|
},
|
|
child: const Text('Valider'))
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|