123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import 'package:flutter_blue/flutter_blue.dart';
- import 'package:flutter/material.dart';
- import 'package:touch_demonstrator/src/blocs/BlocProvider.dart';
-
-
- class Modal {
- _buildScanResult(
- BuildContext context, Map<DeviceIdentifier, ScanResult> scanResults) {
- final bBloc = BlocProvider.of(context).bluetoothBlocGetter;
- return scanResults.values
- .where((result) => result.advertisementData.localName
- .contains('Touchpad Demonstrator'))
- .map((result) => ScanResultTile(
- result: result,
- onTapCallback: () {
- bBloc.connect.add(result);
- print('Connect to ${result.device.name} pressed!');
- Navigator.pop(context);
- }))
- .toList();
- }
-
- _buildHeaderBottomSheet(BuildContext context) {
- return Container(
- color: Theme.of(context).primaryColor,
- child: ListTile(
- title: Center(
- child: Text(
- "CHOOSE TOUCHPAD",
- style: TextStyle(color: Colors.white),
- ),
- ),
- ),
- );
- }
-
- connectBottomSheet(
- BuildContext context, Map<DeviceIdentifier, ScanResult> scanResults) {
- print('Modal Sheet - Result Count: ${scanResults.length}');
- var _bottomSheetElements = List<Widget>();
- _bottomSheetElements.add(_buildHeaderBottomSheet(context));
- _bottomSheetElements.addAll(_buildScanResult(context, scanResults));
- showModalBottomSheet(
- context: context,
- builder: (BuildContext context) {
- return Container(
- child: Padding(
- padding: EdgeInsets.all(0.0),
- child: ListView(
- shrinkWrap: true, children: _bottomSheetElements)));
- });
- }
- }
-
- class ScanResultTile extends StatelessWidget {
- final ScanResult result;
- final VoidCallback onTapCallback;
-
- const ScanResultTile({Key key, this.result, this.onTapCallback})
- : super(key: key);
-
- _buildTitle(BuildContext context) {
- var textOfTile;
- (result.device.name.length > 0)
- ? textOfTile = result.device.name
- : textOfTile = result.device.id.toString();
-
- return Flexible(
- child: Container(
- child: Text(
- textOfTile,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(fontWeight: FontWeight.bold),
- )));
- }
-
- _buildConnectButton(BuildContext context) {
- return OutlineButton(
- borderSide: BorderSide(color: Theme.of(context).primaryColor),
- shape: BeveledRectangleBorder(),
- onPressed: (result.advertisementData.connectable) ? onTapCallback : null,
- child: Text('CONNECT'),
- ); // Name of devices
- }
-
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- _buildTitle(context),
- _buildConnectButton(context),
- ],
- ),
- ),
- );
- }
- }
|