-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## [2.0.4] - 20/06/2023 | ||
|
||
- Fix double on click event | ||
|
||
## [2.0.3] - 03/02/2023 | ||
|
||
- Code formatting standard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,57 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
|
||
/// Action constants | ||
const String keyUp = 'Arrow Up'; | ||
const String keyDown = 'Arrow Down'; | ||
const String keyLeft = 'Arrow Left'; | ||
const String keyRight = 'Arrow Right'; | ||
const String keyCenter = 'Select'; | ||
|
||
/// | ||
/// Using Hooks instead of statefull builder | ||
/// Make coding looks nice and compact | ||
class DpadContainer extends HookWidget { | ||
final Function onClick; | ||
final Function(bool isFocused) onFocus; | ||
final Widget child; | ||
|
||
const DpadContainer({ | ||
Key? key, | ||
required this.onClick, | ||
required this.child, | ||
required this.onFocus, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
/// Focus Node | ||
var node = useFocusNode; | ||
|
||
/// On focus state | ||
var isFocused = useState(false); | ||
|
||
return KeyboardListener( | ||
focusNode: node.call(), | ||
onKeyEvent: (KeyEvent event) { | ||
/// Action label | ||
var label = event.logicalKey.keyLabel; | ||
|
||
/// If label equal to Key Event which arrow up, down, right, left or on Enter | ||
if (label == keyCenter) { | ||
onClick(); | ||
} else { | ||
isFocused.value = !(isFocused.value); | ||
onFocus(isFocused.value); | ||
} | ||
}, | ||
child: child, | ||
); | ||
} | ||
} | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
|
||
/// Action constants | ||
const String keyUp = 'Arrow Up'; | ||
const String keyDown = 'Arrow Down'; | ||
const String keyLeft = 'Arrow Left'; | ||
const String keyRight = 'Arrow Right'; | ||
const String keyCenter = 'Select'; | ||
|
||
/// | ||
/// Using Hooks instead of statefull builder | ||
/// Make coding looks nice and compact | ||
class DpadContainer extends HookWidget { | ||
final Function onClick; | ||
final Function(bool isFocused) onFocus; | ||
final Widget child; | ||
|
||
const DpadContainer({ | ||
Key? key, | ||
required this.onClick, | ||
required this.child, | ||
required this.onFocus, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
/// Focus Node | ||
final FocusNode focusNode = useFocusNode(); | ||
useEffect(() { | ||
return focusNode.requestFocus; | ||
}, []); | ||
|
||
/// On focus state | ||
var isFocused = useState(false); | ||
|
||
return RawKeyboardListener( | ||
focusNode: focusNode, | ||
onKey: (RawKeyEvent event) { | ||
if(event is RawKeyDownEvent) { | ||
/// Action label | ||
var label = event.logicalKey.keyLabel; | ||
|
||
/// If label equal to Key Event which arrow up, down, right, left or on Enter | ||
if (label == keyCenter) { | ||
onClick(); | ||
} | ||
} else { | ||
isFocused.value = !isFocused.value; | ||
onFocus(isFocused.value); | ||
} | ||
}, | ||
child: child, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters