Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protected mode #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'domain/sentry.dart';
import 'models/connection_model.dart';
import 'pages/config_page.dart';
import 'pages/joystick_page.dart';
import 'pages/pin_page.dart';
// ignore: unused_import
import 'theme.dart';

Expand Down Expand Up @@ -38,6 +39,9 @@ class UrsaApp extends StatelessWidget {
// bool isDarkMode =
// MediaQuery.of(context).platformBrightness == Brightness.dark;

// TODO: get pin from storage
String? pin = '1234';

return DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
// lightDynamic = lightDynamic?.copyWith(
Expand All @@ -57,6 +61,8 @@ class UrsaApp extends StatelessWidget {
routes: {
'/': (context) => const JoystickPage(),
'/config': (context) => const ConfigPage(),
'/config-auth': (context) =>
pin == null ? const ConfigPage() : PinputPage(pin: pin),
},
);
},
Expand Down
11 changes: 7 additions & 4 deletions lib/pages/joystick_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_joystick/flutter_joystick.dart' as joystick;
import 'package:provider/provider.dart';
import 'package:universal_platform/universal_platform.dart';

import '../components/enable.dart';
import '../components/joystick/joystick.dart';
Expand Down Expand Up @@ -75,7 +75,7 @@ class JoystickPageState extends State<JoystickPage> {
@override
Widget build(BuildContext context) {
// ModelViewer is not supported on desktop (yet)
bool showModelViewer = Platform.isAndroid || Platform.isIOS || kIsWeb;
bool showModelViewer = UniversalPlatform.isAndroid || UniversalPlatform.isIOS || UniversalPlatform.isWeb;
// bool showModelViewer = false;

return Scaffold(
Expand All @@ -87,7 +87,7 @@ class JoystickPageState extends State<JoystickPage> {
tooltip: 'Open settings',
onPressed: () {
// navigate to config_page
Navigator.pushNamed(context, '/config');
Navigator.pushNamed(context, '/config-auth');
},
),
],
Expand Down Expand Up @@ -148,7 +148,10 @@ class JoystickPageState extends State<JoystickPage> {
const SizedBox(height: 10),
SlideToEnable(
height: clampDouble(
constraints.maxHeight / 4, 50, 70,),
constraints.maxHeight / 4,
50,
70,
),
enabled: _isEnabled,
onStateChange: (value) {
setEnabledCommand(value);
Expand Down
160 changes: 160 additions & 0 deletions lib/pages/pin_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import 'package:flutter/material.dart';
import 'package:pinput/pinput.dart';

class PinputPage extends StatelessWidget {
final String pin;

const PinputPage({Key? key, required this.pin}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
PinputExample(pin: pin),
],
),
);
}
}

/// This is the basic usage of Pinput
/// For more examples check out the demo directory
class PinputExample extends StatefulWidget {
final String pin;

const PinputExample({Key? key, required this.pin}) : super(key: key);

@override
State<PinputExample> createState() => PinputExampleState();
}

class PinputExampleState extends State<PinputExample> {
final pinController = TextEditingController();
final focusNode = FocusNode();
final formKey = GlobalKey<FormState>();

@override
void initState() {
super.initState();

focusNode.requestFocus();
}

@override
void dispose() {
pinController.dispose();
focusNode.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
const focusedBorderColor = Color.fromRGBO(23, 171, 144, 1);
const fillColor = Color.fromRGBO(243, 246, 249, 0);
const borderColor = Color.fromRGBO(23, 171, 144, 0.4);

final defaultPinTheme = PinTheme(
width: 56,
height: 56,
textStyle: const TextStyle(
fontSize: 22,
color: Color.fromRGBO(30, 60, 87, 1),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(19),
border: Border.all(color: borderColor),
),
);

/// Optionally you can use form to validate the Pinput
return Form(
key: formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Directionality(
// Specify direction if desired
textDirection: TextDirection.ltr,
child: Pinput(
controller: pinController,
focusNode: focusNode,
defaultPinTheme: defaultPinTheme,
obscureText: true,
closeKeyboardWhenCompleted: false,
hapticFeedbackType: HapticFeedbackType.lightImpact,
onCompleted: checkAuth,
cursor: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.only(bottom: 9),
width: 22,
height: 1,
color: focusedBorderColor,
),
],
),
focusedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: focusedBorderColor),
),
),
submittedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
color: fillColor,
borderRadius: BorderRadius.circular(19),
border: Border.all(color: focusedBorderColor),
),
),
errorPinTheme: defaultPinTheme.copyBorderWith(
border: Border.all(color: Colors.redAccent),
),
),
),
],
),
);
}

void checkAuth(String pin) {
if (validatePin(pin)) {
debugPrint('Success');

// Navigate to config page
Navigator.of(context).pushReplacementNamed('/config');
} else {
debugPrint('Invalid pin');

// Show invalid PIN dialog
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Invalid PIN'),
content: const Text('Please try again'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
);
},
);

setState(() {
pinController.clear();
});
}
}

bool validatePin(String pin) {
return pin == widget.pin;
}
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <dynamic_color/dynamic_color_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <smart_auth/smart_auth_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
Expand All @@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) sentry_flutter_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin");
sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar);
g_autoptr(FlPluginRegistrar) smart_auth_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SmartAuthPlugin");
smart_auth_plugin_register_with_registrar(smart_auth_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
sentry_flutter
smart_auth
url_launcher_linux
)

Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dynamic_color
import package_info_plus
import sentry_flutter
import shared_preferences_foundation
import smart_auth
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand All @@ -18,5 +19,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
26 changes: 25 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.4.0"
pinput:
dependency: "direct main"
description:
name: pinput
sha256: "1773743c188cdd2f8d0398ea708ec72645bb41ac9311755c4f7bb03a4184bdcf"
url: "https://pub.dev"
source: hosted
version: "2.2.31"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -427,6 +435,14 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
smart_auth:
dependency: transitive
description:
name: smart_auth
sha256: "8cfaec55b77d5930ed1666bb7ae70db5bade099bb1422401386853b400962113"
url: "https://pub.dev"
source: hosted
version: "1.0.8"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -483,6 +499,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
universal_platform:
dependency: "direct main"
description:
name: universal_platform
sha256: d315be0f6641898b280ffa34e2ddb14f3d12b1a37882557869646e0cc363d0cc
url: "https://pub.dev"
source: hosted
version: "1.0.0+1"
url_launcher:
dependency: transitive
description:
Expand Down Expand Up @@ -621,4 +645,4 @@ packages:
version: "6.3.0"
sdks:
dart: ">=3.0.2 <4.0.0"
flutter: ">=3.4.0-17.0.pre"
flutter: ">=3.7.0"
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ dependencies:
sentry_flutter: ^7.7.0
app_settings: ^4.2.0
dynamic_color: ^1.6.5
pinput: ^2.2.31
universal_platform: ^1.0.0+1

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <smart_auth/smart_auth_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
Expand All @@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
SentryFlutterPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SentryFlutterPlugin"));
SmartAuthPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SmartAuthPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
dynamic_color
sentry_flutter
smart_auth
url_launcher_windows
)

Expand Down