Advertisement
rajath_pai

aug5_2pages

Aug 5th, 2021
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.52 KB | None | 0 0
  1. // main
  2.  
  3.   import 'package:flutter/material.dart';
  4.   import 'package:flutter_blue/flutter_blue.dart';
  5.  
  6.   import './SelectBondedDevicePage.dart';
  7.  
  8.   void main() => runApp(const MaterialApp(
  9.     debugShowCheckedModeBanner: false,
  10.     home: Home(),
  11.   ));
  12.  
  13.  
  14.   class Home extends StatelessWidget {
  15.     const Home({Key? key}) : super(key: key);
  16.  
  17.     @override
  18.     Widget build(BuildContext context) {
  19.       FlutterBlue flutterBlue = FlutterBlue.instance;
  20.       return Scaffold(
  21.         appBar: AppBar(
  22.           title: Wrap(
  23.             direction: Axis.horizontal,
  24.             crossAxisAlignment: WrapCrossAlignment.center,
  25.             children: const <Widget>[
  26.               Icon(
  27.                   Icons.bluetooth,
  28.                 //color : Colors.blue,
  29.               ),
  30.               Text(
  31.                   'My BLE',
  32.                 //style : TextStyle(color : Colors.white),
  33.               ),
  34.             ],
  35.           ),
  36.           centerTitle: true,
  37.           //backgroundColor: Colors.black,
  38.           backgroundColor: Colors.white54,
  39.         ),
  40.         body: Center(
  41.           child : Column(
  42.             mainAxisAlignment : MainAxisAlignment.center,
  43.             children: [
  44.               Padding(
  45.                 padding: const EdgeInsets.all(15.0),
  46.                 child: ElevatedButton(
  47.                     onPressed: () async {
  48.                       // Start scanning
  49.                             //flutterBlue.startScan(timeout: Duration(seconds: 4));
  50.                             final BluetoothDevice? selectedDevice =
  51.                             await Navigator.of(context).push(
  52.                             MaterialPageRoute(
  53.                             builder: (context) {
  54.                               return SelectBondedDevicePage();
  55.                           },
  56.                         ),
  57.                       );
  58.                     },
  59.                   child : const Text('Connect to paired device to chat'),
  60.                   style : ElevatedButton.styleFrom(
  61.                     primary: Colors.grey,
  62.                     padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
  63.                   ),
  64.                 ),
  65.               ),
  66.             ],
  67.           ),
  68.         ),
  69.         backgroundColor: Colors.grey[800],
  70.       );
  71.     }
  72.   }
  73.  
  74. //selectBondedDevicePage
  75.  
  76. import 'package:flutter/material.dart';
  77. import 'package:flutter_blue/flutter_blue.dart';
  78.  
  79. import './main.dart';
  80.  
  81. class SelectBondedDevicePage extends StatefulWidget {
  82.   const SelectBondedDevicePage({Key? key}) : super(key: key);
  83.  
  84.   @override
  85.   _SelectBondedDevicePageState createState() => _SelectBondedDevicePageState();
  86. }
  87.  
  88. class _SelectBondedDevicePageState extends State<SelectBondedDevicePage> {
  89.   @override
  90.   Widget build(BuildContext context) {
  91.     FlutterBlue flutterBlue = FlutterBlue.instance;
  92.     return Scaffold(
  93.       appBar: AppBar(
  94.         backgroundColor: Colors.grey,
  95.         centerTitle: true,
  96.         title: Text('Select device'),
  97.         actions: <Widget>[
  98.                FittedBox(
  99.             child: Container(
  100.               margin: new EdgeInsets.all(16.0),
  101.               child: CircularProgressIndicator(
  102.                 valueColor: AlwaysStoppedAnimation<Color>(
  103.                   Colors.white,
  104.                 ),
  105.               ),
  106.             ),
  107.           )
  108.           //     : IconButton(
  109.           //   icon: Icon(Icons.replay),
  110.           //   onPressed: (){},
  111.           // )
  112.         ],
  113.       ),
  114.       body: Center(
  115.         child: Text(
  116.  
  117.         ),
  118.       ),
  119.     );
  120.   }
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement