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 createState() => _EditAvatarState(); } class _EditAvatarState extends State { 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 { @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 oldClipper) => true; }