【Flutter】Dart乱写笔记(个人笔记)

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;

// void main() => runApp(MyApp());
void main() {
  // print(1111);
  var a = 1;
  int b = 10;
  String c = "hi";
  dynamic d = 1;
  final FinalValue = 10;
  const Nae = 20;
  dynamic aa = 1;
  aa = 0.1;
  var aac = "13";
  var canP = true;
  var array = [1,2,3,4];
  List<int> array2 = [1,2,3,4];
  List<String> array3 = ["1","2"];
  var dic = new Map();
  dic["name"] = "张三";
  dic["age"] = 20;
  dic["clothe"] = ["1","2"];
  // print("dic = $dic, ${dic["name"]}");
  dic['name'] = 1;
  // print("dic = $dic, ${dic["name"]}");
  // print("isMap = ${dic is Map}");
  // print(add3(101, 20));
  // tall2(drug: "222");
  // {type name}
  // {name: type}
  // tall();
  // print(haveValue2(1));

  List<int> earchList = [1,2,3];
  earchList.forEach(foreach);
  var f1 = foreach;
  var f2 = foreach;
  var f3 = foreach;
  num bbbbbbbbbb, ccccccc;
  bbbbbbbbbb = 1;
  ccccccc = 2;
  // var f4 = (int a) => print("a=$a");

  // f1(10);
  // f4(20);
  // test((param) {
  //   print(param);
  // });

  // var me = new Person("123", 20);
  // me..eat()..sleep()..study();
  // me.eat();
  // var he = new Person.create();
  // var m = new GreateMan(10, 20, 30);

  // print(m.lastM);
  // m.lastM = 1;
  // print(m.lastM);
  var stu = new Student(1, 2);
  var stu1 = new Student(1, 2);
  stu = stu1 + stu;
  print(stu.x);
  stu.sleep();

  var ccc = LVColor.red;
  String aaaa = "132312";
  // print(getNetDataz());
}
Future<String> getNetDataz() async{
  http.Response res = await http.get("http://www.jianshu.com/p/06aebcad0543");
  print(res);
  return "res.body";
}

class GoodStudent = Student with A;

class A {

}

abstract class Dear {
  void eat();
  void sleep() {
    print("sleep");
  }
}

enum LVColor {
  red, green, blue
}

class Student extends Dear {

  num x, y;
  Student(this.x, this.y);
  Student operator +(Student v) => new Student(x + v.x, y + v.y);
  Student operator -(Student v) => new Student(x - v.x, y - v.y);


  @override
  void eat() {
    print("eat");
  }
}

class GreateMan {
  num myMoney, width, height;
  GreateMan(this.myMoney, this.width, this.height);
  num get lastM {
    return width + height;
  }
  set lastM(num value) => width = value + height;
  num get aaaa {
    print(111111);
    return 1111;
  }
  // GreateMan.create() : super.create() {
  //   print("gregeman = ${name}");
  // }
}

class Rectangle {
  num myMoney, top, width, height;

  // 构造方法传入left, top, width, height几个参数
  Rectangle(this.myMoney, this.top, this.width, this.height);

  // right, bottom两个成员变量提供getter/setter方法
  num get right => myMoney + width;
  set right(num value) => myMoney = value - width;
  // num get bottom => top + height;
  // set bottom(num value) => top = value - height;
}



class Person{
  String name;
  int age;
  var aaa = 10;

  Person.create() {
    // name = "账务";
    age = 20;
    var aaaaa = name;
  }

  // Person(this.name, this.age);
  eat() {
    print("吃饭");
  }
  sleep() {
    print("睡觉");
  }
  study() {
    print("打豆豆");
  }
}

test(Function callback){
  callback("张三");
}

foreach(int a) {
  print(a);
}

haveValue3(int a, int b, {String c}) {
  return a + b;
}

int haveValue2(int a, [int b = 10]){
  b = 20;
  return a + b;
}

int haveValue({int a, int b = 10}) {
  b = 30;
  return a + b;
}

tall2({drug: String}) {
  print(drug);
}

tall({String drug}) {
  print(drug);
}

int add(int a, int b ) {
  return a + b;
}

add2(int a, int c) {
  return a + c;
}

add3(a, b) => a + b;


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(builder: buildScaffold),
    );
  }
}

///创建一个widget
Widget buildScaffold(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text("第一个页面"),),
      body: Center(
        child: FlatButton(
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context)=>SecondPage()));
              // print(111);
            },
            child: Text("跳转")),
      ),
  ); //Scaffo
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("我是张三")),
    );
  }
}




class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // _counter++;
      Navigator.of(context).push(
          MaterialPageRoute(builder: (context) => NextHomePage(title: "LVDemo")));
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
    Navigator.of(context).push(
    MaterialPageRoute(builder: (context) => SecondPage()));
    },
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}


class NextHomePage extends StatefulWidget {
  NextHomePage({Key key, this.title}) : super(key: key);
  final String title;
  _NextHomePageState createState() => _NextHomePageState();
}

class _NextHomePageState extends State<NextHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值