8000 added images from camera & scanner camera feature · jtaxiexpress/flip_book@c8053d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
added images from camera & scanner camera feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Zohaib Hassan Soomro committed Apr 5, 2023
1 parent 673dfa9 commit c8053d5
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 88 deletions.
46 changes: 46 additions & 0 deletions lib/custom_widgets/carousel_dragg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';

class ReorderableListViewExample extends StatefulWidget {
@override
_ReorderableListViewExampleState createState() =>
_ReorderableListViewExampleState();
}

class _ReorderableListViewExampleState
extends State<ReorderableListViewExample> {
List<String> containers = List.generate(6, (index) => 'Container $index');

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Reorderable List View Example'),
),
body: ReorderableListView.builder(
padding: EdgeInsets.symmetric(horizontal: 16),
scrollDirection: Axis.horizontal,
itemCount: containers.length,
itemBuilder: (context, index) => GestureDetector(
key: Key('$index'),
child: Container(
width: 100,
height: 100,
color: Colors.blue,
child: Center(
child: Text(containers[index]),
),
),
),
onReorder: (oldIndex, newIndex) {
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final container = containers.removeAt(oldIndex);
containers.insert(newIndex, container);
});
},
),
);
}
}
2 changes: 1 addition & 1 deletion lib/custom_widgets/flipped_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _FlipContainerState extends State<FlipContainer>
return Transform(
transform: matrix,
alignment: Alignment.center,
child: _isFrontVisible ? widget.child : const Text(''),
child: widget.child,
);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/model/flip_book.dart
< 10000 /div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FlipBook {
required this.title,
required this.creationDate,
required this.imageUrls,
this.flipSpeed = 1.5,
this.flipSpeed = 25,
this.hasFlipAnimation = true,
});

Expand Down
47 changes: 39 additions & 8 deletions lib/pages/edit_flip_book.dart
8000
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class _EditFlipBookState extends State<EditFlipBook> {
final carouselController = CarouselController();
int activeIndex = 0;

@override
void initState() {
super.initState();
if (mounted) {
setState(() {
widget.flipBook.flipSpeed = widget.flipBook.flipSpeed == 25
? widget.flipBook.flipSpeed
: flipSpeed;
});
}
}

@override
void dispose() {
super.dispose();
Expand Down Expand Up @@ -79,29 +91,46 @@ class _EditFlipBookState extends State<EditFlipBook> {
);
}

CarouselSlider buildFlipBookItemsList(ui.Size size) {
Widget buildFlipBookItemsList(ui.Size size) {
return CarouselSlider.builder(
carouselController: carouselController,
disableGesture: false,
options: CarouselOptions(
autoPlay: false,
aspectRatio: 1.0,
initialPage: activeIndex,
enableInfiniteScroll: false,
scrollPhysics: const NeverScrollableScrollPhysics(),
viewportFraction: 0.63,
viewportFraction: 0.7,
onPageChanged: (index, reason) {
activeIndex = index;
if (mounted) setState(() {});
}
// enlargeCenterPage: true,
),
itemCount: widget.flipBook.imageUrls.length,
itemBuilder: (context, index, pageIndex) => buildFlipItem(size, index),
itemCount: widget.flipBook.imageUrls.length > 1
? widget.flipBook.imageUrls.length + 1
: widget.flipBook.imageUrls.length,
itemBuilder: (context, index, pageIndex) {
if (index == widget.flipBook.imageUrls.length) {
return Center(
child: ElevatedButton.icon(
onPressed: () {
carouselController.animateToPage(0);
},
icon: const Icon(FontAwesomeIcons.arrowsRotate),
label: Text('go to first'),
) 8000 ,
);
}
return buildFlipItem(size, index);
},
);
}

Widget buildFlipItem(ui.Size size, index) {
return GestureDetector(
key: Key("Key $index"),
onHorizontalDragUpdate: hasFlipAnimation
? null
: (val) {
Expand Down Expand Up @@ -321,8 +350,8 @@ class _EditFlipBookState extends State<EditFlipBook> {
height: size.height * 0.05,
child: CupertinoSlider(
value: flipSpeed,
min: 1,
max: 40,
min: 20,
max: 50,
onChanged: onFlipSpeedChanged,
),
)
Expand All @@ -332,8 +361,8 @@ class _EditFlipBookState extends State<EditFlipBook> {
value: flipSpeed,
onChanged: onFlipSpeedChanged,
label: flipSpeed.toStringAsFixed(2),
min: 1,
max: 40,
min: 20,
max: 50,
),
),
],
Expand Down Expand Up @@ -413,6 +442,7 @@ class _EditFlipBookState extends State<EditFlipBook> {
if (mounted) {
setState(() {
hasFlipAnimation = value;
widget.flipBook.hasFlipAnimation = hasFlipAnimation;
});
}
}
Expand All @@ -421,6 +451,7 @@ class _EditFlipBookState extends State<EditFlipBook> {
if (mounted) {
setState(() {
flipSpeed = value;
widget.flipBook.flipSpeed = flipSpeed;
});
}
}
Expand Down
165 changes: 114 additions & 51 deletions lib/pages/new_flip.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import 'dart:io';

import 'package:carousel_slider/carousel_slider.dart';
import 'package:document_scanner_flutter/configs/configs.dart';
import 'package:document_scanner_flutter/document_scanner_flutter.dart';
import 'package:flipbook/model/flip_book.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';

import 'edit_flip 8000 _book.dart';

Expand Down Expand Up @@ -78,7 +83,7 @@ class _NewFlipState extends State<NewFlip> {
FloatingActionButton(
heroTag: const ValueKey("scanner"),
backgroundColor: Colors.black,
onPressed: () {},
onPressed: onImagesFromScannerBtnPressed,
mini: true,
child: const Icon(
Icons.document_scanner_outlined,
Expand All @@ -89,7 +94,7 @@ class _NewFlipState extends State<NewFlip> {
FloatingActionButton(
heroTag: const ValueKey("camera"),
backgroundColor: Colors.black,
onPressed: () {},
onPressed: onImagesFromCameraBtnPressed,
mini: true,
child: const Icon(
Icons.camera_alt,
Expand All @@ -100,30 +105,29 @@ class _NewFlipState extends State<NewFlip> {
],
),
SizedBox(height: size.height * 0.02),
// SizedBox(
// height: size.height * 0.6,
// width: size.width,
// child: Swiper(
// loop: false,
// itemBuilder: (BuildContext context, int index) {
// return Card(
// color: Colors.white,
// elevation: 3,
// shape: const RoundedRectangleBorder(
// borderRadius: BorderRadius.zero),
// child: Image.file(File(imagesPaths[index])),
// );
// },
// itemCount: imagesPaths.length,
// itemWidth: size.width * 0.55,
// itemHeight: size.height * 0.4,
// layout: SwiperLayout.DEFAULT,
// viewportFraction: 0.64,
// controller: ,
// physics: NeverScrollableScrollPhysics(),
// // scale: 0.8,
// ),
// ),
SizedBox(
height: size.height * 0.6,
width: size.width,
child: CarouselSlider.builder(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 1.0,
viewportFraction: 0.63,
enableInfiniteScroll: false,
),
itemCount: imagesPaths.length,
itemBuilder: (context, index, pageIndex) => SizedBox(
width: size.width * 0.55,
height: size.height * 0.4,
child: Card(
color: Colors.white,
elevation: 3,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
child: Image.file(File(imagesPaths[index])),
),
),
)),
],
),
),
Expand Down Expand Up @@ -166,36 +170,31 @@ class _NewFlipState extends State<NewFlip> {
}

void onImagesFromGalleryBtnPressed() async {
final directory = await getApplicationDocumentsDirectory();
final List<XFile> images = await picker.pickMultiImage();
print(images.length);
for (int i = 0; i < images.length; i++) {
final imagePath = '${directory.path}/${images[i].name}';
images[i].saveTo(imagePath).then((value) => print("image saved"));
print(imagePath);
imagesPaths.add(imagePath);
}
if (images.isNotEmpty) {
if (images.length >= 6) {
images.forEach((element) {
imagesPaths.add(element.path);
});
if (mounted) setState(() {});
if (imagesPaths.isNotEmpty) {
if (imagesPaths.length >= 6) {
//TODO
// show Ad
}
FlipBook flipBook = FlipBook(
title: flipBookNameController.text,
creationDate: DateTime.now().toIso8601String(),
imageUrls: images.map((e) => e.path).toList());

Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => EditFlipBook(
flipBook: flipBook,
isFromNewFlipPage: true,
FlipBook flipBook = FlipBook(
title: flipBookNameController.text,
creationDate: DateTime.now().toIso8601String(),
imageUrls: images.map((e) => e.path).toList());
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => EditFlipBook(
flipBook: flipBook,
isFromNewFlipPage: true,
),
),
),
);
);
}
}
if (mounted) setState(() {});
// print(imagesPaths);
}

Expand All @@ -204,6 +203,70 @@ class _NewFlipState extends State<NewFlip> {
super.dispose();
flipBookNameController.dispose();
}

void onImagesFromScannerBtnPressed() async {
try {
final scannedImg = await DocumentScannerFlutter.launch(
context,
source: ScannerFileSource.CAMERA,
); // Or ScannerFileSource.GALLERY
if (scannedImg != null) {
imagesPaths.add(scannedImg.path);
}
if (imagesPaths.isNotEmpty) {
if (imagesPaths.length >= 6) {
//TODO
// show Ad
FlipBook flipBook = FlipBook(
title: flipBookNameController.text,
creationDate: DateTime.now().toIso8601String(),
imageUrls: imagesPaths);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => EditFlipBook(
flipBook: flipBook,
isFromNewFlipPage: true,
),
),
);
}
}
if (mounted) setState(() {});
} on PlatformException {
// 'Failed to get document path or operation cancelled!';
}
}

void onImagesFromCameraBtnPressed() async {
final XFile? image = await picker.pickImage(source: ImageSource.camera);
print(image?.path);
// final imagePath = '${directory.path}/${images[i].name}';
if (image != null) {
imagesPaths.add(image.path);
}
if (imagesPaths.isNotEmpty) {
if (imagesPaths.length >= 6) {
//TODO
// show Ad
FlipBook flipBook = FlipBook(
title: flipBookNameController.text,
creationDate: DateTime.now().toIso8601String(),
imageUrls: imagesPaths);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => EditFlipBook(
flipBook: flipBook,
isFromNewFlipPage: true,
),
),
);
}
}
if (mounted) setState(() {});
// print(imagesPaths);
}
}

/*
Expand Down
Loading

0 comments on commit c8053d5

Please sign in to comment.
0