Commit 4eb1d410 authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

Advances

parent 0c4e2558
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}]}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-02-21 18:27:44.378393","version":"1.14.6"}
\ No newline at end of file
import 'package:flutter/material.dart';
// TODO Change to something that pops forward
class PopForwardRoute extends PageRouteBuilder {
final Widget page;
PopForwardRoute({this.page}) : super(
......@@ -14,10 +13,10 @@ class PopForwardRoute extends PageRouteBuilder {
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) => SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, -1),
end: Offset.zero,
) => ScaleTransition(
scale: Tween<double>(
begin: 0,
end: 1,
).animate(animation),
child: child,
),
......
......@@ -25,9 +25,22 @@ class BTLEHandler {
fblueInstance.setLogLevel(LogLevel.info);
}
bool isDeviceConnected() => _device != null;
/// [Stream] that tracks when the app is connected to the [BluetoothDevice]
Stream<bool> isDeviceConnected() async* {
while (true) {
await Future.delayed(Duration(milliseconds: 750));
yield (this._device != null);
}
}
Future<void> connect() => this._device?.let((it) => it.connect());
/// Makes the phone connect to the [BluetoothDevice] and initiate [BluetoothService] discovery.
Future<void> connect() => this._device?.let(
(it) {
it.connect();
it.discoverServices();
return;
}
);
Future<dynamic> disconnect() => this._device?.let((it) {
_device = null;
......@@ -51,6 +64,8 @@ class BTLEHandler {
BluetoothDevice _device;
setDevice(BluetoothDevice device) => device?.let((it) => this._device = it);
bool switchState() {
......@@ -63,13 +78,13 @@ class BTLEHandler {
}
void _start() {
WakeService().modifyWakeService(true).then((value) => print('Device will stay awake $value'));
WakeService().modifyWakeService(true).then((value) => print('_device will stay awake $value'));
started = true;
t = new Timer.periodic(duration, (Timer t) => print("${new DateTime.now()}"));
}
void _end() {
WakeService().modifyWakeService(false).then((value) => print('Device will stay awake $value'));
WakeService().modifyWakeService(false).then((value) => print('_device will stay awake $value'));
t.cancel();
}
......
......@@ -9,9 +9,9 @@ class BluetoothOffScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.lightBlue,
body: Center(
return Container(
color: Colors.lightBlue,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
......@@ -21,10 +21,10 @@ class BluetoothOffScreen extends StatelessWidget {
color: Colors.white54,
),
Text(
'Bluetooth Adapter is ${state.toString().substring(15)}.', // TODO internationalize
'Bluetooth Adapter is ${state.toString()}.', // TODO internationalize
style: Theme.of(context)
.primaryTextTheme
.subtitle
.subtitle1
.copyWith(color: Colors.white),
),
],
......
......@@ -23,7 +23,7 @@ class BluetoothUnavailableScreen extends StatelessWidget {
AppLocalization.of(context).bluetoothUnsupported,
style: Theme.of(context)
.primaryTextTheme
.subtitle
.subtitle1
.copyWith(color: Colors.white),
),
],
......
......@@ -31,26 +31,24 @@ class _BluetoothButtonState extends State<BluetoothButton> {
borderRadius: BorderRadius.circular(1000.0),
onTap: () {
print("onTap");
bool returnValue;
if (!this._bluetoothConnected)
if (!this._bluetoothConnected) {
print("Tap On");
Navigator.push(
context,
PopForwardRoute(
page: BluetoothDialog(),
),
).then((value) => returnValue = value);
).then((value) => setState(() {
if (value)
_bluetoothConnected = true;
}));
else {
} else {
BTLEHandler().disconnect();
print('Tap off');
setState(() => _bluetoothConnected = false );
return true;
}
this.onTapOff().then((value) {
print('Tap off $value');
if (value)
setState(() => {
_bluetoothConnected = !_bluetoothConnected
});
});
},
child: Padding(
padding: EdgeInsets.all(10),
......
......@@ -16,9 +16,24 @@ class BTLEScanTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
title: SlimListTile(
title: result.device.name,
subtitle: result.device.id.toString(),
title: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
result.device.name,
overflow: TextOverflow.fade,
style: TextStyle(
fontSize: 18
),
),
Text(
result.device.id.toString(),
style: Theme.of(context).textTheme.caption,
),
],
),
),
onTap: (result.advertisementData.connectable) ? onTap : null,
);
......
import 'package:flutter/widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SlimListTile extends StatelessWidget {
final String title;
final String subtitle;
SlimListTile({@required this.title, @required this.subtitle});
@override
Widget build(BuildContext context) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
overflow: TextOverflow.fade,
),
Text(
subtitle,
style: Theme.of(context).textTheme.caption,
),
],
),
);
}
}
\ No newline at end of file
......@@ -6,14 +6,13 @@ import 'package:logair_application/handlers/bluetooth_le_handler.dart';
import 'package:logair_application/ui/carousel_card.dart';
import 'package:logair_application/services/battery_service.dart';
import 'package:logair_application/ui/components/bluetooth_button.dart';
import 'package:logair_application/animation/forward_animation.dart';
import 'package:logair_application/ui/dialog/bluetooth_dialog.dart';
class DataWidget extends StatelessWidget {
DataWidget();
@override
Widget build(BuildContext context) {
Widget build(BuildContext context) {
Widget widget = Center(
child: Column(
children: [
......@@ -35,12 +34,29 @@ class DataWidget extends StatelessWidget {
child: Text('Toggle BTLE Service'),
),
BluetoothButton(),
StreamBuilder(
stream: BTLEHandler().isDeviceConnected(),
initialData: false,
builder: (context, snapshot) {
final bool value = snapshot.data;
if (value)
return Text("Connected");
else
return Text("Not connected");
},
),
/*StreamBuilder(
stream: BTLEHandler().getDevice().services,
initialData: [],
builder: (context, snapshot) {
final value = snapshot.data;
return Text(value);
},
)*/
]
),
);
return CarouselCard(child: widget, color: Colors.green);
}
}
_onTapOff(BuildContext context) async {
}
}
\ No newline at end of file
......@@ -17,16 +17,27 @@ class BluetoothDialog extends StatefulWidget {
class _BluetoothDialogState extends State<BluetoothDialog> {
_BluetoothDialogState({Key key});
bool bluetoothAvailable = false;
bool bluetoothAvailable = true;
bool bluetoothAvailabilityChecked = false;
BluetoothState state;
@override
Widget build(BuildContext context) {
if (!bluetoothAvailable)
if (!bluetoothAvailabilityChecked)
BTLEHandler().fblueInstance.isAvailable.then((value) => setState(() {
bluetoothAvailable = true;
bluetoothAvailabilityChecked = true;
bluetoothAvailable = value;
print("btAvail ? $bluetoothAvailable");
}));
BTLEHandler().fblueInstance.state.listen((newState) {
if (state != newState) {
setState(() {
state = newState;
});
}
});
return SafeArea(
child: Scaffold(
body: Center(
......@@ -34,16 +45,16 @@ class _BluetoothDialogState extends State<BluetoothDialog> {
children: <Widget>[
Expanded(
flex: 9,
child: (bluetoothAvailable) ?
child:
(bluetoothAvailable) ?
StreamBuilder<BluetoothState>(
stream: BTLEHandler().fblueInstance.state,
builder: (context, snapshot) {
final state = snapshot.data;
if (state == BluetoothState.on) {
return BluetoothSelectionDialog();
} else {
return BluetoothOffScreen(state: state);
}
final Widget widget = (state == BluetoothState.on) ?
BluetoothSelectionDialog() :
BluetoothOffScreen(state: state);
return widget;
},
) :
BluetoothUnavailableScreen()
......
......@@ -45,100 +45,110 @@ class _BluetoothSelectionDialogState extends State<BluetoothSelectionDialog> {
return BaseWidget(
builder: (context, sizingInfo) => Container(
height: sizingInfo.screenSize.height * 0.9,
width: sizingInfo.screenSize.width * 0.9,
child: SingleChildScrollView(
padding: EdgeInsets.all(0),
child: Container(
child: Column(
children: <Widget>[
ListTile(
leading: IconButton(
padding: EdgeInsets.all(0),
icon: Icon(Icons.arrow_back),
onPressed: () async {
if (await BTLEHandler().fblueInstance.isScanning.first)
BTLEHandler().fblueInstance.stopScan();
Navigator.of(context).pop(false);
},
child: RefreshIndicator(
onRefresh: () => BTLEHandler().fblueInstance.startScan(),
child: SingleChildScrollView(
padding: EdgeInsets.all(0),
child: Container(
child: Column(
children: <Widget>[
ListTile(
leading: IconButton(
padding: EdgeInsets.all(0),
icon: Icon(Icons.arrow_back),
onPressed: () async {
if (await BTLEHandler().fblueInstance.isScanning.first)
BTLEHandler().fblueInstance.stopScan();
Navigator.of(context).pop(false);
},
),
title: Text(
AppLocalization.of(context).bluetoothScanMessage,
style: Theme.of(context).textTheme.headline6,
textAlign: TextAlign.center,
),
dense: true,
trailing: IconButton(
padding: EdgeInsets.all(0),
icon: Icon(Icons.refresh),
onPressed: () => BTLEHandler().fblueInstance.startScan(timeout: Duration(seconds: 5)),
),
),
title: Text(
AppLocalization.of(context).bluetoothScanMessage
Divider(),
Text(
AppLocalization.of(context).bluetoothFrequent
),
dense: true,
trailing: IconButton(
padding: EdgeInsets.all(0),
icon: Icon(Icons.refresh),
onPressed: () => BTLEHandler().fblueInstance.startScan(timeout: Duration(seconds: 5)),
),
),
Divider(),
Text(
AppLocalization.of(context).bluetoothFrequent
),
StreamBuilder<List<ScanResult>>(
stream: BTLEHandler().fblueInstance.scanResults.transform(
new StreamTransformer.fromHandlers(
handleData: (List<ScanResult> list, EventSink<List<ScanResult>> sink) =>
sink.add(list.where((result) => _frequentDevices != null ? _frequentDevices.map((Device d) => d.address).contains(result.device.id.toString()) : false).toList())
StreamBuilder<List<ScanResult>>(
stream: BTLEHandler().fblueInstance.scanResults.transform(
new StreamTransformer.fromHandlers(
handleData: (List<ScanResult> list, EventSink<List<ScanResult>> sink) =>
sink.add(list.where((result) => _frequentDevices != null ? _frequentDevices.map((Device d) => d.address).contains(result.device.id.toString()) : false).toList())
)
),
initialData: [],
builder: (context, snapshot) => Column(
children: (snapshot.data.length > 0) ?
snapshot.data.map(
(result) => BTLEScanTile(
result: result,
onTap: () {
BTLEHandler().setDevice(result.device);
BTLEHandler().connect();
Navigator.of(context).pop(true);
}
),
).toList() : <Widget>[
Text(
AppLocalization.of(context).none,
style: Theme.of(context).textTheme.caption,
)
],
)
),
initialData: [],
builder: (context, snapshot) => Column(
children: (snapshot.data.length > 0) ?
snapshot.data.map(
(result) => BTLEScanTile(
result: result,
onTap: () {
BTLEHandler().setDevice(result.device);
BTLEHandler().connect();
Navigator.of(context).pop(true);
}
),
).toList() : <Widget>[
Text(
AppLocalization.of(context).none,
Divider(),
Text(
AppLocalization.of(context).bluetoothAvailable
),
StreamBuilder<List<ScanResult>>(
stream: BTLEHandler().fblueInstance.scanResults.transform(
new StreamTransformer.fromHandlers(
handleData: (List<ScanResult> list, EventSink<List<ScanResult>> sink) =>
sink.add(
list.where(
(result) =>
((_frequentDevices != null) ?
!_frequentDevices.map((Device d) => d.address).contains(result.device.id.toString())
: true) && result.device.name.length > 0).toList())
)
),
initialData: [],
builder: (context, snapshot) => Column(
children: (snapshot.data.length > 0) ?
snapshot.data.map(
(result) => BTLEScanTile(
result: result,
onTap: () {
BTLEHandler().fblueInstance.stopScan();
BTLEHandler().setDevice(result.device);
BTLEHandler().connect();
Navigator.of(context).pop(true);
}
),
).toList() : <Widget>[
Text(
"None",
style: Theme.of(context).textTheme.caption,
)
],
)
),
Divider(),
Text(
AppLocalization.of(context).bluetoothAvailable
),
StreamBuilder<List<ScanResult>>(
stream: BTLEHandler().fblueInstance.scanResults.transform(
new StreamTransformer.fromHandlers(
handleData: (List<ScanResult> list, EventSink<List<ScanResult>> sink) =>
sink.add(list.where((result) => _frequentDevices != null ? !_frequentDevices.map((Device d) => d.address).contains(result.device.id.toString()) : true).toList())
)
),
initialData: [],
builder: (context, snapshot) => Column(
children: (snapshot.data.length > 0) ?
snapshot.data.map(
(result) => BTLEScanTile(
result: result,
onTap: () {
BTLEHandler().fblueInstance.stopScan();
BTLEHandler().setDevice(result.device);
BTLEHandler().connect();
Navigator.of(context).pop(true);
}
),
).toList() : <Widget>[
Text(
"None",
style: Theme.of(context).textTheme.caption,
)
],
)
),
],
],
),
),
),
)
),
),
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment