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

This commit is contained in:
2021-10-08 01:44:17 +08:00
parent fbc1a4ba72
commit e819ba46e0
7 changed files with 107 additions and 100 deletions
+38 -71
View File
@@ -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
View File
@@ -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,