feat: use CheckedPopupMenuItem instead of PopupMenuItem; use DefaultTextStyle to reduce duplicate code.

This commit is contained in:
2021-10-13 15:05:57 +08:00
parent 6df7543262
commit bc2b514392
5 changed files with 58 additions and 83 deletions
+7 -21
View File
@@ -167,7 +167,7 @@ List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context)
}
},
selected: selected,
cells: editing ? _buildRowCellsEditing(gesture) : _buildRowCellsNormal(selected, gesture),
cells: editing ? _buildRowCellsEditing(gesture) : _buildRowCellsNormal(context, selected, gesture),
);
}).toList();
@@ -180,51 +180,37 @@ List<DDataCell> _buildRowCellsEditing(GestureProp gesture) => [
TextField(controller: TextEditingController(text: gesture.remark)),
].map((e) => DDataCell(e)).toList();
List<DDataCell> _buildRowCellsNormal(bool selected, GestureProp gesture) => [
List<DDataCell> _buildRowCellsNormal(BuildContext context, bool selected, GestureProp gesture) => [
Center(
child: Text(
'${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}',
style: TextStyle(
color: selected ? Colors.white : null,
),
).tr(),
),
Center(
child: Text(
'${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}',
style: TextStyle(
color: selected ? Colors.white : null,
),
).tr()),
Center(
child: Text(
'${gesture.fingers}',
style: TextStyle(
color: selected ? Colors.white : null,
),
),
),
Center(
child: Text(
'${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}',
style: TextStyle(
color: selected ? Colors.white : null,
),
).tr()),
Text(
gesture.command ?? '',
style: TextStyle(
color: selected ? Colors.white : null,
),
),
Text(
gesture.remark ?? '',
style: TextStyle(
color: selected ? Colors.white : null,
),
),
]
.map(
(ele) => DDataCell(ele),
(ele) => DDataCell(DefaultTextStyle(
style: context.t.textTheme.bodyText2!.copyWith(
color: selected ? Colors.white : null,
),
child: ele)),
)
.toList();
+11 -6
View File
@@ -123,12 +123,17 @@ class _LocalManagerState extends State<LocalManager> {
color: _getItemBackgroundColor(index),
child: Padding(
padding: const EdgeInsets.only(left: 6, right: 12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(localSchemes[index].scheme.name ?? ''),
Text('456'),
],
child: DefaultTextStyle(
style: context.t.textTheme.bodyText2!.copyWith(
color: _selectedIndex == index ? Colors.white : null,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(localSchemes[index].scheme.name ?? ''),
Text('456'),
],
),
),
),
),