fix keyboard type store

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-12-27 17:49:32 +08:00
parent ebdead8766
commit 50c33450b9
2 changed files with 39 additions and 40 deletions

View File

@ -6,7 +6,7 @@ import 'package:flutter_hbb/models/platform_model.dart';
import '../../common.dart'; import '../../common.dart';
typedef KBChoosedCallback = bool Function(String); typedef KBChoosedCallback = Future<bool> Function(String);
const double _kImageMarginVertical = 6.0; const double _kImageMarginVertical = 6.0;
const double _kImageMarginHorizental = 10.0; const double _kImageMarginHorizental = 10.0;
@ -78,11 +78,19 @@ class _KBChooser extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
onChanged(String? v) async {
if (v != null) {
if (await cb(v)) {
choosedType.value = v;
}
}
}
return Column( return Column(
children: [ children: [
TextButton( TextButton(
onPressed: () { onPressed: () {
choosedType.value = kbLayoutType; onChanged(kbLayoutType);
}, },
child: _KBImage( child: _KBImage(
kbLayoutType: kbLayoutType, kbLayoutType: kbLayoutType,
@ -98,21 +106,13 @@ class _KBChooser extends StatelessWidget {
splashRadius: 0, splashRadius: 0,
value: kbLayoutType, value: kbLayoutType,
groupValue: choosedType.value, groupValue: choosedType.value,
onChanged: (String? newValue) { onChanged: onChanged,
if (newValue != null) {
if (cb(newValue)) {
choosedType.value = newValue;
}
}
},
)), )),
Text(kbLayoutType), Text(kbLayoutType),
], ],
), ),
onPressed: () { onPressed: () {
if (cb(kbLayoutType)) { onChanged(kbLayoutType);
choosedType.value = kbLayoutType;
}
}, },
), ),
], ],
@ -138,31 +138,28 @@ class KBLayoutTypeChooser extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final imageWidth = width / 2 - dividerWidth; final imageWidth = width / 2 - dividerWidth;
return Container( return SizedBox(
color: Colors.white, width: width,
child: SizedBox( height: height,
width: width, child: Center(
height: height, child: Row(
child: Center( children: [
child: Row( _KBChooser(
children: [ kbLayoutType: _kKBLayoutTypeISO,
_KBChooser( imageWidth: imageWidth,
kbLayoutType: _kKBLayoutTypeISO, choosedType: choosedType,
imageWidth: imageWidth, cb: cb,
choosedType: choosedType, ),
cb: cb, VerticalDivider(
), width: dividerWidth * 2,
VerticalDivider( ),
width: dividerWidth * 2, _KBChooser(
), kbLayoutType: _kKBLayoutTypeNotISO,
_KBChooser( imageWidth: imageWidth,
kbLayoutType: _kKBLayoutTypeNotISO, choosedType: choosedType,
imageWidth: imageWidth, cb: cb,
choosedType: choosedType, ),
cb: cb, ],
),
],
),
), ),
), ),
); );
@ -215,8 +212,8 @@ showKBLayoutTypeChooser(
width: 360, width: 360,
height: 200, height: 200,
dividerWidth: 4.0, dividerWidth: 4.0,
cb: (String v) { cb: (String v) async {
bind.setLocalKbLayoutType(kbLayoutType: v); await bind.setLocalKbLayoutType(kbLayoutType: v);
KBLayoutType.value = bind.getLocalKbLayoutType(); KBLayoutType.value = bind.getLocalKbLayoutType();
return v == KBLayoutType.value; return v == KBLayoutType.value;
}), }),

View File

@ -1024,7 +1024,9 @@ impl LocalConfig {
} }
pub fn set_kb_layout_type(kb_layout_type: String) { pub fn set_kb_layout_type(kb_layout_type: String) {
LOCAL_CONFIG.write().unwrap().kb_layout_type = kb_layout_type let mut config = LOCAL_CONFIG.write().unwrap();
config.kb_layout_type = kb_layout_type;
config.store();
} }
pub fn get_size() -> Size { pub fn get_size() -> Size {