/// loadBuffer方法用于加载图片数据并返回ImageStreamCompleter对象。 @override ImageStreamCompleter loadBuffer( image_provider.ExtendedNetworkImageProvider key, DecoderBufferCallback decode) { // Ownership of this controller is handed off to [_loadAsync]; it is that // method's responsibility to close the controller's stream when the image // has been loaded or an error is thrown. final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>();
classUser{ // 成员变量写法1: String name; int age; String gender; // 成员变量写法2:使用getter/setter声明的成员变量 Stringget uid => "24210853532539238"; set right(String uid) => left = value - width; // 通过创建一个与其类同名的函数来声明构造函数。如果您未声明构造函数,则会为您提供默认构造函数。默认构造函数没有参数,并在超类中调用无参数构造函数。 // 构造方法写法1:跟类名相同的构造方法 User(this.name, this.age, this.gender); // 构造方法写法2:命名的构造方法 User.defaultUser() { name = "dvlp"; age = 20; } // 成员方法写法1:有方法体(是非抽象方法) sayHello() { print("hello, this is $name, I am $age years old, I am a $gender"); } // 成员方法写法2:没有方法体(是抽象方法,需要子类去实现) void doSomething(); }
// right, bottom两个成员变量提供getter/setter方法 numget right => left + width; set right(num value) => left = value - width; numget bottom => top + height; set bottom(num value) => top = value - height; }
2、类的使用
1 2 3 4 5 6 7 8 9
main() { var user1 = new Person("zhangsan", 20, "male"); user.age = 30; user.gender = "female"; user.sayHello(); var user2 = new Person.defaultUser() }
classTest{ // 除非你重写noSuchMethod,否则使用不存在的成员会导致NoSuchMethodError // Unless you override noSuchMethod, using a // non-existent member results in a NoSuchMethodError. @override void noSuchMethod(Invocation invocation) { print('You tried to use a non-existent member: ' + '${invocation.memberName}'); } }
if [[ -z $2 ]] then echo 'Error:参数数量过少,请重新输入' exit_script fi if [[ -n $3 ]] then echo 'Error:参数数量过多,请重新输入' exit_script fi if [ -z ${xcarchive_file_path} ] \ || [ -z ${APPENVIRONMENT} ]; then echo 'Error:上述2个参数都不能为空' echo '请重新执行:sh base_exportArchive.sh ${xcarchive_file_path} ${APPENVIRONMENT}' exit_script fi
AssertExists() { if [[ ! -e "$1" ]]; then if [[ -h "$1" ]]; then EchoError "The path $1 is a symlink to a path that does not exist" else EchoError "The path $1 does not exist" fi exit -1 fi return 0 }
其他表达式:
表达式
含义
-r filename
如果 filename可读,则为真
-w filename
如果 filename可写,则为真
-x filename
如果 filename可执行,则为真
-s filename
如果文件长度不为0,则为真
filename1 -nt filename2
如果 filename1比 filename2新,则为真。
filename1 -ot filename2
如果 filename1比 filename2旧,则为真。
3、对字符串str的判断
表达式
含义
if [ str1 = str2 ]
当两个串有相同内容、长度时为真
if [ str1 != str2 ]
当串str1和str2不等时为真
if [ -n str1 ]
当串的长度大于0时为真(串非空)
if [ -z str1 ]
当串的长度为0时为真(空串)
if [ str1 ]
当串str1为非空时为真
shell 中利用 -n 来判定字符串非空。
使用示例:
1 2 3 4 5 6 7 8 9
RunCommand() { if [[ -n "$VERBOSE_SCRIPT_LOGGING" ]]; then echo "♦ $*" fi "$@" return $? } # 如果$VERBOSE_SCRIPT_LOGGING值不为空,则通过"$*"打印传递给脚本或函数的所有参数(将所有的参数作为一个整体输出),如果为空,则通过"$@"传递给脚本或函数的所有参数(将所有的参数依次分开输出),并通过$?返回上个命令的退出状态,或函数的返回值。