/*
 * @Author: XianKaiQun
 * @Date: 2020-07-28 11:52:05
 * @LastEditors: WuXiangNan
 * @LastEditTime: 2021-07-06 10:16:01
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:qrcode_package/src/view_models/private_register_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

// part 'components/list.dart';
class RegisterPage extends StatelessWidget {
  const RegisterPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateRegisterStore(context, providerContext),
      child: _PageView(),
      lazy: false,
    );
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  PrivateRegisterStore get store => Provider.of(context, listen: false);

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateRegisterStore>(context);

    List list = [
      {
        'name': '保洁清洁',
        'image': 'lib/assets/bjqj.png',
        'ontap': () => Navigator.pushNamed(
              context,
              'qrcode/register_form',
              arguments: {
                'type': 'clean',
                'value': store.routingArgs['id'],
              },
            ),
      },
      {
        'name': '安保巡逻',
        'image': 'lib/assets/abxl.png',
        'ontap': () => Navigator.pushNamed(
              context,
              'qrcode/register_form',
              arguments: {
                'type': 'security',
                'value': store.routingArgs['id'],
              },
            ),
      },
      {
        'name': '设备实施',
        'image': 'lib/assets/sbss.png',
        'ontap': () => Navigator.pushNamed(
              context,
              'qrcode/register_form',
              arguments: {
                'type': 'implement',
                'value': store.routingArgs['id'],
              },
            ),
      },
    ];
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('${store.routingArgs['appBarTitle'] ?? '二维码登记'}',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        slivers: <Widget>[
          Wisdom.row(
            alignment: Alignment.centerLeft,
            height: 34.pt,
            color: colorScheme.warning.withOpacity(0.1),
            padding: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 7.pt),
            children: <Widget>[
              Text(
                '请选择二维码类型',
                style: TextStyle(
                  color: colorScheme.warning,
                ),
              ),
            ],
          ).asSliver(),
          WisSliverGrid(
            count: list.length,
            crossAxisCount: 2,
            builder: (_, i) {
              final item = list[i];
              return Wisdom.column(
                onTap: () => item['ontap'](),
                alignment: Alignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                border: Border(
                  right: BorderSide(width: 1.pt, color: colorScheme.divider),
                  bottom: BorderSide(width: 1.pt, color: colorScheme.divider),
                ),
                children: <Widget>[
                  Image.asset(
                    item['image'],
                    package: 'qrcode_package',
                    width: 80.pt,
                    height: 80.pt,
                  ),
                  Text(item['name']),
                ],
              );
            },
          ),
        ],
      ),
    );
  }
}
