mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-19 15:45:26 +02:00
added torch button
This commit is contained in:
parent
90a52ec9a6
commit
fc19c81127
@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:camera/camera.dart';
|
import 'package:camera/camera.dart';
|
||||||
|
import 'package:expandable_bottom_sheet/expandable_bottom_sheet.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:share_location/constants/spacing.dart';
|
import 'package:share_location/constants/spacing.dart';
|
||||||
import 'package:share_location/constants/values.dart';
|
import 'package:share_location/constants/values.dart';
|
||||||
@ -30,6 +31,7 @@ class MainScreen extends StatefulWidget {
|
|||||||
class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||||
bool isRecording = false;
|
bool isRecording = false;
|
||||||
bool lockCamera = false;
|
bool lockCamera = false;
|
||||||
|
bool isTorchEnabled = false;
|
||||||
List? lastPhoto;
|
List? lastPhoto;
|
||||||
Uint8List? uploadingPhotoAnimation;
|
Uint8List? uploadingPhotoAnimation;
|
||||||
|
|
||||||
@ -208,123 +210,154 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
body: SafeArea(
|
bottomSheet: () {
|
||||||
child: () {
|
if (isLoading) {
|
||||||
if (isLoading) {
|
return const Center(
|
||||||
return const Center(
|
child: CircularProgressIndicator(),
|
||||||
child: CircularProgressIndicator(),
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return SizedBox(
|
return Container(
|
||||||
width: MediaQuery.of(context).size.width,
|
color: Colors.black,
|
||||||
height: MediaQuery.of(context).size.height,
|
child: ExpandableBottomSheet(
|
||||||
child: Stack(
|
background: SafeArea(
|
||||||
alignment: Alignment.center,
|
child: SizedBox(
|
||||||
children: <Widget>[
|
width: MediaQuery.of(context).size.width,
|
||||||
Column(
|
height: MediaQuery.of(context).size.height,
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
AnimateInBuilder(
|
Align(
|
||||||
builder: (showPreview) => AnimatedOpacity(
|
alignment: Alignment.topCenter,
|
||||||
opacity: showPreview ? 1.0 : 0.0,
|
child: AnimateInBuilder(
|
||||||
duration: const Duration(milliseconds: 1100),
|
builder: (showPreview) => AnimatedOpacity(
|
||||||
curve: Curves.easeOutQuad,
|
opacity: showPreview ? 1.0 : 0.0,
|
||||||
child: ClipRRect(
|
duration: const Duration(milliseconds: 1100),
|
||||||
borderRadius: BorderRadius.circular(SMALL_SPACE),
|
curve: Curves.easeOutQuad,
|
||||||
child: AspectRatio(
|
child: ClipRRect(
|
||||||
aspectRatio: 1 / controller!.value.aspectRatio,
|
borderRadius: BorderRadius.circular(SMALL_SPACE),
|
||||||
child: controller!.buildPreview(),
|
child: AspectRatio(
|
||||||
|
aspectRatio: 1 / controller!.value.aspectRatio,
|
||||||
|
child: controller!.buildPreview(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
if (uploadingPhotoAnimation != null)
|
||||||
child: Column(
|
UploadingPhoto(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
data: uploadingPhotoAnimation!,
|
||||||
children: <Widget>[
|
onDone: () {
|
||||||
Padding(
|
setState(() {
|
||||||
padding: const EdgeInsets.symmetric(
|
uploadingPhotoAnimation = null;
|
||||||
horizontal: LARGE_SPACE),
|
});
|
||||||
child: Row(
|
},
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: <Widget>[
|
|
||||||
FadeAndMoveInAnimation(
|
|
||||||
translationDuration:
|
|
||||||
DEFAULT_TRANSLATION_DURATION *
|
|
||||||
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
|
||||||
opacityDuration: DEFAULT_OPACITY_DURATION *
|
|
||||||
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
|
||||||
child: ChangeCameraButton(
|
|
||||||
onChangeCamera: () {
|
|
||||||
final currentCameraIndex =
|
|
||||||
GlobalValuesManager.cameras
|
|
||||||
.indexOf(controller!.description);
|
|
||||||
final availableCameras =
|
|
||||||
GlobalValuesManager.cameras.length;
|
|
||||||
|
|
||||||
onNewCameraSelected(
|
|
||||||
GlobalValuesManager.cameras[
|
|
||||||
(currentCameraIndex + 1) %
|
|
||||||
availableCameras],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FadeAndMoveInAnimation(
|
|
||||||
child: CameraButton(
|
|
||||||
disabled: lockCamera,
|
|
||||||
active: isRecording,
|
|
||||||
onVideoBegin: () async {
|
|
||||||
setState(() {
|
|
||||||
isRecording = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (controller!.value.isRecordingVideo) {
|
|
||||||
// A recording has already started, do nothing.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await controller!.startVideoRecording();
|
|
||||||
},
|
|
||||||
onVideoEnd: takeVideo,
|
|
||||||
onPhotoShot: takePhoto,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FadeAndMoveInAnimation(
|
|
||||||
translationDuration:
|
|
||||||
DEFAULT_TRANSLATION_DURATION *
|
|
||||||
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
|
||||||
opacityDuration: DEFAULT_OPACITY_DURATION *
|
|
||||||
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
|
||||||
child: lastPhoto == null
|
|
||||||
? const TodayPhotoButton()
|
|
||||||
: TodayPhotoButton(
|
|
||||||
data: lastPhoto![0],
|
|
||||||
type: lastPhoto![1],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
persistentHeader: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.black,
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(LARGE_SPACE),
|
||||||
|
topRight: Radius.circular(LARGE_SPACE),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(LARGE_SPACE),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: <Widget>[
|
||||||
|
FadeAndMoveInAnimation(
|
||||||
|
translationDuration: DEFAULT_TRANSLATION_DURATION *
|
||||||
|
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
||||||
|
opacityDuration: DEFAULT_OPACITY_DURATION *
|
||||||
|
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
||||||
|
child: ChangeCameraButton(
|
||||||
|
onChangeCamera: () {
|
||||||
|
final currentCameraIndex = GlobalValuesManager.cameras
|
||||||
|
.indexOf(controller!.description);
|
||||||
|
final availableCameras =
|
||||||
|
GlobalValuesManager.cameras.length;
|
||||||
|
|
||||||
|
onNewCameraSelected(
|
||||||
|
GlobalValuesManager.cameras[
|
||||||
|
(currentCameraIndex + 1) % availableCameras],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
FadeAndMoveInAnimation(
|
||||||
|
child: CameraButton(
|
||||||
|
disabled: lockCamera,
|
||||||
|
active: isRecording,
|
||||||
|
onVideoBegin: () async {
|
||||||
|
setState(() {
|
||||||
|
isRecording = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (controller!.value.isRecordingVideo) {
|
||||||
|
// A recording has already started, do nothing.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await controller!.startVideoRecording();
|
||||||
|
},
|
||||||
|
onVideoEnd: takeVideo,
|
||||||
|
onPhotoShot: takePhoto,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
FadeAndMoveInAnimation(
|
||||||
|
translationDuration: DEFAULT_TRANSLATION_DURATION *
|
||||||
|
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
||||||
|
opacityDuration: DEFAULT_OPACITY_DURATION *
|
||||||
|
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
||||||
|
child: lastPhoto == null
|
||||||
|
? const TodayPhotoButton()
|
||||||
|
: TodayPhotoButton(
|
||||||
|
data: lastPhoto![0],
|
||||||
|
type: lastPhoto![1],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (uploadingPhotoAnimation != null)
|
),
|
||||||
UploadingPhoto(
|
),
|
||||||
data: uploadingPhotoAnimation!,
|
expandableContent: Padding(
|
||||||
onDone: () {
|
padding: const EdgeInsets.all(LARGE_SPACE),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
ElevatedButton.icon(
|
||||||
|
icon: const Icon(Icons.flashlight_on_rounded),
|
||||||
|
label: const Text('Torch'),
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||||
|
(_) => isTorchEnabled ? Colors.white : Colors.black,
|
||||||
|
),
|
||||||
|
foregroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||||
|
(_) => isTorchEnabled ? Colors.black : Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
uploadingPhotoAnimation = null;
|
isTorchEnabled = !isTorchEnabled;
|
||||||
|
|
||||||
|
if (isTorchEnabled) {
|
||||||
|
controller!.setFlashMode(FlashMode.torch);
|
||||||
|
} else {
|
||||||
|
controller!.setFlashMode(FlashMode.off);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}(),
|
);
|
||||||
),
|
}(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.5"
|
version: "1.0.5"
|
||||||
|
expandable_bottom_sheet:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: expandable_bottom_sheet
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.1+1"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -48,6 +48,7 @@ dependencies:
|
|||||||
provider: ^6.0.3
|
provider: ^6.0.3
|
||||||
gallery_saver: ^2.3.2
|
gallery_saver: ^2.3.2
|
||||||
fluttertoast: ^8.0.9
|
fluttertoast: ^8.0.9
|
||||||
|
expandable_bottom_sheet: ^1.1.1+1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user