import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';
import 'package:netrain_flutter_app/douwen/custom/BaseView.dart';
import 'package:netrain_flutter_app/douwen/custom/BaseViewModel.dart';

class Demo2 extends BaseView {

  Demo2() : super(BaseViewModel()) {
    builder = (context, value, child) => Container(
        child: Column(
          children: [
            Row(
              children: [
                _item("setNormal", () {
                  viewModel.setNormal();
                }),
                _item("setEmpty", () {
                  viewModel.setEmpty();
                }),
                _item("setError", () {
                  viewModel.setError();
                }),
              ],
            ),
            setReplaceView(Row(
              children: [
                ValueListenableBuilder(
                    valueListenable: viewModel.num,
                    builder: (context, value, child) =>
                        Text("点击了${viewModel.num.value}次")),
                ElevatedButton(
                    onPressed: () {
                      viewModel.click();
                    },
                    child: Text("点击"))
              ],
            )),
          ],
        )
    );
  }

  _item(String title, VoidCallback onPressed) {
    return Container(
      child: RaisedButton(
        onPressed: onPressed,
        child: Text(title),
      ),
    );
  }
}
