/*
 * @Author: XianKaiQun
 * @Date: 2020-04-21 16:06:13
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-02-02 15:32:17
 * @Descripttion:
 */
part of 'index.dart';

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

class _PageViewState extends State<_PageView> {
  @override
  void initState() {
    super.initState();
//第一帧后后触发且只会触发一次的事件,在这里面可以调用store了
// Future.microtask(() {
//store.xxx();
// });
  }

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    _Store store = Provider.of(context, listen: true);

    return Scaffold(
      appBar: WAppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        title: WisText(
          '切换小区',
          size: 19.pt,
          weight: FontWeight.w600,
          color: colorScheme.mainTitle,
        ),
      ),
      body: WisScrollView(
        onInit: () => store.getCommunitysList(),
        slivers: <Widget>[
          Wisdom(
            color: Colors.white,
            child: WSearch(
              hintText: '输入小区名称搜索',
              onSubmitted: (value) => store.onNameInput(value),
              onCancel: () => store.onNameInput(''),
              moonlight: false,
              isDark: true,
            ),
          ).asSliver(),
          WisCard(
            margin: EdgeInsets.all(15.pt),
            isSliver: true,
            child: Column(
              children: [
                for (var item in store.list)
                  Wisdom(
                    border: Border(
                      bottom: BorderSide(
                        width: 0.5,
                        color: colorScheme.divider,
                      ),
                    ),
                    margin: EdgeInsets.symmetric(horizontal: 15.pt),
                    padding: EdgeInsets.only(top: 15.pt),
                    onTap: item.id == store.currentCommunity?.id
                        ? null
                        : () => store.onPick(item),
                    child: Wisdom.row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      padding: EdgeInsets.only(bottom: 15.pt),
                      children: <Widget>[
                        Column(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            WisText(
                              item.name ?? '',
                              size: 16.pt,
                              color: colorScheme.mainTitle,
                              weight: FontWeight.w600,
                            ),
                            SizedBox(height: 5.pt),
                            WisText(
                              item.address ?? '',
                              size: 14.pt,
                              color: colorScheme.grey,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ).asFlexible(flex: 1),
                        if (item.id == store.currentCommunity?.id)
                          Image.asset(
                            'lib/assets/main/check_circle.png',
                            package: 'app_package',
                            width: 17.pt,
                          ).asFlexible(flex: 1),
                      ],
                    ),
                  ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
