refactored HTTP error handling and streamlined UI components by centralizing shared logic and removing redundant parameters
This commit is contained in:
@@ -86,20 +86,11 @@ class ChatBackgroundSettingsPage extends StatelessWidget {
|
||||
trailing: DropdownButton<ChatBackgroundType>(
|
||||
value: s.type,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: ChatBackgroundType.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<ChatBackgroundType>(
|
||||
value: e,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(_typeIcon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(_typeLabel(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
items: _iconDropdownItems(
|
||||
ChatBackgroundType.values,
|
||||
_typeIcon,
|
||||
_typeLabel,
|
||||
),
|
||||
onChanged: (e) => _onTypeChanged(context, settings, e!),
|
||||
),
|
||||
),
|
||||
@@ -142,20 +133,11 @@ class ChatBackgroundSettingsPage extends StatelessWidget {
|
||||
trailing: DropdownButton<ChatBackgroundFit>(
|
||||
value: s.fit,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: ChatBackgroundFit.values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<ChatBackgroundFit>(
|
||||
value: e,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(_fitIcon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(_fitLabel(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
items: _iconDropdownItems(
|
||||
ChatBackgroundFit.values,
|
||||
_fitIcon,
|
||||
_fitLabel,
|
||||
),
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
settings.val(write: true).chatBackgroundSettings.fit =
|
||||
@@ -280,6 +262,27 @@ class ChatBackgroundSettingsPage extends StatelessWidget {
|
||||
cs.type = ChatBackgroundType.color;
|
||||
}
|
||||
|
||||
/// Dropdown menu items rendered as an icon + label row, shared by the source
|
||||
/// and fill-mode pickers.
|
||||
static List<DropdownMenuItem<T>> _iconDropdownItems<T>(
|
||||
List<T> values,
|
||||
IconData Function(T) icon,
|
||||
String Function(T) label,
|
||||
) => values
|
||||
.map(
|
||||
(e) => DropdownMenuItem<T>(
|
||||
value: e,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(label(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
IconData _typeIcon(ChatBackgroundType type) => switch (type) {
|
||||
ChatBackgroundType.pattern => Icons.texture_outlined,
|
||||
ChatBackgroundType.image => Icons.image_outlined,
|
||||
@@ -330,7 +333,6 @@ class _Preview extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_bubble(
|
||||
context,
|
||||
alignment: Alignment.centerLeft,
|
||||
color: remoteColor,
|
||||
text: 'Wie gefällt dir der neue Hintergrund?',
|
||||
@@ -338,7 +340,6 @@ class _Preview extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_bubble(
|
||||
context,
|
||||
alignment: Alignment.centerRight,
|
||||
color: selfColor,
|
||||
text: 'Sieht richtig gut aus! 🎉',
|
||||
@@ -352,8 +353,7 @@ class _Preview extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bubble(
|
||||
BuildContext context, {
|
||||
Widget _bubble({
|
||||
required Alignment alignment,
|
||||
required Color color,
|
||||
required String text,
|
||||
|
||||
Reference in New Issue
Block a user