Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
dc7451d6
Commit
dc7451d6
authored
Jan 26, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1380 from abarth/raw_keyboard_listener
Add RawKeyboardListener
parents
19ae1e78
58c7fdef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
55 deletions
+130
-55
raw_keyboard.dart
examples/widgets/raw_keyboard.dart
+53
-55
raw_keyboard_listener.dart
packages/flutter/lib/src/widgets/raw_keyboard_listener.dart
+76
-0
widgets.dart
packages/flutter/lib/widgets.dart
+1
-0
No files found.
examples/widgets/raw_keyboard.dart
View file @
dc7451d6
// Copyright
(c) 2015, the Flutter project authors. Please see the AUTHORS file
//
for details. All rights reserved. Use of this source code is governed by a
//
BSD-style license that can be
found in the LICENSE file.
// Copyright
2016 The Chromium Authors. All rights reserved.
//
Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:sky_services/raw_keyboard/raw_keyboard.mojom.dart'
as
mojo
;
import
'package:sky_services/sky/input_event.mojom.dart'
as
mojo
;
import
'package:sky_services/sky/input_event.mojom.dart'
as
mojom
;
GlobalKey
_key
=
new
GlobalKey
();
void
main
(
)
{
runApp
(
new
MaterialApp
(
title:
"Hardware Key Demo"
,
routes:
{
'/'
:
(
RouteArguments
args
)
=>
const
HardwareKeyDemo
()
routes:
<
String
,
RouteBuilder
>{
'/'
:
(
RouteArguments
args
)
{
return
new
Scaffold
(
toolBar:
new
ToolBar
(
center:
new
Text
(
"Hardware Key Demo"
)
),
body:
new
Material
(
child:
new
RawKeyboardDemo
(
key:
_key
)
)
);
}
}
)
);
}
class
HardwareKeyDemo
extends
StatefulComponent
{
const
HardwareKeyDemo
();
HardwareKeyDemoState
createState
()
=>
new
HardwareKeyDemoState
();
}
class
HardwareKeyDemoState
extends
State
<
HardwareKeyDemo
>
implements
mojo
.
RawKeyboardListener
{
class
RawKeyboardDemo
extends
StatefulComponent
{
RawKeyboardDemo
({
GlobalKey
key
})
:
super
(
key:
key
);
mojo
.
InputEvent
_event
=
null
;
_HardwareKeyDemoState
createState
()
=>
new
_HardwareKeyDemoState
();
}
void
initState
()
{
mojo
.
RawKeyboardServiceProxy
rawKeyboardService
=
new
mojo
.
RawKeyboardServiceProxy
.
unbound
();
try
{
shell
.
connectToService
(
null
,
rawKeyboardService
);
mojo
.
RawKeyboardListenerStub
listener
=
new
mojo
.
RawKeyboardListenerStub
.
unbound
()
..
impl
=
this
;
rawKeyboardService
.
ptr
.
addListener
(
listener
);
}
finally
{
rawKeyboardService
.
close
();
}
super
.
initState
();
}
class
_HardwareKeyDemoState
extends
State
<
RawKeyboardDemo
>
{
mojom
.
InputEvent
_event
=
null
;
void
onKey
(
mojo
.
InputEvent
event
)
{
void
_handleKey
(
mojom
.
InputEvent
event
)
{
setState
(()
{
_event
=
event
;
});
}
Widget
_buildBody
()
{
if
(
_event
==
null
)
{
return
new
Center
(
child:
new
Text
(
"Press a key"
,
style:
Typography
.
black
.
display1
)
Widget
build
(
BuildContext
context
)
{
bool
focused
=
Focus
.
at
(
context
);
Widget
child
;
if
(!
focused
)
{
child
=
new
GestureDetector
(
onTap:
()
{
Focus
.
moveTo
(
config
.
key
);
},
child:
new
Center
(
child:
new
Text
(
'Tap to focus'
,
style:
Typography
.
black
.
display1
)
)
);
}
else
if
(
_event
==
null
)
{
child
=
new
Center
(
child:
new
Text
(
'Press a key'
,
style:
Typography
.
black
.
display1
)
);
}
else
{
child
=
new
Column
(
children:
<
Widget
>[
new
Text
(
'
${_event.type}
'
,
style:
Typography
.
black
.
body2
),
new
Text
(
'
${_event.keyData.keyCode}
'
,
style:
Typography
.
black
.
display4
)
],
justifyContent:
FlexJustifyContent
.
center
);
}
return
new
Column
(
children:
<
Widget
>[
new
Text
(
'
${_event.type}
'
,
style:
Typography
.
black
.
body2
),
new
Text
(
'
${_event.keyData.keyCode}
'
,
style:
Typography
.
black
.
display4
)
],
justifyContent:
FlexJustifyContent
.
center
);
}
Widget
build
(
BuildContext
context
)
{
return
new
Scaffold
(
toolBar:
new
ToolBar
(
center:
new
Text
(
"Hardware Key Demo"
)
),
body:
new
Material
(
child:
_buildBody
()
)
return
new
RawKeyboardListener
(
focused:
focused
,
onKey:
_handleKey
,
child:
child
);
}
}
packages/flutter/lib/src/widgets/raw_keyboard_listener.dart
0 → 100644
View file @
dc7451d6
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/services.dart'
;
import
'package:sky_services/raw_keyboard/raw_keyboard.mojom.dart'
as
mojom
;
import
'package:sky_services/sky/input_event.mojom.dart'
as
mojom
;
import
'basic.dart'
;
import
'framework.dart'
;
class
RawKeyboardListener
extends
StatefulComponent
{
RawKeyboardListener
({
Key
key
,
this
.
focused
:
false
,
this
.
onKey
,
this
.
child
})
:
super
(
key:
key
)
{
assert
(
child
!=
null
);
}
final
bool
focused
;
final
ValueChanged
<
mojom
.
InputEvent
>
onKey
;
final
Widget
child
;
_RawKeyboardListenerState
createState
()
=>
new
_RawKeyboardListenerState
();
}
class
_RawKeyboardListenerState
extends
State
<
RawKeyboardListener
>
implements
mojom
.
RawKeyboardListener
{
void
initState
()
{
super
.
initState
();
_attachOrDetachKeyboard
();
}
mojom
.
RawKeyboardListenerStub
_stub
;
void
didUpdateConfig
(
RawKeyboardListener
oldConfig
)
{
_attachOrDetachKeyboard
();
}
void
dispose
()
{
_detachKeyboard
();
super
.
dispose
();
}
void
_attachOrDetachKeyboard
()
{
if
(
config
.
focused
&&
_stub
==
null
)
_attachKeyboard
();
else
if
(!
config
.
focused
&&
_stub
!=
null
)
_detachKeyboard
();
}
void
_attachKeyboard
()
{
assert
(
_stub
==
null
);
_stub
=
new
mojom
.
RawKeyboardListenerStub
.
unbound
()..
impl
=
this
;
mojom
.
RawKeyboardServiceProxy
keyboard
=
new
mojom
.
RawKeyboardServiceProxy
.
unbound
();
shell
.
connectToService
(
null
,
keyboard
);
keyboard
.
ptr
.
addListener
(
_stub
);
keyboard
.
close
();
}
void
_detachKeyboard
()
{
assert
(
_stub
!=
null
);
_stub
.
close
();
_stub
=
null
;
}
void
onKey
(
mojom
.
InputEvent
event
)
{
if
(
config
.
onKey
!=
null
)
config
.
onKey
(
event
);
}
Widget
build
(
BuildContext
context
)
{
return
config
.
child
;
}
}
packages/flutter/lib/widgets.dart
View file @
dc7451d6
...
...
@@ -31,6 +31,7 @@ export 'src/widgets/pageable_list.dart';
export
'src/widgets/pages.dart'
;
export
'src/widgets/performance_overlay.dart'
;
export
'src/widgets/placeholder.dart'
;
export
'src/widgets/raw_keyboard_listener.dart'
;
export
'src/widgets/routes.dart'
;
export
'src/widgets/scrollable.dart'
;
export
'src/widgets/scrollable_grid.dart'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment