1
0
Fork 0
mrtiboute/lib/widgets/pages/settings/messages_settings.dart

66 lines
2.1 KiB
Dart

import 'package:desktopapp/utils/mailer.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class MessagesSettings extends StatefulWidget {
const MessagesSettings(
{Key? key, required this.settings, required this.prefs})
: super(key: key);
final MailerSettings settings;
final SharedPreferences prefs;
@override
_MessagesSettingsState createState() => _MessagesSettingsState();
}
class _MessagesSettingsState extends State<MessagesSettings> {
final TextEditingController controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: [
const Text('Messages :', style: TextStyle(fontSize: 24)),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(child: TextField(controller: controller)),
TextButton(
child: const Text('Ajouter'),
onPressed: () {
setState(() {
widget.settings.messages.add(controller.text);
controller.clear();
widget.settings.saveSettings(widget.prefs);
});
},
)
],
),
),
Expanded(
child: ListView.builder(
itemCount: widget.settings.messages.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(widget.settings.messages[index]),
leading: IconButton(
icon: const Icon(Icons.delete_rounded),
onPressed: () {
setState(() {
widget.settings.messages.removeAt(index);
widget.settings.saveSettings(widget.prefs);
});
},
),
);
}),
)
],
),
);
}
}