|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import 'package:flutter/material.dart';
- import 'package:touch_demonstrator/ui/pageTouchPoints/AppBarPageTouchPoints.dart';
- import 'package:touch_demonstrator/ui/pageTouchPoints/SideBar.dart';
- import 'dart:core';
- import 'package:touch_demonstrator/src/blocs/BlocProvider.dart'; //bloc:
- import 'package:touch_demonstrator/ui/pageTouchPoints/ScanResultBottomSheet.dart';
- import 'package:touch_demonstrator/ui/pageTouchPoints/ButtonOrAnimation.dart';
- import 'package:touch_demonstrator/ui/pageTouchPoints/Logo.dart';
- import 'package:touch_demonstrator/ui/pageTouchPoints/Sensor.dart';
- import 'package:flutter_blue/flutter_blue.dart';
- import 'package:vibrate/vibrate.dart';
- import 'package:touch_demonstrator/model/vibrate.dart';
-
- class PageTouchPoints extends StatefulWidget {
- PageTouchPoints({Key key, this.title}) : super(key: key);
- final String title;
-
- @override
- _PageTouchPointsState createState() => new _PageTouchPointsState();
- }
-
- class _PageTouchPointsState extends State<PageTouchPoints> {
- final GlobalKey<ScaffoldState> mScaffoldState =
- new GlobalKey<ScaffoldState>();
- static Modal modal;
- static bool firstTime = true;
-
- @override
- void dispose() {
- final bBloc = BlocProvider.of(context).bluetoothBlocGetter;
- bBloc.disconnect.add(null); //disconnect everything
- super.dispose();
- }
-
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- print('didChangeDependencies');
-
- /// Manages Snackbar "no device found" and "Bluetooth off" and toggles the debugmode.
- final bBloc = BlocProvider.of(context).bluetoothBlocGetter;
- final debugBloc = BlocProvider.of(context).debugBlocGetter;
-
- _showSnackbar(String textInSnackBar) {
- /// Shows Snackbar for 0.5 s with String textInSnackBar in it
- print('snackbar $textInSnackBar');
- mScaffoldState.currentState.showSnackBar(SnackBar(
- content: Text(
- textInSnackBar,
- style: TextStyle(fontSize: 15),
- ),
- duration: Duration(milliseconds: 1000),
- ));
- }
-
- _toggleDebug(bool debugStatus) {
- vibrate(FeedbackType.success);
- _showSnackbar('Debug View: ${debugStatus ? 'enabled' : 'disabled'}!');
- }
-
- if (firstTime) {
- firstTime = false;
- modal = new Modal();
- bBloc.devicesFound$.listen((device) {
- if (device.length == 0) {
- print('Snackbar: No device found');
- _showSnackbar('No device found');
- vibrateDelayed(FeedbackType.warning, Duration(milliseconds: 150));
- } else {
- modal.connectBottomSheet(context, device);
- }
- });
- debugBloc.debugEnabledStatus$.listen((data) => _toggleDebug(data));
-
- bBloc.bluetoothState$
- .where((bluetoothState) => bluetoothState == BluetoothState.off)
- .listen(
- (bluetoothState) => _showBluetoothOffSnackbar(bluetoothState));
-
- bBloc.bluetoothState$
- .where((bluetoothState) => bluetoothState == BluetoothState.on)
- .listen((_) => mScaffoldState.currentState.removeCurrentSnackBar());
- } else {
- print('REMOVE current snack bar');
- mScaffoldState.currentState.removeCurrentSnackBar();
- }
- }
-
- _showBluetoothOffSnackbar(BluetoothState bluetoothState) {
- /// Shows Snackbar if Bluetooth is off to inform user.
- var textInSnackbar = 'Bluetooth is off!';
-
- print('snackbar $textInSnackbar');
- mScaffoldState.currentState.showSnackBar(SnackBar(
- backgroundColor: Colors.red,
- content: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Icon(Icons.warning),
- Padding(
- padding: EdgeInsets.only(left: 10.0),
- child: Text(
- textInSnackbar,
- textAlign: TextAlign.center,
- style: TextStyle(fontSize: 25),
- ),
- ),
- ],
- ),
- duration: Duration(days: 1),
- ));
- }
-
- @override
- Widget build(BuildContext context) {
- /// build UI for the main screen in the app
- return Scaffold(
- key: mScaffoldState,
- // necessary for toast message
- appBar: buildAppBarPageTouchPoints(context),
- drawer: LeftDrawer(),
- body: SafeArea(child: OrientationBuilder(builder: (context, orientation) {
- return _buildBody(orientation);
- // return _buildVerticalLayout();
- })),
- );
- }
-
- _buildBody(Orientation orientation) {
- if (orientation == Orientation.portrait)
- return _buildVerticalLayout();
- else
- return _buildHorizontalLayout();
- }
-
- static const _heightLogo = 100.0;
-
- _buildVerticalLayout() {
- /// Layout for vertical orientation
- EdgeInsets devicePadding = MediaQuery.of(context).padding;
- return Padding(
- padding: const EdgeInsets.all(5.0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Container(height: devicePadding.top),
- LogoWithText(_heightLogo),
- Expanded(child: Sensor()),
- ConnectButtonWithAnimations(),
- ],
- ),
- );
- }
-
- _buildHorizontalLayout() {
- /// Layout for horizontal orientation
- return Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- LogoWithText(_heightLogo),
- ConnectButtonWithAnimations(),
- ],
- ),
- Column(
- children: <Widget>[
- Sensor(),
- ],
- ),
- ],
- ),
- ]),
- );
- }
- }
|