Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the characteristics of developing Dart language by Android

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly talks about "what are the characteristics of Android developing Dart language". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the characteristics of Android developing Dart language"?

Cascade cascade

Cascades (..,?) Allows you to perform a series of operations on the same object. This usually saves the step of creating temporary variables and allows you to write more fluent code.

Var paint = Paint (); paint.color = Colors.black;paint.strokeCap = StrokeCap.round;paint.strokeWidth = 5.0; block of code when optimizedvar paint = Paint ().. color = Colors.black.. strokeCap = StrokeCap.round.. strokeWidth = 5.0 strokeCap Abstract abstract class

Define a _ abstract abstract class (a class that cannot be instantiated) using the abstract modifier. Abstract classes are useful for defining interfaces, usually with some implementation.

/ / This class is declared abstract and thus// can't be instantiated.abstract class AbstractContainer {/ / Define constructors, fields, methods... Void updateChildren (); / / Abstract method.} Factory constructors factory builder

Use the factory keyword when implementing a constructor that does not always create a new instance of the class.

Class Logger {String name; Logger (this.name); factory Logger.fromJson (Map json) {return Logger (json ['name']. ToString ());} Named naming constructor

Use named constructors to implement multiple constructors for a class or provide additional clarity:

Class Points {final double x; final double y; / / unnamed constructor Points (this.x, this.y); / / Named constructor Points.origin (double XJI double y): X = x, y = y; / / Named constructor Points.destination (double XJI double y): X = x, y = y;} Mixins mixture

Mixin is a way to reuse class code in multiple class hierarchies.

To implement implement mixin, create a class that declares no constructor. Unless you want mixin to be used as a regular class, use the mixin keyword instead of the class.

To use mixin, use the with keyword followed by one or more mixin names.

To limit the types that can use mixin, use the on keyword to specify the desired superclass.

Class Musician {} / / creating a mixinmixin Feedback {void boo () {print ('boooing');} void clap () {print (' clapping');}} / only classes that extend or implement the Musician class//can use the mixin Songmixin Song on Musician {void play () {print ('- playing-');} void stop () {print ('.... stopping.') } / / To use a mixin, use the with keyword followed by one or more mixin namesclass PerformSong extends Musician with Feedback, Song {/ / Because PerformSong extends Musician, / / PerformSong can mixin Song void awesomeSong () {play (); clap ();} void badSong () {play (); boo ();}} void main () {PerformSong (). AwesomeSong (); PerformSong (). Stop (); PerformSong (). BadSong ();} Typedefs

The type alias marker is a concise way to refer to a type. It is commonly used to create custom types that are often used in projects.

Typedef IntList = List;List i1 = [1rect 2jue 3]; / / normal way.IntList i2 = [1meme 2jue 3]; / / Same thing but shorter and clearer.//type alias can have type parameterstypedef ListMapper = Map;Map M1 = {}; / / normal way.ListMapper m2 = {}; / / Same thing but shorter and clearer.Extension extension method

The extension approach introduced in Dart 2.7is a way to add functionality to existing libraries and code.

/ / extension to convert a string to a numberextension NumberParsing on String {int customParseInt () {return int.parse (this);} double customParseDouble () {return double.parse (this);}} void main () {/ / various ways to use the extension var d = '21'.customParseDouble (); print (d); vari = NumberParsing (' 20'). CustomParseInt (); print (I);}

Optional position parameter

Position parameters can be made optional by wrapping them in square brackets. The optional positional parameter is always the last in the function's argument list. Unless you provide another default value, their default value is null.

String joinWithCommas (int a, [int? B, int? C, int? D, int e = 100]) {var total ='$asides; if (b! = null) total ='$total,$b'; if (c! = null) total ='$total,$c'; if (d! = null) total ='$total,$d'; total ='$total,$e'; return total;} void main () {var result = joinWithCommas (1,2); print (result);} unawaited_futures

When you want to start a Future, the recommended method is to use unawaited

Otherwise, you won't execute it if you don't add async.

Import 'dart:async';Future doSomething () {return Future.delayed (Duration (seconds: 5));} void main () async {/ / the function is fired and awaited till completion await doSomething (); / / Explicitly-ignored / / The function is fired and forgotten unawaited (doSomething ());} so far, I believe you have a deeper understanding of "what are the characteristics of Android developing Dart language". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report