- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 555字
- 2021-07-09 18:56:20
Adding metadata
At the time of writing, some of the fullscreen APIs are marked as experimental in the Dart API documentation, and this is made clear in the documentation as well. By the time you read this, the fullscreen APIs should hopefully be stabilized and fully operational.
This is the normal process for new web browser features, which are eventually made stable. The adding of experimental APIs is likely to be a continuous process—it seems very unlikely that web browsers will ever be 100 percent complete! The onFullscreenChange
Dart API documentation reads:
Experimental ElementStream<Event> get onFullscreenChange Stream of fullscreenchange events handled by this Element.
The source code for this part of the dart:html
package has several annotations including the @experimental
marker:
/// Stream of `fullscreenchange` events handled by this [Element]. @DomName('Element.onwebkitfullscreenchange') @DocsEditable() // https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html @Experimental() ElementStream<Event> get onFullscreenChange => fullscreenChangeEvent.forElement(this);
Dart has a very flexible annotation system, and new systems can be created to add metadata to most of the components in Dart, such as classes, functions, and libraries. The pattern, as you probably already spotted, is used to start them with a @
sign followed by a call to the const
constructor or a reference to a compile-time constant variable.
Creating a custom annotation
Let's create our own Temporary
annotation that will mark classes as temporary to the design of the application and will allow a label to record which planned build the temporary classes are scheduled to be removed:
import 'dart:mirrors'; class Temporary { final String removalBuildLabel; const Temporary(this.removalBuildLabel); String toString() => removalBuildLabel; } @Temporary('Build1') class TempWidgetTxt {} @Temporary('Build2') class TempWidgetWithGFX {} void main() { ClassMirror classMirror1 = reflectClass(TempWidgetTxt); ClassMirror classMirror2 = reflectClass(TempWidgetWithGFX); List<InstanceMirror> metadata1 = classMirror1.metadata; print(metadata1.first.reflectee); List<InstanceMirror> metadata2 = classMirror2.metadata; print(metadata2.first.reflectee); }
The Temporary
constructor allows a label to be set. This field must be final
(a single-assignment variable or field) if this class is to be used as an annotation. The main function calls reflectClass
to obtain the details of the classes and then accesses this metadata and stores it in a list. The toString
method allows the metadata to be the output via print
:
Build1 Build2
Annotations are used extensively in the core Dart APIs, and in packages, they are used as the basis of frameworks, for example, web applications. They are not an obscure feature of the core SDK.
Translating the user interface text
My first ever professional software release did not involve any creation of code. It was a language update release for an existing package, and it was just as satisfying to mail out the CD-ROM (this was a while ago!) as something I had coded from scratch. Thankfully, it made me famous in Norway!
The translation of a software application is critical for its acceptance in some markets. This is even more true in the world of web applications. Dart has a package called intl
that is used to help bring your applications to a global audience.
The presenter
interface needs to be updated so that it displays the editor in French and Spanish. This will involve extracting the strings that we wish to use, obtaining translations, and integrating them back into the project.
The language will be selectable at runtime by user selection. The current OS interface language may not be the language that the user wishes to use the application in.
- 零基礎(chǔ)學(xué)Visual C++第3版
- Mastering ServiceStack
- Mastering Adobe Captivate 2017(Fourth Edition)
- PHP 7底層設(shè)計與源碼實現(xiàn)
- jQuery EasyUI網(wǎng)站開發(fā)實戰(zhàn)
- OpenCV 3和Qt5計算機(jī)視覺應(yīng)用開發(fā)
- Python爬蟲開發(fā)與項目實戰(zhàn)
- Python王者歸來
- 機(jī)械工程師Python編程:入門、實戰(zhàn)與進(jìn)階
- 名師講壇:Java微服務(wù)架構(gòu)實戰(zhàn)(SpringBoot+SpringCloud+Docker+RabbitMQ)
- PLC編程及應(yīng)用實戰(zhàn)
- C語言課程設(shè)計
- Highcharts Cookbook
- 時空數(shù)據(jù)建模及其應(yīng)用
- R Data Science Essentials