color_filter 0.1.4 color_filter: ^0.1.4 copied to clipboard
Option to rotate, flash, mode, filters, timer, exposure, effects, music, gallery for image clicked in story.
import 'dart:async';
import 'dart:io';
import 'package:color_filter/color_filter.dart';
import 'package:color_filter/view/StoryFilter.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart';
void main() => runApp(new MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
var isPressed = false;
var type = 0;
Future getImage(context, GlobalKey<StoryFilterState> globalKey) async {
File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
globalKey.currentState.setGalleryImage(imageFile.path);
}
@override
Widget build(BuildContext context) {
GlobalKey<StoryFilterState> globalKey = GlobalKey();
return new Scaffold(
body: Center(
child: Stack(
children: [
StoryFilter(
key: globalKey,
controllerWidget: Stack(
children: [
Positioned.fill(
bottom: 24,
right: 16,
child: Align(
alignment: Alignment.bottomRight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Visibility(
child: _captureControlRowWidget(globalKey),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: _setGallery(globalKey),
),
],
))),
_capture(globalKey),
],
),
imageEditOptionWidget: Stack(
children: [
Positioned.fill(
bottom: 24,
right: 16,
child: Align(
alignment: Alignment.bottomRight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Visibility(
child: _setRotate(globalKey),
),
Visibility(
child: SizedBox(
height: 16,
),
),
],
))),
],
),
videoEditOptionWidget: Stack(
children: [
Positioned.fill(
top: 48,
right: 16,
child: Align(
alignment: Alignment.topRight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Visibility(
child: videoEditorType(Icons.audiotrack,
StoryFilter.typeMergeMusic),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: videoEditorType(
Icons.filter, StoryFilter.typeFilter),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: videoEditorType(
Icons.settings_input_svideo,
StoryFilter.typeBoomRange),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: videoEditorType(Icons.slow_motion_video,
StoryFilter.typeSlowMotion),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: videoEditorType(
Icons.refresh, StoryFilter.typeReverse),
),
Visibility(
child: SizedBox(
height: 16,
),
),
Visibility(
child: videoEditorType(Icons.fast_forward,
StoryFilter.typeFastForward),
),
Visibility(
child: SizedBox(
height: 16,
),
),
],
))),
],
),
),
],
)),
);
}
Widget _captureControlRowWidget(GlobalKey<StoryFilterState> globalKey) {
return menu(
icon: Icons.switch_camera,
text: "Switch Camera",
tap: () async {
globalKey.currentState.changCamera();
});
}
Widget _setGallery(GlobalKey<StoryFilterState> globalKey) {
return menu(
icon: Icons.photo,
text: "Gallery",
tap: () async {
getImage(context, globalKey);
});
}
Widget _setRotate(GlobalKey<StoryFilterState> globalKey) {
return menu(
icon: Icons.image,
text: "Rotate",
tap: () async {
globalKey.currentState.rotateImage();
});
}
/// Toggle _capture
Widget _capture(GlobalKey<StoryFilterState> globalKey) {
return Positioned.fill(
bottom: 24,
child: Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onLongPressStart: (_) {
globalKey.currentState.startVideo();
},
onLongPressEnd: (_) {
onLongPressVideoCapturing(globalKey);
},
onTap: () async {
onTapCapturing(globalKey);
},
child: Container(
height: isPressed ? 100 : 70,
width: isPressed ? 100 : 70,
child:
isPressed ? Icon(Icons.stop, color: Colors.red) : Container(),
decoration: new BoxDecoration(
border: Border.all(width: 2.5, color: Colors.white),
shape: BoxShape.circle,
color: Colors.green.withOpacity(0.30)),
)),
),
);
}
Widget videoEditorType(IconData icon, int viewType) {
return GestureDetector(
onTap: () async {
if (viewType == StoryFilter.typeMergeMusic) {
await StoryEditor.showAlertDialog();
} else {}
selectType(viewType);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 40,
width: 40,
child: Icon(icon,
color: type == viewType ? Colors.green : Colors.white),
decoration: new BoxDecoration(
border: Border.all(
width: 2.5,
color: type == viewType ? Colors.green : Colors.white),
shape: BoxShape.circle,
color: Colors.black12.withOpacity(0.30)),
),
SizedBox(
height: 4,
),
Text(
viewType == StoryFilter.typeReverse
? "Reverse"
: viewType == StoryFilter.typeFilter
? "Filter"
: viewType == StoryFilter.typeBoomRange
? "BoomRange"
: viewType == StoryFilter.typeSlowMotion
? "Slow Motion"
: viewType == StoryFilter.typeFastForward
? "Timelapse"
: viewType == StoryFilter.typeMergeMusic
? "Music"
: "",
style: TextStyle(
color: type == viewType ? Colors.green : Colors.white,
fontSize: 8.0),
)
],
));
}
Widget menu({IconData icon, String text, Function tap}) {
return GestureDetector(
onTap: () async {
tap();
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 40,
width: 40,
child: Icon(icon, color: Colors.white),
decoration: new BoxDecoration(
border: Border.all(width: 2.5, color: Colors.white),
shape: BoxShape.circle,
color: Colors.black12.withOpacity(0.30)),
),
SizedBox(
height: 4,
),
Text(
"$text",
style: TextStyle(color: Colors.white, fontSize: 8.0),
)
],
));
}
selectType(int type) {
setState(() {
this.type = type;
});
}
Future<void> onLongPressVideoCapturing(
GlobalKey<StoryFilterState> globalKey) async {
if (!globalKey.currentState.isRecordingVideo()) {
globalKey.currentState.startVideo();
} else {
onTapCapturing(globalKey);
}
}
Future<void> onTapCapturing(
GlobalKey<StoryFilterState> globalKey) async {
if (globalKey.currentState.isRecordingVideo()) {
globalKey.currentState.stopVideoRecording(type);
} else {
globalKey.currentState.onTakePictureButtonPressed();
}
}
}