Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:core
dart:core
description

dart:core library

Built-in types, collections,and other core functionality for every Dart program.

This library is automatically imported.

Some classes in this library,such asString andnum,support Dart's built-in data types.Other classes, such asList andMap, provide data structuresfor managing collections of objects.And still other classes represent commonly used types of datasuch as URIs, dates and times, and errors.

Numbers and booleans

int anddouble provide support for Dart's built-in numerical data types:integers and double-precision floating point numbers, respectively.An object of typebool is either true or false.Variables of these types can be constructed from literals:

int meaningOfLife = 42;double valueOfPi  = 3.141592;bool visible      = true;

Strings and regular expressions

AString is immutable and represents a sequence of characters.

String shakespeareQuote = "All the world's a stage, ...";

StringBuffer provides a way to construct strings efficiently.

var moreShakespeare = StringBuffer();moreShakespeare.write('And all the men and women ');moreShakespeare.write('merely players; ...');

TheString andStringBuffer classes implement string splitting,concatenation, and other string manipulation features.

bool isPalindrome(String text) => text == text.split('').reversed.join();

RegExp implements Dart regular expressions,which provide a grammar for matching patterns within text.For example, here's a regular expression that matchesa substring containing one or more digits:

var numbers = RegExp(r'\d+');

Dart regular expressions have the same syntax and semantics asJavaScript regular expressions. Seeecma-international.org/ecma-262/5.1/#sec-15.10for the specification of JavaScript regular expressions.

Collections

Thedart:core library provides basic collections,such asList,Map, andSet.

AList is an ordered collection of objects, with a length.Lists are sometimes called arrays.Use aList when you need to access objects by index.

var superheroes = ['Batman', 'Superman', 'Harry Potter'];

ASet is an unordered collection of unique objects.You cannot get an item efficiently by index (position).Adding an element which is already in the set, has no effect.

var villains = {'Joker'};print(villains.length); // 1villains.addAll(['Joker', 'Lex Luthor', 'Voldemort']);print(villains.length); // 3

AMap is an unordered collection of key-value pairs,where each key can only occur once.Maps are sometimes called associative arrays becausemaps associate a key to some value for easy retrieval.Use aMap when you need to access objectsby a unique identifier.

var sidekicks = {'Batman': 'Robin',                 'Superman': 'Lois Lane',                 'Harry Potter': 'Ron and Hermione'};

In addition to these classes,dart:core containsIterable,an interface that defines functionalitycommon in collections of objects.Examples include the abilityto run a function on each element in the collection,to apply a test to each element,to retrieve an object, and to determine the number of elements.

Iterable is implemented byList andSet,and used byMap for its keys and values.

For other kinds of collections, check out thedart:collection library.

Date and time

UseDateTime to represent a point in timeandDuration to represent a span of time.

You can createDateTime objects with constructorsor by parsing a correctly formatted string.

var now = DateTime.now();var berlinWallFell = DateTime(1989, 11, 9);var moonLanding = DateTime.parse("1969-07-20");

Create aDuration object by specifying the individual time units.

var timeRemaining = const Duration(hours: 56, minutes: 14);

In addition toDateTime andDuration,dart:core contains theStopwatch class for measuring elapsed time.

Uri

AUri object represents a uniform resource identifier,which identifies a resource, for example on the web.

var dartlang = Uri.parse('http://dartlang.org/');

Errors

TheError class represents the occurrence of an errorduring runtime.Subclasses of this class represent specific kinds of errors.

Other documentation

For more information about how to use the built-in types, refer toBuilt-in TypesinA tour of the Dart language.

Also, seedart:core - numbers, collections, strings, and morefor more coverage of types in this library.

TheDart Language Specificationprovides technical details.

Classes

BigInt
An arbitrarily large integer value.
bool
The reserved wordstrue andfalse denote objects that are the only twoinstances of this class.
Comparable<T>
Interface used by types that have an intrinsic ordering.
DateTime
An instant in time, such as July 20, 1969, 8:18pm GMT.
Deprecated
The annotation@Deprecated('migration') marks a feature as deprecated.
double
A double-precision floating point number.
Duration
A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
Enum
An enumerated value.
Expando<T extendsObject>
AnExpando allows adding new properties to objects.
Finalizer<T>
A finalizer which can be attached to Dart objects.
Function
A function value.
Future<T>
The result of an asynchronous computation.
int
An integer number.
Invocation
Representation of the invocation of a member on an object.
Iterable<E>
A collection of values, or "elements", that can be accessed sequentially.
Iterator<E>
An interface for getting items, one at a time, from an object.
List<E>
An indexable collection of objects with a length.
Map<K,V>
A collection of key/value pairs, from which you retrieve a valueusing its associated key.
MapEntry<K,V>
A key/value pair representing an entry in aMap.
Match
A result from searching within a string.
Null
The reserved wordnull denotes an object that is the sole instance ofthis class.
num
An integer or floating-point number.
Object
The base class for all Dart objects exceptnull.
Pattern
An interface for basic searches within strings.
pragma
A hint to tools.
Record
A record value.
RegExp
A regular expression pattern.
RegExpMatch
A regular expression match.
RuneIterator
Iterator for reading runes (integer Unicode code points) of a Dart string.
Runes
The runes (integer Unicode code points) of aString.
Set<E>
A collection of objects in which each object can occur only once.
Sink<T>
A generic destination for data.
StackTrace
An interface implemented by all stack trace objects.
Stopwatch
A stopwatch which measures time while it's running.
Stream<T>
A source of asynchronous data events.
String
A sequence of UTF-16 code units.
StringBuffer
A class for concatenating strings efficiently.
StringSink
Symbol
Opaque name used by mirrors, invocations andFunction.apply.
Type
Runtime representation of a type.
Uri
A parsed URI, such as a URL.
UriData
A way to access the structure of adata: URI.
WeakReference<T extendsObject>
A weak reference to a Dart object.

