第3章Dart语言简述-Getters和Setters

防采集标记:亢少军老师的课程和资料


class Rectangle {
  num left;
  num top;
  num width;
  num height;

  Rectangle(this.left, this.top, this.width, this.height);

  //获取right值
  num get right         => left + width;

  //设置right值 同时left也发生变化
  set right(num value)  => left = value - width;

  //获取bottom值
  num get bottom        => top + height;

  //设置bottom值 同时top也发生变化
  set bottom(num value) => top = value - height;
}

main() {
  var rect = new Rectangle(3, 4, 20, 15);

  print('left:'+rect.left.toString());
  print('right:'+rect.right.toString());
  rect.right = 30;
  print('更改right值为30');
  print('left:'+rect.left.toString());
  print('right:'+rect.right.toString());

  print('top:'+rect.top.toString());
  print('bottom:'+rect.bottom.toString());
  rect.bottom = 50;
  print('更改bottom值为50');
  print('top:'+rect.top.toString());
  print('bottom:'+rect.bottom.toString());
}




//import 'package:flutter/material.dart';
//void main() {
//  runApp(
//      new MaterialApp(
//        title: 'Container demo',
//        home: new ContainerDemo(),
//      )
//  );
//}
//
//
//
//
//
//
//class ContainerDemo extends StatelessWidget {
//  @override
//  Widget build(BuildContext context) {
//    // TODO: implement build
//    return new Center(
//
//      child: new Container(
//        width: 200.0,
//        height: 200.0,
//        decoration: new BoxDecoration(
//            color: Colors.white,
//            border: new Border.all(
//              color: Colors.green,
//              width: 8.0,
//            ),
//            borderRadius: const BorderRadius.all(const  Radius.circular(48.0))
//        ),
//        child: new Text(
//          'Flutter',
//          textAlign: TextAlign.center,
//        ),
//      ),
//    );
//  }
//}




@作者: 亢少军

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亢少军

致力于跨平台技术开发

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值