Skip to content

Commit

Permalink
* Optimized Imports
Browse files Browse the repository at this point in the history
* Added fullscreen webcam
  • Loading branch information
Clon1998 committed Sep 18, 2021
1 parent 838f4c3 commit 8d3380c
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 107 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Mobileraker is a Flutter app to control a single or multiple 3D printers running

Checkout the first release to download an Android APK!

## Support me
Want to support me?

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/PadS)



Home | More images...
:------------------------------------------------------:|:-------------------------------------------------------:
Expand All @@ -26,7 +32,7 @@ Home | More images...
* [ ] Add temperature graphs
* [ ] Add a console
* [ ] Add mesh selection
* [ ] Add qery endstops
* [ ] Add query endstops
* [ ] Files(STL) page
* [ ] Upload stls
* [ ] Stl preview
Expand All @@ -36,9 +42,4 @@ Home | More images...
* [ ] Klipper power control feature

## Getting Started
After importing this project into your IDE be sure to run `flutter packages pub run build_runner build` in order to generate required files!

## Support me
Want to support me?

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/PadS)
After importing this project into your IDE be sure to run `flutter packages pub run build_runner build` in order to generate required files!
12 changes: 8 additions & 4 deletions lib/app/AppSetup.dart → lib/app/app_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'dart:ui';
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:mobileraker/dto/machine/PrinterSetting.dart';
import 'package:mobileraker/dto/machine/TemperaturePreset.dart';
import 'package:mobileraker/dto/machine/WebcamSetting.dart';
import 'package:mobileraker/service/MachineService.dart';
import 'package:mobileraker/dto/machine/printer_setting.dart';
import 'package:mobileraker/dto/machine/temperature_preset.dart';
import 'package:mobileraker/dto/machine/webcam_setting.dart';
import 'package:mobileraker/service/machine_service.dart';
import 'package:mobileraker/ui/views/files/files_view.dart';
import 'package:mobileraker/ui/views/fullcam/full_cam_view.dart';
import 'package:mobileraker/ui/views/overview/overview_view.dart';
import 'package:mobileraker/ui/views/overview/tabs/general_tab_viewmodel.dart';
import 'package:mobileraker/ui/views/printers/add/printers_add_view.dart';
Expand All @@ -20,8 +22,10 @@ import 'package:stacked_services/stacked_services.dart';
MaterialRoute(page: OverView, initial: true),
CupertinoRoute(page: SettingView),
CupertinoRoute(page: Printers),
MaterialRoute(page: FullCamView),
MaterialRoute(page: PrintersAdd),
MaterialRoute(page: PrintersEdit),
MaterialRoute(page: FilesView),
], dependencies: [
LazySingleton(classType: NavigationService),
LazySingleton(classType: SnackbarService),
Expand Down
15 changes: 5 additions & 10 deletions lib/service/file_service.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import 'dart:async';
import 'dart:convert';
import 'package:mobileraker/dto/files/folder.dart';
import 'package:mobileraker/dto/files/gcode_file.dart';
import 'package:path/path.dart' as p;

import 'package:enum_to_string/enum_to_string.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobileraker/WebSocket.dart';
import 'package:mobileraker/app/app_setup.logger.dart';
import 'package:mobileraker/dto/machine/printer.dart';
import 'package:mobileraker/dto/server/klipper.dart';
import 'package:rxdart/rxdart.dart';
import 'package:mobileraker/dto/files/folder.dart';
import 'package:mobileraker/dto/files/gcode_file.dart';

enum FileRoot { gcodes, config, config_examples, docs }

Expand Down Expand Up @@ -96,12 +91,12 @@ class FileService {
response, String forPath, Completer<FolderReqWrapper> completer) {
List<dynamic> filesResponse = response['files']; // Just add an type
List<dynamic> directoriesResponse = response['dirs']; // Just add an type

directoriesResponse.removeWhere((element) {
String name = element['dirname'];
return name.startsWith('.');
});

List<Folder> listOfFolder =
List.generate(directoriesResponse.length, (index) {
var element = directoriesResponse[index];
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/bottomsheet/setup_bottom_sheet_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class _NonPrintingBottomSheet
var themeData = Theme.of(context);
var isDark = themeData.brightness == Brightness.dark;
var buttonStyle = ElevatedButton.styleFrom(
primary: isDark ? themeData.accentColor : themeData.primaryColor,
primary: isDark ? themeData.colorScheme.secondary : themeData.primaryColor,
onSurface: Colors.pink,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
));

return Container(
padding: EdgeInsets.fromLTRB(25, 15, 25, 10),
padding: const EdgeInsets.fromLTRB(25, 15, 25, 10),
decoration: BoxDecoration(
color: isDark ? themeData.primaryColor : Colors.white,
borderRadius: BorderRadius.only(
Expand All @@ -66,7 +66,7 @@ class _NonPrintingBottomSheet
),
)),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Icon(
FlutterIcons.raspberry_pi_faw5d,
color: isDark ? Colors.white : Colors.black,
Expand Down
22 changes: 13 additions & 9 deletions lib/ui/components/connection/connection_state_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:mobileraker/WebSocket.dart';
import 'package:progress_indicators/progress_indicators.dart';
import 'package:stacked/stacked.dart';

import 'connection_state_viewmodel.dart';

class ConnectionStateView extends StatelessWidget {
Expand Down Expand Up @@ -31,19 +32,19 @@ class ConnectionStateView extends StatelessWidget {
text: 'You will have to ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[

TextSpan(
text: 'add',
style: TextStyle(fontWeight: FontWeight.bold, decoration: TextDecoration.underline),
style: TextStyle(
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = model.onAddPrinterTap),
TextSpan(
text: ' a printer first!',
),
text: ' a printer first!',
),
],
),
)

],
),
);
Expand Down Expand Up @@ -76,12 +77,12 @@ class ConnectionStateView extends StatelessWidget {
);
case WebSocketState.connecting:
return Center(
key:UniqueKey(),
key: UniqueKey(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SpinKitPouringHourGlassRefined(
color: Theme.of(context).accentColor,
color: Theme.of(context).colorScheme.secondary,
),
SizedBox(
height: 30,
Expand All @@ -94,15 +95,18 @@ class ConnectionStateView extends StatelessWidget {
default:
return Container(
alignment: Alignment.center,
padding: EdgeInsets.all(22),
padding: const EdgeInsets.all(22),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.warning_amber_outlined),
SizedBox(
height: 20,
),
Text(model.websocketErrorMessage, textAlign: TextAlign.center,),
Text(
model.websocketErrorMessage,
textAlign: TextAlign.center,
),
TextButton.icon(
onPressed: model.onRetryPressed,
icon: Icon(Icons.stream),
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/dialog/editForm/editForm_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class EditFormDialogViewArguments {
final num? current;
final int? fraction;

EditFormDialogViewArguments({this.min, this.max, this.current, this.fraction});
EditFormDialogViewArguments(
{this.min, this.max, this.current, this.fraction});
}

class EditFormDialogView extends StatelessWidget {
Expand Down Expand Up @@ -90,7 +91,7 @@ class NumField extends ViewModelWidget<EditFormViewModel> {
TextInputType.numberWithOptions(signed: false, decimal: false),
decoration: InputDecoration(
border: const UnderlineInputBorder(),
contentPadding: EdgeInsets.all(8.0),
contentPadding: const EdgeInsets.all(8.0),
labelText: request.description,
helperText: "Enter a value between $lowerBorder and $upperBorder",
),
Expand Down
9 changes: 4 additions & 5 deletions lib/ui/drawer/nav_drawer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_icons/flutter_icons.dart';
import 'package:mobileraker/app/app_setup.router.dart';
import 'package:mobileraker/dto/machine/printer_setting.dart';
import 'package:mobileraker/ui/drawer/nav_drawer_viewmodel.dart';
import 'package:mobileraker/util/misc.dart';
import 'package:stacked/stacked.dart';

class NavigationDrawerWidget extends StatelessWidget {
Expand All @@ -29,7 +28,7 @@ class NavigationDrawerWidget extends StatelessWidget {
onClicked: () => model.onEditTap(null),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 00),
padding: const EdgeInsets.symmetric(horizontal: 00),
child: Column(
children: [
ExpansionTile(
Expand Down Expand Up @@ -84,7 +83,7 @@ class NavigationDrawerWidget extends StatelessWidget {
if (index == printers.length) {
return ListTile(
title: Text('Add new printer', style: textStyle),
contentPadding: EdgeInsets.only(left: 32, right: 16),
contentPadding: const EdgeInsets.only(left: 32, right: 16),
trailing: Icon(Icons.add, color: highlightColor),
onTap: () => model.navigateTo(Routes.printersAdd),
);
Expand All @@ -100,7 +99,7 @@ class NavigationDrawerWidget extends StatelessWidget {
trailing: Icon(index == 0 ? Icons.check : Icons.arrow_forward_ios_sharp,
color: highlightColor),
selectedTileColor: Colors.white12,
contentPadding: EdgeInsets.only(left: 32, right: 16),
contentPadding: const EdgeInsets.only(left: 32, right: 16),
selected: index == 0,
onTap: () => model.onSetActiveTap(curPS),
onLongPress: () => model.onEditTap(curPS),
Expand All @@ -114,7 +113,7 @@ class NavigationDrawerWidget extends StatelessWidget {
required VoidCallback onClicked,
}) =>
Container(
margin: EdgeInsets.symmetric(vertical: 40, horizontal: 20),
margin: const EdgeInsets.symmetric(vertical: 40, horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/views/files/files_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:mobileraker/app/app_setup.router.dart';
import 'package:mobileraker/dto/files/folder.dart';
import 'package:mobileraker/dto/files/gcode_file.dart';
import 'package:mobileraker/dto/machine/printer.dart';
import 'package:mobileraker/service/file_service.dart';
import 'package:mobileraker/ui/components/connection/connection_state_view.dart';
import 'package:mobileraker/ui/drawer/nav_drawer_view.dart';
Expand Down Expand Up @@ -84,7 +83,7 @@ class FilesView extends ViewModelBuilderWidget<FilesViewModel> {
? theme.colorScheme.secondary
: theme.primaryColor;
return Container(
margin: EdgeInsets.all(4.0),
margin: const EdgeInsets.all(4.0),
color: theme.colorScheme.background,
child: Column(
children: [
Expand All @@ -99,7 +98,7 @@ class FilesView extends ViewModelBuilderWidget<FilesViewModel> {
width: 64,
height: 64,
color: Colors.white,
margin: EdgeInsets.symmetric(vertical: 2),
margin: const EdgeInsets.symmetric(vertical: 2),
),
title: Container(
width: double.infinity,
Expand Down Expand Up @@ -129,7 +128,7 @@ class FilesView extends ViewModelBuilderWidget<FilesViewModel> {
ThemeData theme = Theme.of(context);

return Container(
margin: EdgeInsets.all(4.0),
margin: const EdgeInsets.all(4.0),
color: theme.colorScheme.background,
child: Column(
children: [
Expand Down
43 changes: 43 additions & 0 deletions lib/ui/views/fullcam/full_cam_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_mjpeg/flutter_mjpeg.dart';
import 'package:mobileraker/ui/views/fullcam/full_cam_viewmodel.dart';
import 'package:stacked/stacked.dart';

class FullCamView extends ViewModelBuilderWidget<FullCamViewModel> {
@override
FullCamViewModel viewModelBuilder(BuildContext context) =>
FullCamViewModel();

@override
Widget builder(BuildContext context, FullCamViewModel model, Widget? child) {
return Scaffold(
body: Container(
child: Stack(children: [
Center(
child: InteractiveViewer(
panEnabled: true,
minScale: 1,
maxScale: 10,
child: Transform(
alignment: Alignment.center,
transform: model.transformMatrix,
child: Mjpeg(
isLive: true,
stream: model.selectedCam.url,
)),
),
),
Align(
alignment: Alignment.bottomRight,
child: IconButton(
icon: Icon(Icons.close_fullscreen_outlined),
tooltip: 'Close',
onPressed: model.onCloseTapped,
),
),
]),
),
);
}
}
47 changes: 47 additions & 0 deletions lib/ui/views/fullcam/full_cam_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:mobileraker/app/app_setup.locator.dart';
import 'package:mobileraker/dto/machine/webcam_setting.dart';
import 'package:mobileraker/service/machine_service.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';

class FullCamViewModel extends BaseViewModel {
final _navigationService = locator<NavigationService>();
final _machineService = locator<MachineService>();

WebcamSetting? _camHack() {
var printSetting = _machineService.selectedPrinter.valueOrNull;
if (printSetting != null && printSetting.cams.isNotEmpty) {
return printSetting.cams.first;
}
return null;
}

bool get hasCam => _camHack() != null;

WebcamSetting get selectedCam => _camHack()!;

double get yTransformation {
if (selectedCam.flipHorizontal)
return pi;
else
return 0;
}

double get xTransformation {
if (selectedCam.flipVertical)
return pi;
else
return 0;
}

Matrix4 get transformMatrix => Matrix4.identity()
..rotateX(xTransformation)
..rotateY(yTransformation);

onCloseTapped() {
_navigationService.back();
}
}
2 changes: 1 addition & 1 deletion lib/ui/views/overview/overview_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class OverView extends StatelessWidget {

Color? getActiveTextColor(context) {
var themeData = Theme.of(context);
if (themeData.brightness == Brightness.dark) return themeData.accentColor;
if (themeData.brightness == Brightness.dark) return themeData.colorScheme.secondary;
return Colors.white;
}

Expand Down
Loading

0 comments on commit 8d3380c

Please sign in to comment.