当前位置:网站首页>[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
2022-07-02 16:10:00 【Programmer community】
List of articles
- I . establish Dart file
- II . num / int / double Numeric type
- III . Number type correlation API
I . establish Dart file
establish Flutter application : This is created before Flutter application ;

establish Dart file : Right click on the lib -> New -> Dart File , Enter... In the pop-up dialog box Dart File name is enough ;


Use templates : Enter in file stful , choice New Stateful widge Templates , You can use this template ;


The completion code : The main codes are in Widget build(BuildContext context) { } Method implementation ;
import 'package:flutter/material.dart';class DartType_Number extends StatefulWidget {
@override _DartType_NumberState createState() => _DartType_NumberState();}class _DartType_NumberState extends State<DartType_Number> {
@override Widget build(BuildContext context) {
return Container(); }}II . num / int / double Numeric type
1 . num And int and double The relationship between :num It's the number type , It has two subclasses , int and double type ;
2 . num Type variable : It can be accepted that Integer variables , You can also accept floating-point variables ;
3 . num Examples of type usage :
/* num Numeric type Is the parent of numeric type num Two subclasses of : ① int , ② double num Type variables can be assigned Integer types , You can also assign values Floating point type */num num_1 = 1.0; // Accept floating point types num num_2 = 1; // Accept integer int int_1 = -1; //int Type can only accept integer types double double_1 = 3.14; //double Type can only accept floating-point types // Print the four values above print("num_1 : $num_1 num_2 : $num_2 int_1 : $int_1 double_1 : $double_1");4 . Execution results :
num_1 : 1.0 num_2 : 1 int_1 : -1 double_1 : 3.14III . Number type correlation API
1 . Find the absolute value : call num Of abs() Method , O the num The absolute value of the type ;
2 . Digital type conversion : call num Of toInt() , toDouble() , toString() And other methods can realize digital type conversion ;
3 . complete Dart Component code example :
import 'package:flutter/material.dart';class DartType_Number extends StatefulWidget {
@override _DartType_NumberState createState() => _DartType_NumberState();}class _DartType_NumberState extends State<DartType_Number> {
@override Widget build(BuildContext context) {
/* num Numeric type Is the parent of numeric type num Two subclasses of : ① int , ② double num Type variables can be assigned Integer types , You can also assign values Floating point type */ num num_1 = 1.0; // Accept floating point types num num_2 = 1; // Accept integer int int_1 = -1; //int Type can only accept integer types double double_1 = 3.14; //double Type can only accept floating-point types // Print the four values above print("num_1 : $num_1 num_2 : $num_2 int_1 : $int_1 double_1 : $double_1"); /* Number type common API 1 . Find the absolute value : call num Of abs() Method , O the num The absolute value of the type 2 . Digital type conversion : call num Of toInt() , toDouble() , toString() And other methods can realize digital type conversion */ print("$int_1 The absolute value : ${int_1.abs()}"); print("$int_1 To double : ${int_1.toDouble()}"); print("$double_1 To int : ${double_1.toInt()}"); return Container(child: Text(' Numeric type ')); }}4 . Execution results :
num_1 : 1.0 num_2 : 1 int_1 : -1 double_1 : 3.14-1 The absolute value : 1-1 To double : -1.03.14 To int : 3
边栏推荐
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
- Construction and business practice of Zhongke brain knowledge map platform
- 奥比中光 astra: Could not open “2bc5/[email protected]/6“: Failed to set USB interface
- 基于 Nebula Graph 构建百亿关系知识图谱实践
- 【小白聊云】中小企业容器化改造建议
- Write your own CPU Chapter 11 - learning notes
- 2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
- Summary of multithreading and thread synchronization knowledge
- 智联招聘的基于 Nebula Graph 的推荐实践分享
- HMS core machine learning service helps zaful users to shop conveniently
猜你喜欢

Armv8-a programming guide MMU (4)

The sea of stars hidden behind the nebula graph

Teach you how to build virtual machines locally and deploy microservices

Dimension table and fact table in data warehouse

中科大脑知识图谱平台建设及业务实践

通过两级网关设计来路由服务网格流量

Idea jar package conflict troubleshooting

HMS core machine learning service helps zaful users to shop conveniently

win10系统升级一段时间后,内存占用过高

IDEA中设置背景图片(超详细)
随机推荐
JS learning notes - data types
Leetcode -- number of palindromes
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
/Bin/ld: cannot find -lssl
Various entanglements between qvariant and Jason -- QT
原神2.6服务端下载以及搭建安装教程
Aike AI frontier promotion (7.2)
Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
The light of ideal never dies
day4
Dimension table and fact table in data warehouse
JS learning notes - first acquaintance
Vscode设置标签页多行显示
Group by的用法
Song of cactus - throwing stones to ask the way (2)
Introduction to Dynamic Planning II (5.647.62)
Leetcode --- longest public prefix
(Wanzi essence knowledge summary) basic knowledge of shell script programming
Pattern matching extraction of specific subgraphs in graphx graph Computing Practice