feat: use data from provider to render table and make it clickable.

pull/2/head
DebuggerX 4 years ago
parent fbc1a4ba72
commit e819ba46e0

@ -77,6 +77,8 @@ class GestureProp {
return 'GestureProp{gesture: $gesture, direction: $direction, fingers: $fingers, type: $type, command: $command, remark: $remark}'; return 'GestureProp{gesture: $gesture, direction: $direction, fingers: $fingers, type: $type, command: $command, remark: $remark}';
} }
GestureProp.empty();
GestureProp.parse(props) { GestureProp.parse(props) {
if (props is String) props = json.decode(props); if (props is String) props = json.decode(props);
assert(props is Map); assert(props is Map);

@ -1,6 +1,7 @@
import 'package:dde_gesture_manager/constants/constants.dart'; import 'package:dde_gesture_manager/constants/constants.dart';
import 'package:dde_gesture_manager/extensions.dart'; import 'package:dde_gesture_manager/extensions.dart';
import 'package:dde_gesture_manager/models/content_layout.provider.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/models/solution.provider.dart';
import 'package:dde_gesture_manager/utils/helper.dart'; import 'package:dde_gesture_manager/utils/helper.dart';
import 'package:dde_gesture_manager/widgets/dde_button.dart'; import 'package:dde_gesture_manager/widgets/dde_button.dart';
@ -11,13 +12,43 @@ import 'package:flutter/material.dart';
class GestureEditor extends StatelessWidget { class GestureEditor extends StatelessWidget {
const GestureEditor({Key? key}) : super(key: key); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var layoutProvider = context.watch<ContentLayoutProvider>(); var layoutProvider = context.watch<ContentLayoutProvider>();
var solutionProvider = context.watch<SolutionProvider>(); var solutionProvider = context.watch<SolutionProvider>();
solutionProvider.name.sout();
solutionProvider.gestures.sout();
return Flexible( return Flexible(
child: Padding( child: Padding(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
@ -85,6 +116,7 @@ class GestureEditor extends StatelessWidget {
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth), constraints: BoxConstraints(minWidth: constraints.maxWidth),
child: DDataTable( child: DDataTable(
showCheckboxColumn: true,
headerBackgroundColor: context.t.dialogBackgroundColor, headerBackgroundColor: context.t.dialogBackgroundColor,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(defaultBorderRadius), borderRadius: BorderRadius.circular(defaultBorderRadius),
@ -94,8 +126,8 @@ class GestureEditor extends StatelessWidget {
), ),
), ),
dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) { dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) if (states.contains(MaterialState.hovered)) return Colors.grey;
return Colors.blue; if (states.contains(MaterialState.selected)) return Colors.green;
return null; return null;
}), }),
columns: [ columns: [
@ -106,72 +138,7 @@ class GestureEditor extends StatelessWidget {
DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())), DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())),
DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())), DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())),
], ],
rows: [ rows: _buildDataRow(solutionProvider.gestures, context),
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.'),
)),
],
),
],
), ),
), ),
), ),

