【Flutter】Dart 数据类型 布尔类型 ( 布尔类型定义 | 逻辑运算 )



I . bool 类型定义



bool bool_1 = true;
bool bool_0 = false;
//打印结果 : bool_1 : true , bool_0 : false
print("bool_1 : $bool_1 , bool_0 : $bool_0");


II . bool 类型逻辑运算



// 1 . 逻辑或运算
bool bool_2 = bool_0 || bool_1;
// 2 . 逻辑与运算
bool bool_3 = bool_0 && bool_1;
//打印结果 : bool_2 : true , bool_3 : false
print("bool_2 : $bool_2 , bool_3 : $bool_3");


III . 代码示例



import 'package:flutter/material.dart';

class DartType_Bool extends StatefulWidget {
  @override
  _DartType_BoolState createState() => _DartType_BoolState();
}

class _DartType_BoolState extends State<DartType_Bool> {
  @override
  Widget build(BuildContext context) {

    //调用 Demo 示例方法
    _boolDemo();

    return Container(child: Text('布尔数据类型'),);
  }

  /**
   * 布尔类型代码示例
   */
  _boolDemo(){


    // I . 布尔类型定义


    bool bool_1 = true;
    bool bool_0 = false;

    //打印结果 : bool_1 : true , bool_0 : false
    print("bool_1 : $bool_1 , bool_0 : $bool_0");


    // II . 逻辑运算


    // 1 . 逻辑或运算
    bool bool_2 = bool_0 || bool_1;

    // 2 . 逻辑与运算
    bool bool_3 = bool_0 && bool_1;

    //打印结果 : bool_2 : true , bool_3 : false
    print("bool_2 : $bool_2 , bool_3 : $bool_3");


  }

}


执行结果 :

bool_1 : true , bool_0 : false
bool_2 : true , bool_3 : false
发布了307 篇原创文章 · 获赞 1043 · 访问量 170万+

猜你喜欢

转载自blog.csdn.net/han1202012/article/details/104930060