Skip to content

Commit

Permalink
major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Illusion47586 committed Apr 10, 2021
1 parent 6d74e04 commit a0cb38a
Show file tree
Hide file tree
Showing 10 changed files with 548 additions and 315 deletions.
4 changes: 4 additions & 0 deletions lib/common/value_notifiers.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Flutter imports:
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// Project imports:
import '../model/position.dart';

ValueNotifier<String> foundText = ValueNotifier<String>("searching");
ValueNotifier<bool> hasStarted = ValueNotifier<bool>(false);
ValueNotifier<double> lastRecorded = ValueNotifier<double>(null);

ValueNotifier<int> counter = ValueNotifier<int>(0);
ValueNotifier<Position> position = ValueNotifier<Position>(
Expand Down
2 changes: 2 additions & 0 deletions lib/functions/ball_position.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Dart imports:
import 'dart:math';
import 'dart:ui';

// Project imports:
import '../model/position.dart';

Position getBallPosition({Size size, double ballSize}) {
Expand Down
19 changes: 14 additions & 5 deletions lib/functions/face_detector.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Dart imports:
import 'dart:ui';

// Package imports:
import 'package:camera/camera.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';

// Project imports:
import '../common/value_notifiers.dart';
import '../model/data.dart';

Future<Offset> foundImage(CameraImage image) async {
Future<dynamic> foundImage(CameraImage image) async {
final FirebaseVisionImageMetadata metadata = FirebaseVisionImageMetadata(
rawFormat: image.format.raw,
size: Size(
Expand Down Expand Up @@ -43,16 +46,22 @@ Future<Offset> foundImage(CameraImage image) async {
if (faces.length > 0) {
Offset nosePosition =
faces[0].getLandmark(FaceLandmarkType.noseBase).position;
// The nose is in the viscinity of the dot and we record the time
if (((nosePosition.dx - position.value.x).abs() <= 250) &&
((nosePosition.dy - position.value.y).abs() <= 250)) {

/// The [nose] is in the `viscinity of the dot` and we record the time
int noticeRadius = 200;
if (((nosePosition.dx - position.value.x).abs() <= noticeRadius) &&
((nosePosition.dy - position.value.y).abs() <= noticeRadius)) {
Duration duration = position.value.time.difference(DateTime.now());
if ((counter.value - 1) >= 0 && data[counter.value - 1] == 0)
data[counter.value - 1] = duration.inMilliseconds.abs().floorToDouble();
foundText.value = "Focus on the green dot.";
if (counter.value > 15) foundText.value = "Your latency is $avg ms.";
}
return nosePosition;
} else
} else {
foundText.value = "No one is there.";
if ((counter.value - 1) >= 0 && data[counter.value - 1] == 0)
data[counter.value - 1] = -1;
}
}
84 changes: 65 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,88 @@
// Dart imports:
import 'dart:async';

import 'package:camera/camera.dart';
// Flutter imports:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

// Package imports:
import 'package:camera/camera.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_statusbar_manager/flutter_statusbar_manager.dart';

// Project imports:
import 'view/home_screen.dart';

class MyBehavior extends ScrollBehavior {
@override
Widget buildViewportChrome(
BuildContext context, Widget child, AxisDirection axisDirection) {
return child;
}
}

List<CameraDescription> cameras;

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.white,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.light,
systemNavigationBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.dark,
),
await FlutterStatusbarManager.setStyle(StatusBarStyle.DARK_CONTENT);
await FlutterStatusbarManager.setColor(
Colors.transparent,
animated: true,
);
await FlutterStatusbarManager.setNavigationBarColor(
Colors.transparent,
animated: true,
);
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.black,
accentColor: Color(0xffF92B5C),
backgroundColor: Colors.white,
visualDensity: VisualDensity.adaptivePlatformDensity,
fontFamily: 'metropolis',
brightness: Brightness.light,
return ScreenUtilInit(
designSize: Size(1080, 1920),
allowFontScaling: true,
builder: () => MaterialApp(
theme: ThemeData(
primaryColor: Colors.black,
accentColor: Color(0xffF92B5C),
backgroundColor: Colors.white,
visualDensity: VisualDensity.adaptivePlatformDensity,
fontFamily: 'metropolis',
brightness: Brightness.light,
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.black),
foregroundColor: MaterialStateProperty.all(Colors.white),
padding: MaterialStateProperty.all(
EdgeInsets.symmetric(vertical: 15, horizontal: 25),
),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
alignment: Alignment.center,
enableFeedback: true,
elevation: MaterialStateProperty.all(20),
shadowColor: MaterialStateProperty.all(Colors.black12),
),
),
),
home: Home(cameras: cameras),
debugShowCheckedModeBanner: false,
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 0.9),
child: ScrollConfiguration(
behavior: MyBehavior(),
child: child,
),
);
},
),
home: Home(cameras: cameras),
debugShowCheckedModeBanner: false,
);
}
}
147 changes: 54 additions & 93 deletions lib/view/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:auto_size_text/auto_size_text.dart';
import 'package:boxicons_flutter/boxicons_flutter.dart';
import 'package:camera/camera.dart';
import '../model/data.dart';
import 'package:flutter/material.dart';
import 'package:share/share.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// Project imports:
import '../common/value_notifiers.dart';
import 'widgets/appbar.dart';
import 'widgets/camera.dart';

class Home extends StatelessWidget {
Expand All @@ -16,102 +19,60 @@ class Home extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
padding: EdgeInsets.fromLTRB(
40,
30,
40,
40,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyAppBar(),
SizedBox(height: 5),
AutoSizeText(
"Focus your nose on the crosshair",
style: TextStyle(
color: Theme.of(context).accentColor,
fontFamily: "metropolis",
fontSize: 20,
fontWeight: FontWeight.w700,
height: 1.3,
),
maxLines: 1,
textAlign: TextAlign.start,
),
AutoSizeText(
"and then follow the green dot with your head.",
style: TextStyle(
color: Colors.black,
fontFamily: "metropolis",
fontSize: 20,
fontWeight: FontWeight.w500,
height: 1.1,
),
textAlign: TextAlign.start,
maxLines: 1,
),
SizedBox(height: 5),
CameraWidget(cameras: cameras),
SizedBox(height: 5),
ValueListenableBuilder(
valueListenable: foundText,
builder: (context, value, w) {
return Text(
value,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 80.h,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(height: 80.h),
MyAppBar(),
AutoSizeText.rich(
TextSpan(
text: "Focus your nose on the crosshair\n",
style: TextStyle(
fontSize: 15,
color: Theme.of(context).accentColor,
fontFamily: "metropolis",
fontSize: 20,
fontWeight: FontWeight.w700,
height: 1.5,
),
);
},
),
],
),
),
),
);
}
}

class MyAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
text: "Dizzy\n",
style: TextStyle(
color: Colors.black,
fontFamily: "metropolis",
fontWeight: FontWeight.w400,
fontSize: 40,
height: 1.1,
),
children: [
TextSpan(
text: "Check",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 45,
children: [
TextSpan(
text: "and then follow the green dot with your head.",
style: TextStyle(
color: Colors.black,
fontFamily: "metropolis",
fontSize: 17,
fontWeight: FontWeight.w500,
height: 1.3,
),
),
],
),
),
SizedBox(height: 60.h),
CameraWidget(cameras: cameras),
SizedBox(height: 60.h),
ValueListenableBuilder(
valueListenable: foundText,
builder: (context, value, w) {
return Text(
"Debug text: $value",
style: TextStyle(
fontSize: 15,
),
);
},
),
SizedBox(height: 80.h),
],
),
),
IconButton(
icon: Icon(
Boxicons.bxShareAlt,
size: 30,
),
onPressed: () {
Share.share('My latency is $avg ms.');
},
),
],
),
),
);
}
Expand Down
54 changes: 54 additions & 0 deletions lib/view/widgets/appbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:boxicons_flutter/boxicons_flutter.dart';
import 'package:share/share.dart';

// Project imports:
import '../../model/data.dart';

class MyAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: "Dizzy\n",
style: TextStyle(
color: Colors.black,
fontFamily: "metropolis",
fontWeight: FontWeight.w400,
fontSize: 40,
height: 1.1,
),
children: [
TextSpan(
text: "Check",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 45,
),
),
],
),
),
IconButton(
icon: Icon(
Boxicons.bxShareAlt,
size: 30,
),
iconSize: 30,
padding: EdgeInsets.all(12),
color: Colors.black,
onPressed: () {
Share.share('My latency is $avg ms.');
},
),
],
);
}
}
Loading

0 comments on commit a0cb38a

Please sign in to comment.