@ -24,15 +24,47 @@ class _HomePageState extends State<HomePage> {
"gestures": [ "gestures": [
{ {
"gesture": "swipe", "gesture": "swipe",
"direction": "down",
"fingers": 3,
"type": "shortcut",
"command": "ctrl+w",
"remark": "close current page."
},
{
"gesture": "swipe",
"direction": "up", "direction": "up",
"fingers": 3, "fingers": 3,
"type": "shortcut", "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( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,

@ -49,11 +49,11 @@ class H {
return preferredPanelsStatus..marketPanelOpened = false; return preferredPanelsStatus..marketPanelOpened = false;
} }
static String getGestureName(Gesture gesture) => const { static String? getGestureName(Gesture? gesture) => const {
Gesture.swipe: 'swipe', Gesture.swipe: 'swipe',
Gesture.tap: 'tap', Gesture.tap: 'tap',
Gesture.pinch: 'pinch', Gesture.pinch: 'pinch',
}[gesture]!; }[gesture];
static Gesture getGestureByName(String gestureName) => static Gesture getGestureByName(String gestureName) =>
const { const {
@ -63,13 +63,14 @@ class H {
}[gestureName] ?? }[gestureName] ??
Gesture.swipe; Gesture.swipe;
static String? getGestureDirectionName(GestureDirection direction) => const { static String? getGestureDirectionName(GestureDirection? direction) => const {
GestureDirection.up: 'up', GestureDirection.up: 'up',
GestureDirection.down: 'down', GestureDirection.down: 'down',
GestureDirection.left: 'left', GestureDirection.left: 'left',
GestureDirection.right: 'right', GestureDirection.right: 'right',
GestureDirection.pinch_in: 'in', GestureDirection.pinch_in: 'in',
GestureDirection.pinch_out: 'out', GestureDirection.pinch_out: 'out',
GestureDirection.none: 'none',
}[direction]; }[direction];
static GestureDirection getGestureDirectionByName(String? directionName) => static GestureDirection getGestureDirectionByName(String? directionName) =>
@ -83,11 +84,11 @@ class H {
}[directionName] ?? }[directionName] ??
GestureDirection.none; GestureDirection.none;
static String getGestureTypeName(GestureType type) => const { static String? getGestureTypeName(GestureType? type) => const {
GestureType.built_in: 'built_in', GestureType.built_in: 'built_in',
GestureType.shortcut: 'shortcut', GestureType.shortcut: 'shortcut',
GestureType.commandline: 'commandline', GestureType.commandline: 'commandline',
}[type]!; }[type];
static GestureType getGestureTypeByName(String typeName) => static GestureType getGestureTypeByName(String typeName) =>
const { const {

@ -990,26 +990,29 @@ class _DDataTableState extends State<DDataTable> {
int displayColumnIndex = 0; int displayColumnIndex = 0;
if (displayCheckboxColumn) { if (displayCheckboxColumn) {
tableColumns[0] = FixedColumnWidth( tableColumns[0] = FixedColumnWidth(0);
effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd); tableRows[0].children![0] = RectGetter.defaultKey(child: Container());
tableRows[0].children![0] = _buildCheckbox( // tableColumns[0] = FixedColumnWidth(
context: context, // effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd);
checked: someChecked ? null : allChecked, // tableRows[0].children![0] = _buildCheckbox(
onRowTap: null, // context: context,
onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked), // checked: someChecked ? null : allChecked,
overlayColor: null, // onRowTap: null,
tristate: true, // onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked),
); // overlayColor: null,
// tristate: true,
// );
rowIndex = 1; rowIndex = 1;
for (final DDataRow row in widget.rows) { for (final DDataRow row in widget.rows) {
tableRows[rowIndex].children![0] = _buildCheckbox( // tableRows[rowIndex].children![0] = _buildCheckbox(
context: context, // context: context,
checked: row.selected, // checked: row.selected,
onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected), // onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
onCheckboxChanged: row.onSelectChanged, // onCheckboxChanged: row.onSelectChanged,
overlayColor: row.color ?? effectiveDataRowColor, // overlayColor: row.color ?? effectiveDataRowColor,
tristate: false, // tristate: false,
); // );
tableRows[rowIndex].children![0] = Container();
rowIndex += 1; rowIndex += 1;
} }
displayColumnIndex += 1; displayColumnIndex += 1;

@ -39,7 +39,8 @@
"left": "left", "left": "left",
"right": "right", "right": "right",
"in": "pinch-in", "in": "pinch-in",
"out": "pinch-out" "out": "pinch-out",
"none": "/"
}, },
"gestures": { "gestures": {
"swipe": "swipe", "swipe": "swipe",

@ -39,12 +39,13 @@
"left": "向左", "left": "向左",
"right": "向右", "right": "向右",
"in": "向内捏合", "in": "向内捏合",
"out": "向外展开" "out": "向外展开",
"none": "/"
}, },
"gestures": { "gestures": {
"swipe": "滑动", "swipe": "",
"pinch": "捏", "pinch": "捏",
"tap": "点" "tap": "点"
}, },
"types": { "types": {
"built_in": "内置操作", "built_in": "内置操作",

Loading…
Cancel
Save