美文网首页
10-Dart语言基础-库

10-Dart语言基础-库

作者: Mark_Liu_JS | 来源:发表于2021-11-06 10:25 被阅读0次

1.库的操作

  • main.dart
import 'dart:io';
import 'function.dart';
// import 'package:flutter/material.dart';
import 'function.dart' as HYFoundation;
import 'unitl.dart';
import 'user.dart' hide printInfo;

export 'unitl.dart';

import 'package:http/http.dart' as http;

void main(List<String> args) {
  // 1. 在Dart中的库的使用import关键字引入
  // 2. Dart中的库主要有三种:
  //    1.系统内置库 如 io, math, html等
  //    2.我们自定义的文件 如 funciton.dart, 使用相对路径导入
  //    3.pub包管理系统中的库, 如 flutter中的库

  // 3. 库的别名:
  // 可以使用as关键字来指定库的前缀

  // HYFoundation.show();
  HYFoundation.Person person = HYFoundation.Person();
  person.hello();

  Person p = Person();
  p.hello();

  // 4.显示与隐藏部分
  // 只导入需要的部分,使用show关键字
  // 隐藏不需要的部分,使用hide关键字

  // printInfo(); // 隐藏后报错
  showInfo();

  // 5. library 可以创建一个库, 可以给库起一个名称。
  // 将每一个dart文件作为库文件,使用export关键字在某个库文件中单独导入.
  work();
  study();

  // 6.Flutter中引入第三方库
  //  1、在项目根目录新建一个pubspec.yaml
  //  2、在pubspec.yaml文件 然后配置名称 、描述、依赖等信息
  //  3、然后运行 pub get 获取包下载到本地
  //  4、项目中引入库 import 'package:XXXX'

  // pub仓库 https://pub.dev/
  // http.Client;
}

class Person {
  void hello() {
    print("Main中的Person");
  }
}

  • function.dart
void show() {
  print('我是show函数');
}

class Person {
  void hello() {
    print('我是Person类');
  }
}

class Animal {}

  • user.dart
void showInfo() {
  print('showInfo =====');
}

void printInfo() {
  print('printInfo =====');
}

  • until.dart
library HYUnitl;

void work() {
  print('工作');
}

void study() {
  print('学习');
}

  • subspec.yaml
name: hello
description: 一个demo

environment:
  sdk: ">=2.12.0 <3.0.0"
  
dependencies:
  http: ^0.13.4

相关文章

  • 10-Dart语言基础-库

    1.库的操作 main.dart function.dart user.dart until.dart subsp...

  • python数据可视化--matplotlib库介绍

    matplotlib库简介 matplotlib库是python数据可视化最基础的一个库,它的语言风格与MATLA...

  • 数据库系列(1/21)

    1.数据库的基础知识2.数据库的基础操作3.数据库的事务4.SQL语言5.SQL-Oracle6.SQL-MySQ...

  • Gobject C语言库 I 对象与它的类定义

    Gobject 时一个为C语言提供面向对象编程的基础库。 作为一门基础语言,C语言在操作系统层面有着绝对统治的应用...

  • Objective-c 快速指南

    Objective-c是c语言的超集, 就是objective-c是基础C语言的基础上,增加了扩展库,并在gcc上...

  • Nodejs技术栈梳理

    Nodejs语言 基础知识 fs net http crypto process util 框架和库 expres...

  • 1 SQL基础教程

    1 SQL基础 1.1 SQL 简介 SQL(结构化查询语言)是用于访问和操作数据库中的数据的标准数据库编程语言。...

  • Python介绍

    python特点 高级语言 解释型语言,与编译型语言对应 优点 简单易用 有非常完善的基础代码库,覆盖了网络、文件...

  • 第6次课-Shell脚本语言-第6讲

    内容一:Shell脚本->数据库SQL语句->基础(回顾) 内容二:Shell脚本语言->数据库操作->在Shel...

  • 数据库(5) | MySQL SQL 语言查询

    SQL语言基础 本章,我们将会重点探讨SQL语言基础,学习用SQL进行数据库的基本数据查询操作。另外请注意本章的S...

网友评论

      本文标题:10-Dart语言基础-库

      本文链接:https://www.haomeiwen.com/subject/vvtjzltx.html