diff --git a/example/lib/main.dart b/example/lib/main.dart index 9101f6f..c96007a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -285,7 +285,7 @@ class _GattViewState extends State { appBar: AppBar( title: Text('$address'), actions: [ - connectionView, + changeStateView, ], ), body: bodyView, @@ -378,32 +378,37 @@ class _GattViewState extends State { } extension on _GattViewState { - Widget get connectionView { + Widget get changeStateView { return ValueListenableBuilder( valueListenable: state, builder: (context, ConnectionState stateValue, child) { void Function()? onPressed; - var data = ''; + String data; switch (stateValue) { case ConnectionState.disconnected: onPressed = connect; data = '连接'; break; + case ConnectionState.connecting: + data = '连接'; + break; case ConnectionState.connected: onPressed = disconnect; data = '断开'; break; + case ConnectionState.disconnecting: + data = '断开'; + break; default: + data = ''; break; } return TextButton( onPressed: onPressed, - child: Text( - data, - style: TextStyle( - color: Colors.white, - ), + style: TextButton.styleFrom( + primary: Colors.white, ), + child: Text(data), ); }, );