camerapack 0.0.1
camerapack: ^0.0.1 copied to clipboard
A Flutter plugin for custom camera functionalities, including capturing images, flipping cameras, and accessing the gallery.
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:camerapack/camerapack.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String? data;
final _camerapackPlugin = Camerapack();
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String? platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await _camerapackPlugin.captureImage() ?? 'Unknown platform version';
} on PlatformException {
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
data = platformVersion!;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: initPlatformState,
child: Text('Click Photo',textAlign: TextAlign.center,)),
if(data!=null) Image.file(File(data!),width: 200,height: 200,)
],
),
),
),
);
}
}