| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import 'dart:ui';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get_connect/http/src/utils/utils.dart';
- import 'package:head_image_cropper/head_image_cropper.dart';
- import 'package:link/view/component/link_btn.dart';
- import 'package:photo_view/photo_view.dart';
- import 'package:screenshot/screenshot.dart';
- import '../constants.dart';
- import '../utils/size_fit.dart';
- import 'component/top_container.dart';
- class EditAvatar extends StatefulWidget {
- Uint8List image;
- var callback;
- EditAvatar({Key? key, required this.image,required this.callback}) : super(key: key);
- @override
- State<EditAvatar> createState() => _EditAvatarState();
- }
- class _EditAvatarState extends State<EditAvatar> {
- var _controller = CropperController();
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- }
- clip() {
- _controller.outImage().then((image) async{
- var bytes = (await (image.toByteData(format: ImageByteFormat.png)))
- ?.buffer
- .asUint8List();
- widget.callback(bytes);
- Navigator.of(context).pop();
- });
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- double width = 300.px;
- double height = 300.px;
- double left = (MediaQuery.of(context).size.width - width) / 2.0;
- double top = (MediaQuery.of(context).size.height - width) / 2.0;
- return Material(
- color: kBgColor,
- child: TopContainer(
- child: Stack(
- children: [
- Container(
- padding: EdgeInsets.zero,
- child: CropperImage(
- MemoryImage(widget.image),
- controller: _controller,
- ),
- ),
- Positioned(
- left: 0,
- bottom: 0,
- right: 0,
- height: 110.px,
- child: Container(
- alignment: Alignment.center,
- child: LinkButton(
- title: '完成',
- disable: false,
- isBlack: false,
- callback: () {
- clip();
- })),
- )
- ],
- )
- // child: Screenshot(
- // controller: screenshotController,
- // child: Stack(children: [
- // PhotoView(
- // maxScale: 1.5,
- // minScale: 0.1,
- // filterQuality: FilterQuality.medium,
- // scaleStateChangedCallback: ((value) {}),
- // imageProvider: MemoryImage(widget.image)),
- // Positioned(
- // left: left,
- // top: top,
- // width: width,
- // height: height,
- // child: IgnorePointer(
- // child: Container(
- // decoration: BoxDecoration(
- // color: Colors.transparent,
- // border: Border.all(color: Colors.white, width: 2.px)),
- // ))),
- // Positioned(
- // left: 0,
- // right: 0,
- // top: 0,
- // height: top,
- // child: IgnorePointer(
- // child: Container(color: const Color(0x80000000)),
- // )),
- // Positioned(
- // left: 0,
- // right: 0,
- // bottom: 0,
- // height: top,
- // child: IgnorePointer(
- // child: Container(color: const Color(0x80000000)),
- // )),
- // Positioned(
- // left: 0,
- // width: left,
- // top: top,
- // height: height,
- // child: IgnorePointer(
- // child: Container(color: const Color(0x80000000)),
- // )),
- // Positioned(
- // width: left,
- // right: 0,
- // top: top,
- // height: height,
- // child: IgnorePointer(
- // child: Container(color: const Color(0x80000000)),
- // )),
- // Positioned(
- // left: 0,
- // bottom: 0,
- // right: 0,
- // height: 110.px,
- // child: Container(
- // alignment: Alignment.center,
- // child: LinkButton(
- // title: '完成',
- // disable: false,
- // isBlack: false,
- // callback: () {
- // clip();
- // })),
- // )
- // ]),
- // )
- ));
- }
- }
- class MyClipper extends CustomClipper<RRect> {
- @override
- RRect getClip(Size size) => RRect.fromLTRBXY(10.0, 15.0, 380.0, 380.0, 0.0,
- 0.0); //RRect.fromLTWH(10.0, 15.0, 40.0, 30.0);
- @override
- bool shouldReclip(CustomClipper<RRect> oldClipper) => true;
- }
|