simple_picker 0.0.3 copy "simple_picker: ^0.0.3" to clipboard
simple_picker: ^0.0.3 copied to clipboard

Simple picker is fix issue of image_picker plugin on iOS

example/lib/main.dart

import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:image/image.dart' as img;
import 'package:flutter/services.dart';
import 'package:plugin_example_example/MyAppNew.dart';
import 'package:simple_picker/simple_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late SimplePicker _simplePickerPlugin;
  final String _platformVersion = 'Unknown';
  File? _value;
  @override
  void initState() {
    super.initState();
    _simplePickerPlugin = SimplePicker();
  }

  Future<void> _showPicker() async {
    try {
      var result = await _simplePickerPlugin.showPicker(source: 'front');
      log('result: $result');
      setState(() {
        _value = result;
      });
    } catch (e) {
      log('error: $e');
    }
  }

  //show dialog to show image
  void _showImageDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content:
              Container(height: 300, width: 300, child: Image.file(_value!)),
        );
      },
    );
  }

  @override
  void dispose() {
    // _simplePickerPlugin.dispose(); // Don't forget to dispose the plugin
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        bottomNavigationBar: BottomAppBar(
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  onPressed: () {
                    print('tapped left button');
                  },
                  child: const Text('Show Picker'),
                ),
              ),
              Expanded(
                child: ElevatedButton(
                  onPressed: () {
                    print('tapped');
                  },
                  child: const Text('Show Picker'),
                ),
              ),
            ],
          ),
        ),
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: _showPicker,
                child: const Text('Show Picker'),
              ),
              Text('Data received True or Null: ${_value}'),
              if (_value != null)
                InkWell(
                    onTap: () {
                      // _showImageDialog();
                    },
                    child: Image.file(_value!)),
              // Text('Data received: ${snapshot.data}'),
              // FutureBuilder(
              //   future: _getImageSize(_value!.path),
              //   builder: (context, snapshot) {
              //     if (snapshot.connectionState == ConnectionState.waiting) {
              //       return CircularProgressIndicator();
              //     } else if (snapshot.hasError) {
              //       return Text('Error: ${snapshot.error}');
              //     } else {
              //       final img.Image? image = snapshot.data;
              //       return Column(
              //         children: [
              //           Image.file(File(_value!.path)),
              //           SizedBox(height: 20),
              //           Text('Width: ${image!.width}'),
              //           SizedBox(height: 10),
              //           Text('Height: ${image!.height}'),
              //         ],
              //       );
              //     }
              //   },
              // ),
              ElevatedButton(
                onPressed: () {
                  // _showImageDialog();
                },
                child: const Text('Call Off Image'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<img.Image> _getImageSize(String imagePath) async {
    final bytes = await File(imagePath).readAsBytes();
    return img.decodeImage(bytes)!;
  }
}
2
likes
0
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

Simple picker is fix issue of image_picker plugin on iOS

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on simple_picker

Packages that implement simple_picker