简体   繁体   中英

I want to click a picture of document and crop it (like cam scanner), this to be done when user clicks on my sliverList. I am new to flutter

Remember it is 3rd page where i want my onPressed to open camera and crop image.
Tell me code for both android and Ios.

  import 'package:flutter/material.dart';
  import 'package:telemed/pages/size_config.dart';
  import 'strings.dart';
  import 'package:camera/camera.dart';

  class User extends StatefulWidget {
 
 List<CameraDescription> cameras;
 Future<void> main() async {
 runApp(); // what to write here instead of all this code.it is my 3rd page of flutter  
 WidgetsFlutterBinding.ensureInitialized();
 final cameras = await availableCameras();

 @override
 _PatientState createState() => _UserState();
}

class _UserState extends State<User> {
 @override
 Widget build(BuildContext context) {
 return Scaffold(
  body: CustomScrollView(
      slivers: <Widget>[
        Container(
          child: SliverList(
            delegate: SliverChildBuilderDelegate((context, index) {
              return Container(
                alignment: Alignment.center,
                color: Colors.white,
                child: Text('Patient ${index}'),
                height: 120,
                margin: EdgeInsets.all(1),
              );
            }, childCount: 20),
          ),
        )
      ],
    ));
  } // please ignore any extra curly braces...
 }

my main aim is that user touches my sliverListview (like whatsapp but opens camera to crop a document clicked via camera instead of chat).

Please, read the relevant Flutter documentation about Widgets, then read the camera package documentation.

Configure your project to support camera and photo library access as per the documentation.

Then you can wrap your Container in an InkWell widget and use its onTap callback to then invoke the initialize method on your CameraController .

The camera package is built with support for both Android and iOS, so the Flutter code you write will work on both platforms.

You can use either image_crop or flutter_native_image packages to crop resulting image.

I hope you don't expect me (or anyone else) to write the whole app for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM