Skip to content

Commit

Permalink
update capture page , model is now a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdrz committed Oct 12, 2018
1 parent 52b204f commit 326d050
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 53 deletions.
1 change: 1 addition & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eclipse.preferences.version=1
72 changes: 19 additions & 53 deletions lib/pages/capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ class Choice {

enum Options { video, videoRecording, photo, audio, audioRecording }

class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
class _CaptureRoute extends State<CaptureRoute> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

AnimationController _animationController;
Animation _animation;

CameraController controller;
CaptureModel model;

var _state = Options.photo;
bool _initializing = false;
Expand All @@ -66,18 +64,6 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {

@override
void initState() {
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 5),
);

_animation = Tween(begin: 0.0, end: 500.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.fastOutSlowIn,
),
);

_prepare();
super.initState();
}
Expand All @@ -93,11 +79,10 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
_loading = false;
});
if (filePath != null) {
CaptureModel audio = CaptureModel(
model = CaptureModel(
filePath: filePath,
seriesUUID: uuid,
captureMode: CaptureMode.audio);
CaptureModel.updateItem(audio);
}
}
});
Expand All @@ -106,6 +91,7 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
void onAudioStopButtonPressed() {
stopAudioRecording().then((_) {
_state = Options.audio;
CaptureModel.updateItem(model);
if (mounted) setState(() {});
});
}
Expand Down Expand Up @@ -135,49 +121,43 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
}

void onTakePictureButtonPressed() {
setState(() {
_loading = true;
});
_loading = true;
takePicture().then((String filePath) {
if (mounted) {
setState(() {
_loading = false;
});
_loading = false;
if (filePath != null) {
CaptureModel image = CaptureModel(
model = CaptureModel(
filePath: filePath,
seriesUUID: uuid,
captureMode: CaptureMode.picture);
CaptureModel.updateItem(image);
CaptureModel.updateItem(model);
}
setState(() {});
}
});
}

void onVideoRecordButtonPressed() {
setState(() {
_loading = true;
});
_loading = true;
startVideoRecording().then((String filePath) {
_state = Options.videoRecording;
if (mounted) {
setState(() {
_loading = false;
});
_state = Options.videoRecording;
_loading = false;
if (filePath != null) {
CaptureModel video = CaptureModel(
model = CaptureModel(
filePath: filePath,
seriesUUID: uuid,
captureMode: CaptureMode.video);
CaptureModel.updateItem(video);
}
setState(() {});
}
});
}

void onVideoStopButtonPressed() {
stopVideoRecording().then((_) {
_state = Options.video;
CaptureModel.updateItem(model);
if (mounted) setState(() {});
});
}
Expand Down Expand Up @@ -327,7 +307,6 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
if (_state == Options.photo) {
onTakePictureButtonPressed();
} else if (_state == Options.video) {
_animationController.repeat();
onVideoRecordButtonPressed();
} else if (_state == Options.videoRecording) {
onVideoStopButtonPressed();
Expand Down Expand Up @@ -368,23 +347,10 @@ class _CaptureRoute extends State<CaptureRoute> with TickerProviderStateMixin {
);
}
if (_state == Options.audioRecording || _state == Options.videoRecording) {
return AnimatedBuilder(
animation: _animationController,
builder: (BuildContext context, Widget child) {
int value = (_animation.value as double).toInt();
if (value > 250) {
value = 500 - value;
}
double size = value / 5.0;
if (size < 30.0) {
size = 30.0;
}
return Icon(
Icons.stop,
size: size,
color: Colors.black.withRed(value),
);
},
return Icon(
Icons.stop,
size: 50.0,
color: Colors.black.withRed(50),
);
}
return Icon(Icons.archive);
Expand Down

0 comments on commit 326d050

Please sign in to comment.