Extensions

DateTimeCopyWith onDateTime
AddscopyWith method toDateTime objects.
EnumByName onIterable<T>
Access enum values by name.
EnumName onEnum
Access to the name of an enum value.
FutureExtensions onFuture<T>
Convenience methods on futures.
FutureIterable onIterable<Future<T>>
FutureRecord2 on (Future<T1>,Future<T2>)
Parallel operations on a record of futures.
FutureRecord3 on (Future<T1>,Future<T2>,Future<T3>)
Parallel operations on a record of futures.
FutureRecord4 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>)
Parallel operations on a record of futures.
FutureRecord5 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>,Future<T5>)
Parallel operations on a record of futures.
FutureRecord6 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>,Future<T5>,Future<T6>)
Parallel operations on a record of futures.
FutureRecord7 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>,Future<T5>,Future<T6>,Future<T7>)
Parallel operations on a record of futures.
FutureRecord8 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>,Future<T5>,Future<T6>,Future<T7>,Future<T8>)
Parallel operations on a record of futures.
FutureRecord9 on (Future<T1>,Future<T2>,Future<T3>,Future<T4>,Future<T5>,Future<T6>,Future<T7>,Future<T8>,Future<T9>)
Parallel operations on a record of futures.
IterableExtensions onIterable<T>
Operations on iterables.
NullableIterableExtensions onIterable<T?>
Operations on iterables with nullable elements.

Constants

deprecated→ constDeprecated
Marks a feature asDeprecated until the next release.
override→ constObject
Annotation on instance members which override an interface member.

Functions

identical(Object?a,Object?b)bool
Check whether two object references are to the same object.
identityHashCode(Object?object)int
The identity hash code ofobject.
print(Object?object)→ void
Prints an object to the console.

Typedefs

Comparator<T>=int Function(Ta,Tb)
The signature of a generic comparison function.

Exceptions / Errors

ArgumentError
Error thrown when a function is passed an unacceptable argument.
AssertionError
Error thrown by the runtime system when an assert statement fails.
ConcurrentModificationError
Error occurring when a collection is modified during iteration.
Error
Error objects thrown in the case of a program failure.
Exception
A marker interface implemented by all core library exceptions.
FormatException
Exception thrown when a string or some other data does not have an expectedformat and cannot be parsed or processed.
IndexError
A specializedRangeError used when an index is not in the range0..indexable.length-1.
IntegerDivisionByZeroException
NoSuchMethodError
Error thrown on an invalid function or method invocation.
OutOfMemoryError
Error that the platform can use in case of memory shortage.
ParallelWaitError<V,E>
Error thrown when waiting for multiple futures, when some have errors.
RangeError
Error thrown due to an argument value being outside an accepted range.
StackOverflowError
Error that the platform can use in case of stack overflow.
StateError
The operation was not allowed by the current state of the object.
TypeError
Error thrown by the runtime system when a dynamic type error happens.
UnimplementedError
Thrown by operations that have not been implemented yet.
UnsupportedError
The operation was not allowed by the object.
  1. Dart
  2. dart:core
DartSDK
  1. Libraries
  2. Core
  3. dart:async
  4. dart:collection
  5. dart:convert
  6. dart:core
  7. dart:developer
  8. dart:math
  9. dart:typed_data
  10. VM
  11. dart:ffi
  12. dart:io
  13. dart:isolate
  14. dart:mirrors
  15. Web
  16. package:webopen_in_new
  17. dart:js_interop
  18. dart:js_interop_unsafe
  19. Web (Legacy)
  20. dart:html
  21. dart:indexed_db
  22. dart:js
  23. dart:js_util
  24. dart:svg
  25. dart:web_audio
  26. dart:web_gl
dart:core library

[8]ページ先頭

©2009-2025 Movatter.jp