/*
 * @Author: XianKaiQun
 * @Date: 2020-09-09 16:43:04
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-06 10:01:47
 * @Description: 
 */

import 'package:extended_image/extended_image.dart';
import 'package:face_package/src/assets.gen.dart';
import 'package:face_package/src/view_models/private_edit_store.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'components/photo.dart';

///人脸编辑
class EditPage extends StatelessWidget {
  const EditPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) => PrivateEditStore(context, providerContext),
      child: _PageView(),
      lazy: false,
    );
  }
}

class _PageView extends StatelessWidget {
  const _PageView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateEditStore>(context);
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('人脸编辑',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        slivers: [
          _PhotoComponent().nestSliverToBoxAdapter(),
          Wisdom.row(
            padding: EdgeInsets.symmetric(horizontal: 15.pt),
            children: [
              WButton(
                onPressed: () => store.picker(),
                height: 44.pt,
                color: Colors.transparent,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25.pt),
                  side: BorderSide(color: colorScheme.primary),
                ),
                textColor: colorScheme.primary,
                child: Text(
                  store.source == WImageSource.camera ? '重新拍照' : '重新选择',
                ),
              ),
              SizedBox(width: 15.pt),
              WButton(
                height: 44.pt,
                onPressed: () => store.upload(),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25.pt),
                ),
                child: Text('确认'),
              ).nestExpanded(),
            ],
          ).nestSliverToBoxAdapter(),
        ],
      ),
    );
  }
}
