好,所以我只是想使用flutterblue库接收一个蓝牙设备,但是几乎每次我尝试使用它时,遵循使用指南的idk似乎都会失败,并且尝试在示例应用程序中使用代码会造成混淆。天哪,如果有人甚至可以将我指向基础的Flutter blue教程,我将永远感激不已。
我要做的就是在第三个容器中显示由蓝牙设备组成的数据流,而我所做的一切都失败了。帮助我是一个扑扑的菜鸟。这是控制台中的错误
═══════════════════════════════════════════════ ══════════════════════════════════════════════════ ═══ 在371毫秒内重新加载582个库中的0个。
════════(2)服务库捕获到异常 ══════════════════════════════════════════════════ PlatformException(错误,没有要取消的活动流,null) ══════════════════════════════════════════════════ ══════════════════════════════════════════════════
════════(3)小部件库捕获到异常 ══════════════════════════════════════════════════ ═ 'package:flutter / src / widgets / async.dart':断言失败:386行 排名15:“ builder!= null”:不正确。相关的引起错误 小部件为:_SnapshotScreenState 文件:/// C:/Users/sqandil/Downloads/simple_firebase_auth-completed-part-one/flutterLoginBT/simple_firebase_auth-completed-part-one/lib/snapshot.dart:34:22
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:provider/provider.dart';
import 'package:simple_firebase_auth/home_page.dart';
import 'package:simple_firebase_auth/util/hexcolor.dart';
// flutter blue imports
import 'dart:async';
import 'dart:math';
import 'package:flutter_blue/flutter_blue.dart';
//import 'package:flutter_blue/flutter_blue.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:simple_firebase_auth/widgets.dart';
import 'auth.dart';
class SnapshotScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.lightBlue,
home: StreamBuilder<BluetoothState>(
stream: FlutterBlue.instance.state,
initialData: BluetoothState.unknown,
builder: (c, snapshot) {
final state = snapshot.data;
if (state == BluetoothState.on) {
return _SnapshotScreenState();
}
return BluetoothOffScreen(state: state);
}),
);
}
_SnapshotScreenState createState() => _SnapshotScreenState();
}
// ignore: must_be_immutable
class _SnapshotScreenState extends StatelessWidget {
//const SnapshotScreenState({Key key, this.state}) : super(key: key);
//String dataFromDevice;
Color _purple = HexColor("#6908D6");
Color _cornellBlue = HexColor("#2467ed");
Color _palePink = HexColor("#f7c3ee");
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hand App'),
backgroundColor: _cornellBlue,
),
body: Container(
margin: EdgeInsets.only(top: MediaQuery.of(context).size.height*.1), // use this to calculate the height of device and place widgets percentage wise
alignment: Alignment.center,
color: Colors.white,
child: ListView(
scrollDirection: Axis.vertical,
padding: EdgeInsets.all(8),
children: <Widget>[
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
color: _cornellBlue.withOpacity(0.5),
borderRadius: BorderRadius.circular(12.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("null",style: TextStyle(
color: _purple,
fontWeight: FontWeight.normal,
fontSize: 15
),),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text("null", style: TextStyle(
color: _purple,
fontWeight: FontWeight.bold,
fontSize: 30
),),
)
],
),
),
Container(
margin: EdgeInsets.only(top: 20),
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: _cornellBlue,
border: Border.all(
color: Colors.blueGrey.shade100,
style: BorderStyle.solid
),
borderRadius: BorderRadius.circular(12)
),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left:10.0, right: 20.0),
child: RaisedButton(
child: Text("Search"),
onPressed: () async{
debugPrint("test");
},
),
),
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: RaisedButton(
child: Text("Snapshot"),
onPressed: () async{
debugPrint("test");
},
),
),
Padding(
padding: const EdgeInsets.only(left:15.0, right: 4.0),
child: RaisedButton(
child: Text("Docs"),
onPressed: (){
debugPrint("test");
},
),
)
],
),
),
Container(
margin: EdgeInsets.only(top: 20),
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: _cornellBlue,
border: Border.all(
color: Colors.blueGrey.shade100,
style: BorderStyle.solid
),
borderRadius: BorderRadius.circular(12)
),
child: Column(
children: <Widget>[
StreamBuilder<List<BluetoothDevice>>(
//stream: Stream.periodic(Duration(seconds: 2)).asyncMap((_) => FlutterBlue.instance.connectedDevices),
)
],
)
)],
),
),
);
}
}