Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

crop

a flutter package for cropping any widget, not only images. this flutter package is entirely written in dart and supports android, ios, web and desktop. also, because of being independent from native platform, it does not increase size of your apps output (e.g. apk).

crop any widget/image in android, ios, web and desktop with fancy and customizable ui, in pure dart code.

crop

getting started with this flutter package

in your pubspec.yaml file add:

dependencies:
  crop: any

then, in your code import:

import 'package:crop/crop.dart';

now in build function, put a crop widget in the widget tree:

import 'package:app/centered_slider_track_shape.dart';
import 'package:flutter/material.dart';
import 'package:crop/crop.dart';

void main() => runapp(myapp());

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return materialapp(
      title: 'crop demo',
      theme: themedata(
        primaryswatch: colors.blue,
      ),
      home: myhomepage(),
    );
  }
}

class myhomepage extends statefulwidget {
  @override
  _myhomepagestate createstate() => _myhomepagestate();
}

class _myhomepagestate extends state<myhomepage> {
  final _cropkey = globalkey<cropstate>();
  double _rotation = 0;

  void _cropimage() async {
    final cropped = await _cropkey.currentstate.crop();
    navigator.of(context).push(
      materialpageroute(
        builder: (context) => scaffold(
          appbar: appbar(
            title: text('crop result'),
            centertitle: true,
          ),
          body: center(
            child: rawimage(
              image: cropped,
            ),
          ),
        ),
        fullscreendialog: true,
      ),
    );
  }

  @override
  widget build(buildcontext context) {
    final theme = theme.of(context);
    return scaffold(
      appbar: appbar(
        title: text('crop demo'),
        centertitle: true,
        actions: <widget>[
          iconbutton(
            onpressed: _cropimage,
            tooltip: 'crop',
            icon: icon(icons.crop),
          )
        ],
      ),
      body: column(
        children: <widget>[
          expanded(
            child: crop(
              key: _cropkey,
              child: image.asset('images/sample.jpg'),
              aspectratio: 1000 / 667.0,
            ),
          ),
          row(
            children: <widget>[
              iconbutton(
                icon: icon(icons.undo),
                tooltip: 'undo',
                onpressed: () {
                  _cropkey.currentstate.rotation = 0;
                  _cropkey.currentstate.scale = 1;
                  _cropkey.currentstate.offset = offset.zero;
                  setstate(() {
                    _rotation = 0;
                  });
                },
              ),
              expanded(
                child: slidertheme(
                  data: theme.slidertheme.copywith(
                    trackshape: centeredrectangularslidertrackshape(),
                  ),
                  child: slider(
                    divisions: 91,
                    value: _rotation,
                    min: -45,
                    max: 45,
                    label: '$_rotation°',
                    onchanged: (n) {
                      setstate(() {
                        _rotation = n.roundtodouble();
                        _cropkey.currentstate.rotation = _rotation;
                      });
                    },
                  ),
                ),
              ),
              iconbutton(
                icon: icon(icons.aspect_ratio),
                tooltip: 'aspect ratio',
                onpressed: () {},
              ),
            ],
          ),
        ],
      ),
    );
  }
}

please don’t forget to check /example folder, there is much more.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.