InteractiveView buggy

This commit is contained in:
open-trade 2020-11-23 01:16:17 +08:00
parent 06cb5b6c35
commit 8e529399c3
4 changed files with 204 additions and 153 deletions

View File

@ -3,18 +3,6 @@ import 'dart:async';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
class HexColor extends Color {
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
static int _getColorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll('#', '');
if (hexColor.length == 6) {
hexColor = 'FF' + hexColor;
}
return int.parse(hexColor, radix: 16);
}
}
class MyTheme { class MyTheme {
MyTheme._(); MyTheme._();
static const Color grayBg = Color(0xFFEEEEEE); static const Color grayBg = Color(0xFFEEEEEE);
@ -112,7 +100,7 @@ class _PasswordWidgetState extends State<PasswordWidget> {
bool _passwordVisible = false; bool _passwordVisible = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextFormField( return TextField(
autofocus: true, autofocus: true,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: widget.controller, controller: widget.controller,

View File

@ -72,7 +72,9 @@ class _HomePageState extends State<HomePage> {
Expanded( Expanded(
child: Container( child: Container(
padding: const EdgeInsets.only(left: 16, right: 16), padding: const EdgeInsets.only(left: 16, right: 16),
child: TextFormField( child: TextField(
autocorrect: false,
enableSuggestions: false,
style: TextStyle( style: TextStyle(
fontFamily: 'WorkSans', fontFamily: 'WorkSans',
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -82,18 +84,18 @@ class _HomePageState extends State<HomePage> {
// keyboardType: TextInputType.number, // keyboardType: TextInputType.number,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Remote ID', labelText: 'Remote ID',
hintText: 'Enter your remote ID', // hintText: 'Enter your remote ID',
border: InputBorder.none, border: InputBorder.none,
helperStyle: TextStyle( helperStyle: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16, fontSize: 16,
color: HexColor('#B9BABC'), color: Color(0xFFB9BABC),
), ),
labelStyle: TextStyle( labelStyle: TextStyle(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16, fontSize: 16,
letterSpacing: 0.2, letterSpacing: 0.2,
color: HexColor('#B9BABC'), color: Color(0xFFB9BABC),
), ),
), ),
autofocus: false, autofocus: false,
@ -106,7 +108,7 @@ class _HomePageState extends State<HomePage> {
height: 60, height: 60,
child: IconButton( child: IconButton(
icon: Icon(Icons.arrow_forward, icon: Icon(Icons.arrow_forward,
color: HexColor('#B9BABC'), size: 45), color: Color(0xFFB9BABC), size: 45),
onPressed: onConnect, onPressed: onConnect,
), ),
) )

View File

@ -132,7 +132,7 @@ class FfiModel with ChangeNotifier {
_display = _pi.displays[_pi.currentDisplay]; _display = _pi.displays[_pi.currentDisplay];
FFI.cursorModel.updateDisplayOrigin(_display.x, _display.y); FFI.cursorModel.updateDisplayOrigin(_display.x, _display.y);
} }
if (displays.length > 1) { if (displays.length > 0) {
showLoading('Waiting for image...'); showLoading('Waiting for image...');
_waitForImage = true; _waitForImage = true;
} }

View File

@ -87,138 +87,182 @@ class _RemotePageState extends State<RemotePage> {
return false; return false;
}, },
child: Scaffold( child: Scaffold(
floatingActionButton: _showBar floatingActionButton: _showBar
? null ? null
: FloatingActionButton( : FloatingActionButton(
mini: true, mini: true,
child: Icon(Icons.expand_less), child: Icon(Icons.expand_less),
backgroundColor: MyTheme.accent50, backgroundColor: MyTheme.accent50,
onPressed: () { onPressed: () {
setState(() => _showBar = !_showBar); setState(() => _showBar = !_showBar);
}), }),
bottomNavigationBar: _showBar bottomNavigationBar: _showBar
? BottomAppBar( ? BottomAppBar(
elevation: 10, elevation: 10,
color: MyTheme.accent, color: MyTheme.accent,
child: Row( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Row(children: [ Row(children: [
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () { onPressed: () {
close(); close();
}, },
), ),
IconButton(
color: Colors.white,
icon: Icon(Icons.keyboard),
onPressed: () {
SystemChrome.setEnabledSystemUIOverlays(
SystemUiOverlay.values);
_focusNode.requestFocus();
SystemChannels.textInput
.invokeMethod('TextInput.show');
}),
Transform.rotate(
angle: 15 * math.pi / 180,
child: IconButton(
color: Colors.white,
icon: Icon(Icons.flash_on),
onPressed: () {
showActions(context);
},
)),
IconButton(
color: Colors.white,
icon: Icon(Icons.tv),
onPressed: () {
showOptions(context);
},
),
Container(
color: _pan ? Colors.blue[500] : null,
child: IconButton(
color: Colors.white,
icon: Icon(Icons.pan_tool),
onPressed: () {
setState(() => _pan = !_pan);
},
))
]),
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.expand_more), icon: Icon(Icons.keyboard),
onPressed: () { onPressed: () {
setState(() => _showBar = !_showBar); SystemChrome.setEnabledSystemUIOverlays(
SystemUiOverlay.values);
_focusNode.requestFocus();
SystemChannels.textInput
.invokeMethod('TextInput.show');
}), }),
], Transform.rotate(
), angle: 15 * math.pi / 180,
) child: IconButton(
: null, color: Colors.white,
body: FlutterEasyLoading( icon: Icon(Icons.flash_on),
child: Container( onPressed: () {
color: MyTheme.canvasColor, showActions(context);
child: RawGestureDetector( },
gestures: { )),
MultiTouchGestureRecognizer: IconButton(
GestureRecognizerFactoryWithHandlers< color: Colors.white,
MultiTouchGestureRecognizer>( icon: Icon(Icons.tv),
() => MultiTouchGestureRecognizer(), onPressed: () {
(MultiTouchGestureRecognizer instance) { showOptions(context);
instance.onMultiTap = ( },
touchCount, ),
addOrRemove, Container(
) => color: _pan ? Colors.blue[500] : null,
print('$touchCount, $addOrRemove'); child: IconButton(
}, color: Colors.white,
), icon: Icon(Icons.pan_tool),
onPressed: () {
setState(() => _pan = !_pan);
},
))
]),
IconButton(
color: Colors.white,
icon: Icon(Icons.expand_more),
onPressed: () {
setState(() => _showBar = !_showBar);
}),
],
),
)
: null,
body: RawGestureDetector(
gestures: {
MultiTouchGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
MultiTouchGestureRecognizer>(
() => MultiTouchGestureRecognizer(),
(MultiTouchGestureRecognizer instance) {
instance.onMultiTap = (
touchCount,
addOrRemove,
) =>
print('$touchCount, $addOrRemove');
}, },
child: GestureDetector( ),
onTap: () { TapGestureRecognizer:
if (_pan) return; GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
}, () => TapGestureRecognizer(),
onDoubleTap: () { (TapGestureRecognizer instance) {
if (_pan) return; instance.onTap = () {
}, print('tap');
onLongPress: () { };
if (_pan) return; },
}, ),
child: InteractiveViewer( ImmediateMultiDragGestureRecognizer:
constrained: false, GestureRecognizerFactoryWithHandlers<
panEnabled: _pan, ImmediateMultiDragGestureRecognizer>(
onInteractionUpdate: (details) { () => ImmediateMultiDragGestureRecognizer(),
// print('$details'); (ImmediateMultiDragGestureRecognizer instance) {
}, instance
onInteractionStart: (s) { ..onStart = (x) {
print('$s'); return CustomDrag();
}, };
onInteractionEnd: (x) { },
print('$x'); ),
}, LongPressGestureRecognizer:
child: Stack(children: [ GestureRecognizerFactoryWithHandlers<
ImagePaint(), LongPressGestureRecognizer>(
CursorPaint(), () => LongPressGestureRecognizer(),
SizedBox( (LongPressGestureRecognizer instance) {
width: 0, instance.onLongPress = () {
height: 0, print('long press');
child: _bottom < 100 };
? Container() },
: TextField( ),
textInputAction: TextInputAction.newline, PanGestureRecognizer:
autocorrect: false, GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
enableSuggestions: false, () => PanGestureRecognizer(),
focusNode: _focusNode, (PanGestureRecognizer instance) {
maxLines: null, instance
keyboardType: TextInputType.multiline, ..onStart = (detail) {
onChanged: (x) => print('$x'), print('pan start');
), }
), ..onUpdate = (detail) {
])), print('$detail');
)), };
)))); },
),
ScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers<
ScaleGestureRecognizer>(
() => ScaleGestureRecognizer(),
(ScaleGestureRecognizer instance) {
instance
..onStart = (detail) {
print('scale start');
}
..onUpdate = (detail) {
print('$detail');
};
},
),
DoubleTapGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
DoubleTapGestureRecognizer>(
() => DoubleTapGestureRecognizer(),
(DoubleTapGestureRecognizer instance) {
instance.onDoubleTap = () {
print('double tap');
};
},
),
},
child: FlutterEasyLoading(
child: Container(
color: MyTheme.canvasColor,
child: Stack(children: [
ImagePaint(),
CursorPaint(),
SizedBox(
width: 0,
height: 0,
child: _bottom < 100
? Container()
: TextField(
textInputAction: TextInputAction.newline,
autocorrect: false,
enableSuggestions: false,
focusNode: _focusNode,
maxLines: null,
keyboardType: TextInputType.multiline,
onChanged: (x) => print('$x'),
),
),
])),
)),
));
} }
void close() { void close() {
@ -329,7 +373,6 @@ void wrongPasswordDialog(String id, BuildContext context) {
FlatButton( FlatButton(
textColor: MyTheme.accent, textColor: MyTheme.accent,
onPressed: () { onPressed: () {
Navigator.pop(context);
enterPasswordDialog(id, context); enterPasswordDialog(id, context);
}, },
child: Text('Retry'), child: Text('Retry'),
@ -443,10 +486,11 @@ class MultiTouchGestureRecognizer extends MultiTapGestureRecognizer {
var numberOfTouches = 0; var numberOfTouches = 0;
MultiTouchGestureRecognizer() { MultiTouchGestureRecognizer() {
super.onTapDown = (pointer, details) => addTouch(pointer, details); this
super.onTapUp = (pointer, details) => removeTouch(pointer, details); ..onTapDown = addTouch
super.onTapCancel = (pointer) => cancelTouch(pointer); ..onTapUp = removeTouch
super.onTap = (pointer) => captureDefaultTap(pointer); ..onTapCancel = cancelTouch
..onTap = captureDefaultTap;
} }
void addTouch(int pointer, TapDownDetails details) { void addTouch(int pointer, TapDownDetails details) {
@ -460,11 +504,28 @@ class MultiTouchGestureRecognizer extends MultiTapGestureRecognizer {
} }
void cancelTouch(int pointer) { void cancelTouch(int pointer) {
numberOfTouches = 0; numberOfTouches--;
print('$numberOfTouches x');
} }
void captureDefaultTap(int pointer) {} void captureDefaultTap(int pointer) {
print('$pointer');
}
} }
typedef MultiTouchGestureRecognizerCallback = void Function( typedef MultiTouchGestureRecognizerCallback = void Function(
int touchCount, bool addOrRemove); int touchCount, bool addOrRemove);
typedef OnUpdate(DragUpdateDetails details);
class CustomDrag extends Drag {
@override
void update(DragUpdateDetails details) {
print('xx $details');
}
@override
void end(DragEndDetails details) {
super.end(details);
}
}