Skip to content

Commit

Permalink
Add Registered Poeple Page
Browse files Browse the repository at this point in the history
  • Loading branch information
sayannath committed Sep 16, 2021
1 parent 298b79b commit a3a961e
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 130 deletions.
6 changes: 5 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Mahindra FaceID"
android:label="Ikshana FaceID"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Empty file added lib/models/User.dart
Empty file.
7 changes: 4 additions & 3 deletions lib/pages/db/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'package:path_provider/path_provider.dart';

class DataBaseService {
// singleton boilerplate
static final DataBaseService _cameraServiceService = DataBaseService._internal();
static final DataBaseService _cameraServiceService =
DataBaseService._internal();

factory DataBaseService() {
return _cameraServiceService;
}

// singleton boilerplate
DataBaseService._internal();

Expand All @@ -17,11 +19,11 @@ class DataBaseService {

/// Data learned on memory
Map<String, dynamic> _db = Map<String, dynamic>();

Map<String, dynamic> get db => this._db;

/// loads a simple json file.
Future loadDB() async {

var tempDir = await getApplicationDocumentsDirectory();
String _embPath = tempDir.path + '/emb.json';

Expand All @@ -40,7 +42,6 @@ class DataBaseService {
jsonFile.writeAsStringSync(json.encode(_db));
}


/// deletes the created users
cleanDB() {
this._db = Map<String, dynamic>();
Expand Down
220 changes: 120 additions & 100 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:FaceNetAuthentication/constants/uiConstants.dart';
import 'package:FaceNetAuthentication/pages/db/database.dart';
import 'package:FaceNetAuthentication/pages/peopleScreen.dart';
import 'package:FaceNetAuthentication/pages/sign-in.dart';
import 'package:FaceNetAuthentication/pages/sign-up.dart';
import 'package:FaceNetAuthentication/services/facenet.service.dart';
import 'package:FaceNetAuthentication/services/ml_vision_service.dart';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}
Expand All @@ -26,6 +29,7 @@ class _MyHomePageState extends State<MyHomePage> {
void initState() {
super.initState();
_startUp();
_getLocation();
}

/// 1 Obtain a list of the available cameras on the device.
Expand Down Expand Up @@ -56,115 +60,131 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

_getLocation() async {
bool serviceEnabled;
LocationPermission permission;
permission = await Geolocator.checkPermission();
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
print(position.toString());
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
actions: [
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Image.asset('assets/images/logo_mahindra.png'),
)
],
),
body: !loading
? Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Text('Face Recognition System',
style: Theme.of(context)
.primaryTextTheme
.headline6
.copyWith(
fontSize: 23,
color: Color(0xff25354E),
fontWeight: FontWeight.bold)),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
'This app helps to\nAuthenticate Users by using\nFace Recognition',
style: TextStyle(color: Color(0xff878787)),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
actions: [
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Image.asset('assets/images/logo_mahindra.png'),
)
],
),
body: !loading
? Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Text('Face Recognition System',
style: Theme.of(context)
.primaryTextTheme
.headline6
.copyWith(
fontSize: 23,
color: Color(0xff25354E),
fontWeight: FontWeight.bold)),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Text(
'Ikshana',
style: TextStyle(color: Color(0xff878787)),
),
Image.asset(
'assets/images/login.png',
height: UIConstants.fitToHeight(360, context),
width: UIConstants.fitToWidth(360, context),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.11,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: UIConstants.fitToWidth(100, context),
child: RaisedButton(
padding:
const EdgeInsets.symmetric(vertical: 16),
child: Text('Sign In',
style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SignIn(
cameraDescription: cameraDescription,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Image.asset(
'assets/images/login.png',
height: UIConstants.fitToHeight(360, context),
width: UIConstants.fitToWidth(360, context),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.11,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: UIConstants.fitToWidth(100, context),
child: RaisedButton(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Text('Sign In',
style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SignIn(
cameraDescription: cameraDescription,
),
);
},
),
),
);
},
),
SizedBox(
width: UIConstants.fitToWidth(100, context),
child: RaisedButton(
padding:
const EdgeInsets.symmetric(vertical: 16),
child: Text('Sign Up',
style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SignUp(
cameraDescription: cameraDescription,
),
),
SizedBox(
width: UIConstants.fitToWidth(100, context),
child: RaisedButton(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Text('Sign Up',
style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SignUp(
cameraDescription: cameraDescription,
),
);
},
),
)
],
)
],
),
),
);
},
),
)
],
)
],
),
),
)
: Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Color(0xff25354E),
),
),
)
: Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Color(0xff25354E),
),
));
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => PeopleScreen()));
},
backgroundColor: Color(0xff25354E),
child: Icon(Icons.data_usage),
),
);
}
}
89 changes: 89 additions & 0 deletions lib/pages/peopleScreen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:FaceNetAuthentication/pages/db/database.dart';
import 'package:flutter/material.dart';

class PeopleScreen extends StatefulWidget {
@override
_PeopleScreenState createState() => _PeopleScreenState();
}

class _PeopleScreenState extends State<PeopleScreen> {
bool isLoading = false;
DataBaseService dataBaseService = DataBaseService();

List<String> names = [];

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

loadDatabase() async {
setState(() {
isLoading = true;
});
dataBaseService.loadDB();
// print(dataBaseService.db);
var people = dataBaseService.db.forEach((key, value) {
var person = key.toString().split(':');
names.add(person[0]);
});

print(names);
setState(() {
isLoading = false;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Registered People'),
brightness: Brightness.dark,
),
body: isLoading
? CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Color(0xff25354E),
),
)
: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: dataBaseService.db.length == 0 ||
dataBaseService.db.length == null
? Center(
child: Text(
'No one is registered!',
style: TextStyle(color: Colors.black, fontSize: 20),
))
: ListView.builder(
itemCount: dataBaseService.db.length,
shrinkWrap: true,
itemBuilder: (_, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Text(
'${index + 1}.',
style: TextStyle(
color: Colors.black, fontSize: 18),
),
SizedBox(
width: 4.0,
),
Text(
names[index],
style: TextStyle(
color: Colors.black, fontSize: 18),
),
],
),
);
}),
),
);
}
}
Loading

0 comments on commit a3a961e

Please sign in to comment.