更新示例程序
This commit is contained in:
@ -285,7 +285,7 @@ class _GattViewState extends State<GattView> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('$address'),
|
title: Text('$address'),
|
||||||
actions: [
|
actions: [
|
||||||
connectionView,
|
changeStateView,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: bodyView,
|
body: bodyView,
|
||||||
@ -378,32 +378,37 @@ class _GattViewState extends State<GattView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension on _GattViewState {
|
extension on _GattViewState {
|
||||||
Widget get connectionView {
|
Widget get changeStateView {
|
||||||
return ValueListenableBuilder(
|
return ValueListenableBuilder(
|
||||||
valueListenable: state,
|
valueListenable: state,
|
||||||
builder: (context, ConnectionState stateValue, child) {
|
builder: (context, ConnectionState stateValue, child) {
|
||||||
void Function()? onPressed;
|
void Function()? onPressed;
|
||||||
var data = '';
|
String data;
|
||||||
switch (stateValue) {
|
switch (stateValue) {
|
||||||
case ConnectionState.disconnected:
|
case ConnectionState.disconnected:
|
||||||
onPressed = connect;
|
onPressed = connect;
|
||||||
data = '连接';
|
data = '连接';
|
||||||
break;
|
break;
|
||||||
|
case ConnectionState.connecting:
|
||||||
|
data = '连接';
|
||||||
|
break;
|
||||||
case ConnectionState.connected:
|
case ConnectionState.connected:
|
||||||
onPressed = disconnect;
|
onPressed = disconnect;
|
||||||
data = '断开';
|
data = '断开';
|
||||||
break;
|
break;
|
||||||
|
case ConnectionState.disconnecting:
|
||||||
|
data = '断开';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
data = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return TextButton(
|
return TextButton(
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
child: Text(
|
style: TextButton.styleFrom(
|
||||||
data,
|
primary: Colors.white,
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
child: Text(data),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user