feat: use data from provider to render table and make it clickable.
This commit is contained in:
@@ -77,6 +77,8 @@ class GestureProp {
|
||||
return 'GestureProp{gesture: $gesture, direction: $direction, fingers: $fingers, type: $type, command: $command, remark: $remark}';
|
||||
}
|
||||
|
||||
GestureProp.empty();
|
||||
|
||||
GestureProp.parse(props) {
|
||||
if (props is String) props = json.decode(props);
|
||||
assert(props is Map);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/models/content_layout.provider.dart';
|
||||
import 'package:dde_gesture_manager/models/solution.dart';
|
||||
import 'package:dde_gesture_manager/models/solution.provider.dart';
|
||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||
import 'package:dde_gesture_manager/widgets/dde_button.dart';
|
||||
@@ -11,13 +12,43 @@ import 'package:flutter/material.dart';
|
||||
class GestureEditor extends StatelessWidget {
|
||||
const GestureEditor({Key? key}) : super(key: key);
|
||||
|
||||
List<DDataRow> _buildDataRow(List<GestureProp>? gestures, BuildContext context) => (gestures ?? [])
|
||||
.map((gesture) => DDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
if (selected == true)
|
||||
context.read<GesturePropProvider>().setProps(
|
||||
gesture: gesture.gesture,
|
||||
direction: gesture.direction,
|
||||
fingers: gesture.fingers,
|
||||
type: gesture.type,
|
||||
command: gesture.command,
|
||||
remark: gesture.remark,
|
||||
);
|
||||
},
|
||||
selected: context.watch<GesturePropProvider>() == gesture,
|
||||
cells: [
|
||||
Center(
|
||||
child: Text('${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}').tr(),
|
||||
),
|
||||
Text('${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}').tr(),
|
||||
Center(
|
||||
child: Text('${gesture.fingers}'),
|
||||
),
|
||||
Center(child: Text('${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}').tr()),
|
||||
Text(gesture.command ?? ''),
|
||||
Text(gesture.remark ?? ''),
|
||||
]
|
||||
.map(
|
||||
(ele) => DDataCell(ele),
|
||||
)
|
||||
.toList(),
|
||||
))
|
||||
.toList();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var layoutProvider = context.watch<ContentLayoutProvider>();
|
||||
var solutionProvider = context.watch<SolutionProvider>();
|
||||
solutionProvider.name.sout();
|
||||
solutionProvider.gestures.sout();
|
||||
|
||||
return Flexible(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
@@ -85,6 +116,7 @@ class GestureEditor extends StatelessWidget {
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||
child: DDataTable(
|
||||
showCheckboxColumn: true,
|
||||
headerBackgroundColor: context.t.dialogBackgroundColor,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(defaultBorderRadius),
|
||||
@@ -94,8 +126,8 @@ class GestureEditor extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.hovered))
|
||||
return Colors.blue;
|
||||
if (states.contains(MaterialState.hovered)) return Colors.grey;
|
||||
if (states.contains(MaterialState.selected)) return Colors.green;
|
||||
return null;
|
||||
}),
|
||||
columns: [
|
||||
@@ -106,72 +138,7 @@ class GestureEditor extends StatelessWidget {
|
||||
DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())),
|
||||
DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())),
|
||||
],
|
||||
rows: [
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_right).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()),
|
||||
DDataCell(Text('ctrl+w')),
|
||||
DDataCell(Text('close current page.')),
|
||||
],
|
||||
),
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()),
|
||||
DDataCell(Text('ctrl+alt+t')),
|
||||
DDataCell(Text('reopen last closed page.')),
|
||||
],
|
||||
),
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()),
|
||||
DDataCell(Text('ctrl+alt+t')),
|
||||
DDataCell(Text('reopen last closed page.')),
|
||||
],
|
||||
),
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()),
|
||||
DDataCell(Text('ctrl+alt+t')),
|
||||
DDataCell(Text('reopen last closed page.')),
|
||||
],
|
||||
),
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_left).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_shortcut).tr()),
|
||||
DDataCell(Text('ctrl+alt+t')),
|
||||
DDataCell(Text('reopen last closed page.')),
|
||||
],
|
||||
),
|
||||
DDataRow(
|
||||
cells: [
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_gestures_swipe).tr()),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_directions_down).tr()),
|
||||
DDataCell(Text('3')),
|
||||
DDataCell(Text(LocaleKeys.gesture_editor_types_commandline).tr()),
|
||||
DDataCell(Text(
|
||||
'dbus-send --type=method_call --dest=com.deepin.dde.Launcher /com/deepin/dde/Launcher com.deepin.dde.Launcher.Toggle')),
|
||||
DDataCell(TextButton(
|
||||
onPressed: () => print(123),
|
||||
child: Text('show launcher.'),
|
||||
)),
|
||||
],
|
||||
),
|
||||
],
|
||||
rows: _buildDataRow(solutionProvider.gestures, context),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+34
-2
@@ -22,17 +22,49 @@ class _HomePageState extends State<HomePage> {
|
||||
"name": "test",
|
||||
"desc": "some desc",
|
||||
"gestures": [
|
||||
{
|
||||
"gesture": "swipe",
|
||||
"direction": "down",
|
||||
"fingers": 3,
|
||||
"type": "shortcut",
|
||||
"command": "ctrl+w",
|
||||
"remark": "close current page."
|
||||
},
|
||||
{
|
||||
"gesture": "swipe",
|
||||
"direction": "up",
|
||||
"fingers": 3,
|
||||
"type": "shortcut",
|
||||
"command": "ctrl+w"
|
||||
"command": "ctrl+alt+t",
|
||||
"remark": "reopen last closed page."
|
||||
},
|
||||
{
|
||||
"gesture": "pinch",
|
||||
"direction": "in",
|
||||
"fingers": 4,
|
||||
"type": "shortcut",
|
||||
"command": "ctrl+alt+f",
|
||||
"remark": "search files."
|
||||
},
|
||||
{
|
||||
"gesture": "tap",
|
||||
"fingers": 4,
|
||||
"type": "built_in",
|
||||
"command": "handle4FingersTap",
|
||||
"remark": "handle4FingersTap."
|
||||
},
|
||||
{
|
||||
"gesture": "swipe",
|
||||
"direction": "down",
|
||||
"fingers": 5,
|
||||
"type": "commandline",
|
||||
"command": "dbus-send --type=method_call --dest=com.deepin.dde.Launcher /com/deepin/dde/Launcher com.deepin.dde.Launcher.Toggle",
|
||||
"remark": "toggle launcher."
|
||||
}
|
||||
]
|
||||
}
|
||||
''')),
|
||||
// ChangeNotifierProvider(create: (context) => GesturePropProvider()),
|
||||
ChangeNotifierProvider(create: (context) => GesturePropProvider.empty()),
|
||||
],
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
|
||||
@@ -49,11 +49,11 @@ class H {
|
||||
return preferredPanelsStatus..marketPanelOpened = false;
|
||||
}
|
||||
|
||||
static String getGestureName(Gesture gesture) => const {
|
||||
static String? getGestureName(Gesture? gesture) => const {
|
||||
Gesture.swipe: 'swipe',
|
||||
Gesture.tap: 'tap',
|
||||
Gesture.pinch: 'pinch',
|
||||
}[gesture]!;
|
||||
}[gesture];
|
||||
|
||||
static Gesture getGestureByName(String gestureName) =>
|
||||
const {
|
||||
@@ -63,13 +63,14 @@ class H {
|
||||
}[gestureName] ??
|
||||
Gesture.swipe;
|
||||
|
||||
static String? getGestureDirectionName(GestureDirection direction) => const {
|
||||
static String? getGestureDirectionName(GestureDirection? direction) => const {
|
||||
GestureDirection.up: 'up',
|
||||
GestureDirection.down: 'down',
|
||||
GestureDirection.left: 'left',
|
||||
GestureDirection.right: 'right',
|
||||
GestureDirection.pinch_in: 'in',
|
||||
GestureDirection.pinch_out: 'out',
|
||||
GestureDirection.none: 'none',
|
||||
}[direction];
|
||||
|
||||
static GestureDirection getGestureDirectionByName(String? directionName) =>
|
||||
@@ -83,11 +84,11 @@ class H {
|
||||
}[directionName] ??
|
||||
GestureDirection.none;
|
||||
|
||||
static String getGestureTypeName(GestureType type) => const {
|
||||
static String? getGestureTypeName(GestureType? type) => const {
|
||||
GestureType.built_in: 'built_in',
|
||||
GestureType.shortcut: 'shortcut',
|
||||
GestureType.commandline: 'commandline',
|
||||
}[type]!;
|
||||
}[type];
|
||||
|
||||
static GestureType getGestureTypeByName(String typeName) =>
|
||||
const {
|
||||
|
||||
@@ -990,26 +990,29 @@ class _DDataTableState extends State<DDataTable> {
|
||||
|
||||
int displayColumnIndex = 0;
|
||||
if (displayCheckboxColumn) {
|
||||
tableColumns[0] = FixedColumnWidth(
|
||||
effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd);
|
||||
tableRows[0].children![0] = _buildCheckbox(
|
||||
context: context,
|
||||
checked: someChecked ? null : allChecked,
|
||||
onRowTap: null,
|
||||
onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked),
|
||||
overlayColor: null,
|
||||
tristate: true,
|
||||
);
|
||||
tableColumns[0] = FixedColumnWidth(0);
|
||||
tableRows[0].children![0] = RectGetter.defaultKey(child: Container());
|
||||
// tableColumns[0] = FixedColumnWidth(
|
||||
// effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd);
|
||||
// tableRows[0].children![0] = _buildCheckbox(
|
||||
// context: context,
|
||||
// checked: someChecked ? null : allChecked,
|
||||
// onRowTap: null,
|
||||
// onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked),
|
||||
// overlayColor: null,
|
||||
// tristate: true,
|
||||
// );
|
||||
rowIndex = 1;
|
||||
for (final DDataRow row in widget.rows) {
|
||||
tableRows[rowIndex].children![0] = _buildCheckbox(
|
||||
context: context,
|
||||
checked: row.selected,
|
||||
onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
|
||||
onCheckboxChanged: row.onSelectChanged,
|
||||
overlayColor: row.color ?? effectiveDataRowColor,
|
||||
tristate: false,
|
||||
);
|
||||
// tableRows[rowIndex].children![0] = _buildCheckbox(
|
||||
// context: context,
|
||||
// checked: row.selected,
|
||||
// onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
|
||||
// onCheckboxChanged: row.onSelectChanged,
|
||||
// overlayColor: row.color ?? effectiveDataRowColor,
|
||||
// tristate: false,
|
||||
// );
|
||||
tableRows[rowIndex].children![0] = Container();
|
||||
rowIndex += 1;
|
||||
}
|
||||
displayColumnIndex += 1;
|
||||
|
||||
Reference in New Issue
Block a user