Keyboard shortcuts
This commit is contained in:
parent
5858f5bf79
commit
d539807965
|
|
@ -1,4 +1,18 @@
|
|||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/client_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/expense/expense_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/task/task_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart';
|
||||
|
||||
class AppBuilder extends StatefulWidget {
|
||||
const AppBuilder({Key key, this.builder}) : super(key: key);
|
||||
|
|
@ -14,11 +28,13 @@ class AppBuilder extends StatefulWidget {
|
|||
|
||||
class AppBuilderState extends State<AppBuilder> {
|
||||
FocusNode _focusNode;
|
||||
String _command = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode = new FocusNode();
|
||||
_focusNode.requestFocus(null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -31,14 +47,89 @@ class AppBuilderState extends State<AppBuilder> {
|
|||
setState(() {});
|
||||
}
|
||||
|
||||
void runCommand(BuildContext context) {
|
||||
print('### RUN COMMAND: $_command ###');
|
||||
final store = StoreProvider.of<AppState>(context);
|
||||
final company = store.state.selectedCompany;
|
||||
const force = true;
|
||||
dynamic action;
|
||||
|
||||
switch (_command) {
|
||||
case 'lc':
|
||||
action = ViewClientList(context: context, force: force);
|
||||
break;
|
||||
case 'nc':
|
||||
action =
|
||||
EditClient(context: context, client: ClientEntity(), force: force);
|
||||
break;
|
||||
case 'lr':
|
||||
action = ViewProductList(context: context, force: force);
|
||||
break;
|
||||
case 'nr':
|
||||
action = EditProduct(
|
||||
context: context, product: ProductEntity(), force: force);
|
||||
break;
|
||||
case 'li':
|
||||
action = ViewInvoiceList(context: context, force: force);
|
||||
break;
|
||||
case 'ni':
|
||||
action = EditInvoice(
|
||||
context: context,
|
||||
invoice: InvoiceEntity(company: company),
|
||||
force: force);
|
||||
break;
|
||||
case 'lq':
|
||||
action = ViewQuoteList(context: context, force: force);
|
||||
break;
|
||||
case 'nq':
|
||||
action = EditQuote(
|
||||
context: context,
|
||||
quote: InvoiceEntity(company: company, isQuote: force));
|
||||
break;
|
||||
case 'lt':
|
||||
action = ViewTaskList(context: context);
|
||||
break;
|
||||
case 'nt':
|
||||
action = EditTask(context: context, task: TaskEntity(), force: force);
|
||||
break;
|
||||
case 'lv':
|
||||
action = ViewVendorList(context: context);
|
||||
break;
|
||||
case 'nv':
|
||||
action =
|
||||
EditVendor(context: context, vendor: VendorEntity(), force: force);
|
||||
break;
|
||||
case 'le':
|
||||
action = ViewExpenseList(context: context);
|
||||
break;
|
||||
case 'ne':
|
||||
action = EditExpense(
|
||||
context: context,
|
||||
expense: ExpenseEntity(company: company),
|
||||
force: force);
|
||||
break;
|
||||
}
|
||||
|
||||
if (action != null) {
|
||||
store.dispatch(action);
|
||||
SystemChannels.textInput.invokeMethod<String>('TextInput.hide');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RawKeyboardListener(
|
||||
child: widget.builder(context),
|
||||
focusNode: _focusNode,
|
||||
onKey: (event) {
|
||||
if (kReleaseMode) {
|
||||
return;
|
||||
}
|
||||
print(
|
||||
'onKey: ${event.logicalKey.keyLabel}, focus: ${_focusNode.hasFocus}');
|
||||
'onKey: ${event.logicalKey.keyLabel}, hasFoucs: ${_focusNode.hasFocus}, hasPrimaryFocus: ${_focusNode.hasPrimaryFocus}');
|
||||
_command += event.logicalKey.keyLabel;
|
||||
runCommand(context);
|
||||
Timer(Duration(seconds: 1), () => _command = '');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue