Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 检查BLE是否在颤振中关闭时显示底部板材_Flutter_Dart - Fatal编程技术网

Flutter 检查BLE是否在颤振中关闭时显示底部板材

Flutter 检查BLE是否在颤振中关闭时显示底部板材,flutter,dart,Flutter,Dart,我想在页面上检查蓝牙时显示下页。该页面还包括底部导航栏。当它检查条件时,它将打印底部工作表,这意味着它将进入底部工作表小部件,但它不会显示在屏幕上。我还想在最后展示下一页。我怎样才能做到这一点 代码: import'包:epicare/BluetoothAccessDenied.dart'; 导入“包:epicare/BluetoothConnectBand.dart”; 导入“包:epicare/BluetoothScanningDevices.dart”; 进口“包装:颤振/cupertin

我想在页面上检查蓝牙时显示下页。该页面还包括底部导航栏。当它检查条件时,它将打印底部工作表,这意味着它将进入底部工作表小部件,但它不会显示在屏幕上。我还想在最后展示下一页。我怎样才能做到这一点

代码:

import'包:epicare/BluetoothAccessDenied.dart';
导入“包:epicare/BluetoothConnectBand.dart”;
导入“包:epicare/BluetoothScanningDevices.dart”;
进口“包装:颤振/cupertino.dart”;
进口“包装:颤振/材料.省道”;
进口“包装:飞舞蓝/飞舞蓝.飞镖”;
类BluetoothAllowScreen扩展StatefulWidget{
@凌驾
_BluetoothAllowScreenState createState()=>\u BluetoothAllowScreenState();
}
类BluetoothAllowScreenState扩展状态{
flatterblue flatterblue=flatterblue.instance;
布尔·伊斯布伦;
//初始化和监听设备状态
@凌驾
void initState(){
//TODO:实现initState
super.initState();
//检查蓝牙当前状态
blue.instance.state.listen((state){
if(state==BluetoothState.on){
打印(“蓝牙开启”);
isBleOn=真;
//提醒用户打开蓝牙。
}else if(state==BluetoothState.off){
打印(“蓝牙关闭”);
isBleOn=假;
}
打印(iBleon);
//通过显示底页请求打开BLE
if(isBleOn==false){
打印(“请求启用BLE”);
底板();
}
//如果BLE处于启用状态,则应移至“扫描设备”页面
否则{
Navigator.pushandremove直到(
上下文
材料路线(
生成器:(上下文){
返回BluetoothScanningDevices();
},
),
(路线)=>错误,
);
}
});
}
@凌驾
小部件构建(构建上下文){
Size Size=MediaQuery.of(context).Size;
返回脚手架(
appBar:appBar(
背景颜色:常量颜色(0xffE5E0A1),
海拔:0,
标题:对,
标题:正文(
“连接频带”,
样式:TextStyle(
字体大小:15.0,
颜色:颜色,黑色,
fontFamily:“蒙特塞拉特”,
fontWeight:fontWeight.normal,
),
),
领先:IconButton(
图标:图标(
Icons.arrow_back,
颜色:颜色,黑色,
),
已按下:(){
导航器。推(
上下文
材料路线(
生成器:(上下文){
返回BluetoothConnectBand();
},
),
);
},
),
行动:[
填充物(
填充:仅限边缘设置(右侧:5.0),
孩子:扁平按钮(
已按下:(){
showModalBottomSheet(
形状:圆形矩形边框(
borderRadius:仅限borderRadius(
右上角:半径。圆形(15),
左上:半径。圆形(15),
),
),
上下文:上下文,
builder:(builder)=>bottomSheet());
},
子:文本(
“搜索”,
样式:TextStyle(
字体大小:15.0,
颜色:颜色,黑色,
fontWeight:fontWeight.normal,
fontFamily:“蒙特塞拉特”,
),
),
),
)
],
),
正文:专栏(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
高度:size.height*0.4,
宽度:size.width,
颜色:常量颜色(0xffE5E0A1),
子:Image.asset(
“assets/images/bluetooth.png”,
),
),
],
),
);
}
小部件底页(){
打印(“底页”);
返回容器(
填充:边缘组。对称(垂直:15.0),
高度:150.0,
子:列(
儿童:[
正文(
“\nPecare想要打开蓝牙”,
样式:TextStyle(
颜色:颜色,黑色,
fontFamily:“蒙特塞拉特”,
fontWeight:fontWeight.w400,
字体大小:12.0,
),
textAlign:textAlign.center,
),
大小盒子(
身高:30.0,
),
划船(
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
钮扣(
身高:40.0,
最小宽度:150.0,
孩子:扁平按钮(
形状:圆形矩形边框(
边界半径:边界半径。圆形(28),
),
颜色:常量颜色(0xffE5E0A1),
已按下:(){
导航器。推(
上下文
材料路线(
生成器:(上下文){
返回BluetoothAccessDenied();
},
),
);
},
子:文本(
“否认”,
样式:TextStyle(
字体大小:14.0,
fontFamily:“蒙特塞拉特”,
颜色:颜色,黑色,
fontWeight:fontWeight.w700),
),
),
),
钮扣(
身高:40.0,
最小宽度:150.0,
孩子:扁平按钮(
形状:圆形矩形边框(
borderRadius:borderRadius.ci
import 'package:epicare/BluetoothAccessDenied.dart';
import 'package:epicare/BluetoothConnectBand.dart';
import 'package:epicare/BluetoothScanningDevices.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';

class BluetoothAllowScreen extends StatefulWidget {
  @override
  _BluetoothAllowScreenState createState() => _BluetoothAllowScreenState();
}

class _BluetoothAllowScreenState extends State<BluetoothAllowScreen> {
  FlutterBlue flutterBlue = FlutterBlue.instance;
  bool isBleOn;

  //Initialisation and listening to device state
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //checks bluetooth current state
    FlutterBlue.instance.state.listen((state) {
      if (state == BluetoothState.on) {
        print("Bluetooth is on");
        isBleOn = true;
        //Alert user to turn on bluetooth.
      } else if (state == BluetoothState.off) {
        print("Bluetooth is off");
        isBleOn = false;
      }
      print(isBleOn);
      //asking to turn on BLE by showing bottom sheet
      if (isBleOn == false) {
        print("Requesting BLE to turn on");
        bottomSheet();
      }
      //if BLE is on then it should move to scanning devices page
      else {
        Navigator.pushAndRemoveUntil(
          context,
          MaterialPageRoute(
            builder: (context) {
              return BluetoothScanningDevices();
            },
          ),
          (route) => false,
        );
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: const Color(0xffE5E0A1),
        elevation: 0,
        centerTitle: true,
        title: Text(
          " Connect Band",
          style: TextStyle(
            fontSize: 15.0,
            color: Colors.black,
            fontFamily: 'Montserrat',
            fontWeight: FontWeight.normal,
          ),
        ),
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: Colors.black,
          ),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) {
                  return BluetoothConnectBand();
                },
              ),
            );
          },
        ),
        actions: [
          Padding(
            padding: EdgeInsets.only(right: 5.0),
            child: FlatButton(
              onPressed: () {
                showModalBottomSheet(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                        topRight: Radius.circular(15),
                        topLeft: Radius.circular(15),
                      ),
                    ),
                    context: context,
                    builder: (builder) => bottomSheet());
              },
              child: Text(
                "Search",
                style: TextStyle(
                  fontSize: 15.0,
                  color: Colors.black,
                  fontWeight: FontWeight.normal,
                  fontFamily: 'Montserrat',
                ),
              ),
            ),
          )
        ],
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: size.height * 0.4,
            width: size.width,
            color: const Color(0xffE5E0A1),
            child: Image.asset(
              'assets/images/bluetooth.png',
            ),
          ),
        ],
      ),
    );
  }

  Widget bottomSheet() {
    print("BottomSheet");
    return Container(
      padding: EdgeInsets.symmetric(vertical: 15.0),
      height: 150.0,
      child: Column(
        children: [
          Text(
            "\nEpicare wants to turn on Bluetooth",
            style: TextStyle(
              color: Colors.black,
              fontFamily: 'Montserrat',
              fontWeight: FontWeight.w400,
              fontSize: 12.0,
            ),
            textAlign: TextAlign.center,
          ),
          SizedBox(
            height: 30.0,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              ButtonTheme(
                height: 40.0,
                minWidth: 150.0,
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(28),
                  ),
                  color: const Color(0xffE5E0A1),
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) {
                          return BluetoothAccessDenied();
                        },
                      ),
                    );
                  },
                  child: Text(
                    "Deny",
                    style: TextStyle(
                        fontSize: 14.0,
                        fontFamily: 'Montserrat',
                        color: Colors.black,
                        fontWeight: FontWeight.w700),
                  ),
                ),
              ),
              ButtonTheme(
                height: 40.0,
                minWidth: 150.0,
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(28),
                  ),
                  color: Colors.black,
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context){
                          return BluetoothScanningDevices();
                        },
                      ),
                    );
                  },
                  child: Text(
                    "Allow",
                    style: TextStyle(
                      fontSize: 14.0,
                      fontFamily: 'Montserrat',
                      color: const Color(0xffd4d411),
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }
}