Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main
- import 'package:flutter/material.dart';
- import 'package:flutter_blue/flutter_blue.dart';
- import './SelectBondedDevicePage.dart';
- void main() => runApp(const MaterialApp(
- debugShowCheckedModeBanner: false,
- home: Home(),
- ));
- class Home extends StatelessWidget {
- const Home({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- FlutterBlue flutterBlue = FlutterBlue.instance;
- return Scaffold(
- appBar: AppBar(
- title: Wrap(
- direction: Axis.horizontal,
- crossAxisAlignment: WrapCrossAlignment.center,
- children: const <Widget>[
- Icon(
- Icons.bluetooth,
- //color : Colors.blue,
- ),
- Text(
- 'My BLE',
- //style : TextStyle(color : Colors.white),
- ),
- ],
- ),
- centerTitle: true,
- //backgroundColor: Colors.black,
- backgroundColor: Colors.white54,
- ),
- body: Center(
- child : Column(
- mainAxisAlignment : MainAxisAlignment.center,
- children: [
- Padding(
- padding: const EdgeInsets.all(15.0),
- child: ElevatedButton(
- onPressed: () async {
- // Start scanning
- //flutterBlue.startScan(timeout: Duration(seconds: 4));
- final BluetoothDevice? selectedDevice =
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) {
- return SelectBondedDevicePage();
- },
- ),
- );
- },
- child : const Text('Connect to paired device to chat'),
- style : ElevatedButton.styleFrom(
- primary: Colors.grey,
- padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
- ),
- ),
- ),
- ],
- ),
- ),
- backgroundColor: Colors.grey[800],
- );
- }
- }
- //selectBondedDevicePage
- import 'package:flutter/material.dart';
- import 'package:flutter_blue/flutter_blue.dart';
- import './main.dart';
- class SelectBondedDevicePage extends StatefulWidget {
- const SelectBondedDevicePage({Key? key}) : super(key: key);
- @override
- _SelectBondedDevicePageState createState() => _SelectBondedDevicePageState();
- }
- class _SelectBondedDevicePageState extends State<SelectBondedDevicePage> {
- @override
- Widget build(BuildContext context) {
- FlutterBlue flutterBlue = FlutterBlue.instance;
- return Scaffold(
- appBar: AppBar(
- backgroundColor: Colors.grey,
- centerTitle: true,
- title: Text('Select device'),
- actions: <Widget>[
- FittedBox(
- child: Container(
- margin: new EdgeInsets.all(16.0),
- child: CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation<Color>(
- Colors.white,
- ),
- ),
- ),
- )
- // : IconButton(
- // icon: Icon(Icons.replay),
- // onPressed: (){},
- // )
- ],
- ),
- body: Center(
- child: Text(
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement