고원빈

[frontend] bluetooth 연결 작업 중

......@@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.Smart_Medicine_Box"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
......
......@@ -238,7 +238,7 @@ Widget ineerInformationpage(BuildContext context) {
children: <Widget>[
Container(
width: size.width * 0.43,
height: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
......@@ -265,7 +265,7 @@ Widget ineerInformationpage(BuildContext context) {
),
Container(
width: size.width,
height: size.height * 0.14,
height: size.height * 0.145,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
......@@ -276,7 +276,7 @@ Widget ineerInformationpage(BuildContext context) {
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontSize: 76,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
......@@ -299,7 +299,7 @@ Widget ineerInformationpage(BuildContext context) {
),
Container(
width: size.width * 0.43,
height: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
......@@ -377,7 +377,7 @@ Widget ineerInformationpage(BuildContext context) {
children: <Widget>[
Container(
width: size.width * 0.43,
height: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
......@@ -438,7 +438,7 @@ Widget ineerInformationpage(BuildContext context) {
),
Container(
width: size.width * 0.43,
height: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
......
......@@ -161,7 +161,7 @@ class _SettingPageState extends State<SettingPage> {
));
},
child: Text(
' 정보 수정',
'회원 정보 수정',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
......
......@@ -10,7 +10,42 @@ class Bluetooth extends StatefulWidget {
FlutterBlue flutterBlue;
class _BluetoothState extends State<Bluetooth> {
@override
void initState() {
super.initState();
flutterBlue = FlutterBlue.instance;
}
void _startscan() {
flutterBlue.startScan(timeout: Duration(seconds: 12));
var subscription = flutterBlue.scanResults.listen((results) {
// do something with scan results
for (ScanResult r in results) {
print(
'Device Name : ${r.device.name} // Device ID : ${r.device.id} // Device rssi: ${r.rssi}');
}
});
}
Widget build(BuildContext context) {
Widget _buildItem(ScanResult s) {
return ListTile(
leading: Text(s.rssi.toString()),
title: Text(s.device.name),
subtitle: Text(s.device.id.id),
onTap: () =>
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return Device(device: s.device);
})),
);
}
Widget _buildList(List<ScanResult> scanResults) {
return Column(
children: scanResults.map((v) => _buildItem(v)).toList(),
);
}
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
......@@ -65,10 +100,80 @@ class _BluetoothState extends State<Bluetooth> {
],
),
),
body: Center(
child: Text('약병 내부 페이지 작업 영역'),
body: SingleChildScrollView(
child: StreamBuilder<List<ScanResult>>(
stream: FlutterBlue.instance.scanResults,
initialData: [],
builder: (c, snapshot) {
return _buildList(snapshot.data);
}),
),
floatingActionButton: StreamBuilder<bool>(
stream: FlutterBlue.instance.isScanning,
initialData: false,
builder: (c, snapshot) {
if (snapshot.data) {
return FloatingActionButton(
child: Icon(Icons.stop),
onPressed: () => FlutterBlue.instance.stopScan(),
backgroundColor: Colors.red,
);
} else {
return FloatingActionButton(
child: Icon(Icons.search),
onPressed: () => FlutterBlue.instance
.startScan(timeout: Duration(seconds: 4)));
}
},
),
),
);
}
}
class Device extends StatefulWidget {
Device({Key key, this.device}) : super(key: key);
final BluetoothDevice device;
@override
_DeviceState createState() => _DeviceState();
}
class _DeviceState extends State<Device> {
void initState() {
super.initState();
widget.device.connect();
}
@override
void dispose() {
widget.device.disconnect();
super.dispose();
}
Widget _buildIconButton() {
return StreamBuilder<BluetoothDeviceState>(
stream: widget.device.state,
initialData: BluetoothDeviceState.connecting,
builder: (c, snapshot) {
if (snapshot.data != BluetoothDeviceState.connected)
return Icon(Icons.warning);
return IconButton(
icon: Icon(Icons.bluetooth_searching),
onPressed: () => widget.device.discoverServices(),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.device.name),
actions: <Widget>[
_buildIconButton(),
],
),
body: Text('hello'),
);
}
}
......