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,9 +138,7 @@ 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,
child: SizedBox(
width: width, width: width,
height: height, height: height,
child: Center( child: Center(
@ -164,7 +162,6 @@ class KBLayoutTypeChooser extends StatelessWidget {
], ],
), ),
), ),
),
); );
} }
} }
@ -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 {