/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2022-01-19 16:44:35
 * @LastEditTime: 2023-04-03 15:04:09
 * @Description  : Do not edit
 */
import 'package:community_package/src/components/list_item.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/private_community_index.model.dart';

class CommunityIndexPage extends StatelessWidget {
  const CommunityIndexPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateCommunityIndexStore(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> {
  @override
  Widget build(BuildContext context) {
    final store =
        Provider.of<PrivateCommunityIndexStore>(context, listen: true);
    var list = store.communityList;
    final colorScheme = WTheme.of(context).colorScheme;
    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: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.min,
        children: [
          Wisdom.row(
              color: Color(0xFFFFFFFF),
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Expanded(
                  child: WSearch(
                    hintText: '输入小区名称搜索',
                    onSubmitted: (value) => store.onNameInput(value),
                    onCancel: () => store.onNameInput(''),
                    moonlight: false,
                    padding: EdgeInsets.symmetric(vertical: 10.pt),
                    isDark: true,
                  ),
                )
              ]),
          Expanded(
            child: WisScrollView(
              key: store.scorllViewListKey,
              onInit: () => store.getCommunityList(isLoad: false),
              slivers: <Widget>[
                WisSliverList.childBuilder(
                  childCount: list.length,
                  builder: (context, index) {
                    final item = list[index];
                    return ListItem(item: item, isDetail: false);
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
