mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-19 07:35:26 +02:00
improved today button
This commit is contained in:
parent
24927627ab
commit
e49c8f8211
@ -35,7 +35,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
bool isRecording = false;
|
||||
bool lockCamera = false;
|
||||
bool isTorchEnabled = false;
|
||||
List? lastPhoto;
|
||||
Uint8List? uploadingPhotoAnimation;
|
||||
List<double>? zoomLevels;
|
||||
|
||||
@ -62,7 +61,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
getLastPhoto();
|
||||
onNewCameraSelected(GlobalValuesManager.cameras[0]);
|
||||
}
|
||||
|
||||
@ -101,14 +99,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getLastPhoto() async {
|
||||
final data = await FileManager.getLastFile(_user);
|
||||
|
||||
setState(() {
|
||||
lastPhoto = data;
|
||||
});
|
||||
}
|
||||
|
||||
void onNewCameraSelected(final CameraDescription cameraDescription) async {
|
||||
final previousCameraController = controller;
|
||||
// Instantiating the camera controller
|
||||
@ -198,10 +188,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
uploadingPhotoAnimation = null;
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
await getLastPhoto();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> takeVideo() async {
|
||||
@ -240,10 +226,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
lockCamera = false;
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
await getLastPhoto();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@ -362,8 +344,6 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
opacityDuration: DEFAULT_OPACITY_DURATION *
|
||||
SECONDARY_BUTTONS_DURATION_MULTIPLIER,
|
||||
child: TodayPhotoButton(
|
||||
data: lastPhoto == null ? null : lastPhoto![0],
|
||||
type: lastPhoto == null ? null : lastPhoto![1],
|
||||
onLeave: () {
|
||||
controller!.setFlashMode(FlashMode.off);
|
||||
},
|
||||
@ -436,7 +416,7 @@ class _MainScreenState extends AuthRequiredState<MainScreen> with Loadable {
|
||||
});
|
||||
},
|
||||
child: zoomLevels == null
|
||||
? Text('1x')
|
||||
? const Text('1x')
|
||||
: Text(
|
||||
formatZoomLevel(currentZoomLevel),
|
||||
),
|
||||
|
@ -62,6 +62,10 @@ class _RawMemoryDisplayState extends State<RawMemoryDisplay> {
|
||||
|
||||
videoController = VideoPlayerController.file(file);
|
||||
videoController!.initialize().then((value) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
videoController!.setLooping(widget.loopVideo);
|
||||
videoController!.play();
|
||||
|
@ -1,16 +1,16 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:quid_faciam_hodie/constants/spacing.dart';
|
||||
import 'package:quid_faciam_hodie/enums.dart';
|
||||
import 'package:quid_faciam_hodie/models/memories.dart';
|
||||
import 'package:quid_faciam_hodie/screens/server_loading_screen.dart';
|
||||
import 'package:quid_faciam_hodie/screens/timeline_screen.dart';
|
||||
|
||||
import 'raw_memory_display.dart';
|
||||
|
||||
class TodayPhotoButton extends StatelessWidget {
|
||||
final Uint8List? data;
|
||||
final MemoryType? type;
|
||||
class TodayPhotoButton extends StatefulWidget {
|
||||
final VoidCallback onLeave;
|
||||
final VoidCallback onComeBack;
|
||||
|
||||
@ -18,26 +18,70 @@ class TodayPhotoButton extends StatelessWidget {
|
||||
Key? key,
|
||||
required this.onLeave,
|
||||
required this.onComeBack,
|
||||
this.data,
|
||||
this.type,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TodayPhotoButton> createState() => _TodayPhotoButtonState();
|
||||
}
|
||||
|
||||
class _TodayPhotoButtonState extends State<TodayPhotoButton> {
|
||||
Uint8List? data;
|
||||
MemoryType? type;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final memories = context.read<Memories>();
|
||||
|
||||
memories.addListener(loadMemory, ['memories']);
|
||||
|
||||
loadMemory();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final memories = context.read<Memories>();
|
||||
|
||||
memories.removeListener(loadMemory);
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> loadMemory() async {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final memories = context.read<Memories>();
|
||||
|
||||
final lastMemory = memories.memories.first;
|
||||
|
||||
final file = await lastMemory.downloadToFile();
|
||||
final memoryData = await file.readAsBytes();
|
||||
|
||||
setState(() {
|
||||
data = memoryData;
|
||||
type = lastMemory.type;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
onLeave();
|
||||
widget.onLeave();
|
||||
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ServerLoadingScreen(
|
||||
builder: (context) => const ServerLoadingScreen(
|
||||
nextScreen: TimelineScreen.ID,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
onComeBack();
|
||||
widget.onComeBack();
|
||||
},
|
||||
child: Container(
|
||||
width: 45,
|
||||
@ -53,7 +97,7 @@ class TodayPhotoButton extends StatelessWidget {
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(SMALL_SPACE),
|
||||
child: (data == null || type == null)
|
||||
? const SizedBox()
|
||||
? const SizedBox.shrink()
|
||||
: RawMemoryDisplay(
|
||||
data: data!,
|
||||
type: type!,
|
||||
|
Loading…
x
Reference in New Issue
Block a user