Add local_auth to auth with fingerprint
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
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.USE_FINGERPRINT" />
|
||||
<application
|
||||
android:name="io.flutter.app.FlutterApplication"
|
||||
android:label="como_gasto"
|
||||
|
||||
@@ -2,10 +2,10 @@ package ar.com.p39.como_gasto
|
||||
|
||||
import android.os.Bundle
|
||||
|
||||
import io.flutter.app.FlutterActivity
|
||||
import io.flutter.app.FlutterFragmentActivity
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
class MainActivity: FlutterFragmentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
GeneratedPluginRegistrant.registerWith(this)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:charts_flutter/flutter.dart';
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flare_dart/actor.dart';
|
||||
|
||||
class LoginState with ChangeNotifier {
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn();
|
||||
|
||||
+70
-29
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
|
||||
import '../expenses_repository.dart';
|
||||
|
||||
@@ -30,10 +31,20 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
|
||||
File _selectedPicture;
|
||||
|
||||
LocalAuthentication _localAth;
|
||||
bool _isBiometricAvailable = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_localAth = LocalAuthentication();
|
||||
_localAth.canCheckBiometrics.then((b) {
|
||||
setState(() {
|
||||
_isBiometricAvailable = b;
|
||||
});
|
||||
});
|
||||
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: Duration(milliseconds: 750),
|
||||
@@ -59,17 +70,15 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var h = MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.height;
|
||||
var h = MediaQuery.of(context).size.height;
|
||||
return Stack(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: Offset(0, h * (1 - _pageAnimation.value)),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: BackButton(
|
||||
leading: IconButton(
|
||||
icon: BackButtonIcon(),
|
||||
color: Colors.grey,
|
||||
onPressed: () {
|
||||
_controller.reverse();
|
||||
@@ -92,13 +101,15 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now().subtract(Duration(hours: 24*30)),
|
||||
firstDate:
|
||||
DateTime.now().subtract(Duration(hours: 24 * 30)),
|
||||
lastDate: DateTime.now(),
|
||||
).then((newDate) {
|
||||
if (newDate != null) {
|
||||
setState(() {
|
||||
date = newDate;
|
||||
dateStr = "${date.year.toString()}-${date.month.toString().padLeft(2,'0')}-${date.day.toString().padLeft(2,'0')}";
|
||||
dateStr =
|
||||
"${date.year.toString()}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}";
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -108,7 +119,8 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
icon: Icon(Icons.camera_alt),
|
||||
color: Colors.grey,
|
||||
onPressed: () async {
|
||||
var image = await ImagePicker.pickImage(source: ImageSource.camera);
|
||||
var image =
|
||||
await ImagePicker.pickImage(source: ImageSource.camera);
|
||||
|
||||
setState(() {
|
||||
_selectedPicture = image;
|
||||
@@ -126,10 +138,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
}
|
||||
|
||||
Widget _body() {
|
||||
var h = MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.height;
|
||||
var h = MediaQuery.of(context).size.height;
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
_categorySelector(),
|
||||
@@ -264,10 +273,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
Widget _submit() {
|
||||
if (_controller.value < 1) {
|
||||
var buttonWidth = widget.buttonRect.right - widget.buttonRect.left;
|
||||
var w = MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.width;
|
||||
var w = MediaQuery.of(context).size.width;
|
||||
|
||||
return Positioned(
|
||||
left: widget.buttonRect.left * (1 - _buttonAnimation.value),
|
||||
@@ -277,10 +283,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
top: widget.buttonRect.top,
|
||||
//<-- Margin from top
|
||||
bottom:
|
||||
(MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.height - widget.buttonRect.bottom) *
|
||||
(MediaQuery.of(context).size.height - widget.buttonRect.bottom) *
|
||||
(1 - _buttonAnimation.value),
|
||||
//<-- Margin from bottom
|
||||
child: Container(
|
||||
@@ -292,6 +295,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
color: Colors.blueAccent,
|
||||
),
|
||||
child: MaterialButton(
|
||||
onPressed: () {},
|
||||
child: Text(
|
||||
"Add expense",
|
||||
style: TextStyle(
|
||||
@@ -312,24 +316,56 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
return Container(
|
||||
decoration: BoxDecoration(color: Colors.blueAccent),
|
||||
child: MaterialButton(
|
||||
child: Text(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
"Add expense",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_isBiometricAvailable)
|
||||
Icon(
|
||||
Icons.fingerprint,
|
||||
color: Colors.white,
|
||||
size: 30.0,
|
||||
)
|
||||
],
|
||||
),
|
||||
onPressed: () async {
|
||||
var db = Provider.of<ExpensesRepository>(context);
|
||||
if (value > 0 && category != "") {
|
||||
db.add(category, value / 100.0, date, _selectedPicture);
|
||||
|
||||
_controller.reverse();
|
||||
if (_isBiometricAvailable) {
|
||||
bool didAuthenticate = await _localAth.authenticateWithBiometrics(
|
||||
localizedReason: "Please identify yourself!",
|
||||
);
|
||||
if (didAuthenticate) {
|
||||
_saveAndBack(db);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
AlertDialog(
|
||||
builder: (context) => AlertDialog(
|
||||
content: Text(
|
||||
"You need to identify yourself."),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('Ok'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
} else {
|
||||
_saveAndBack(db);
|
||||
}
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Text(
|
||||
"You need to select a category and a value greater than zero."),
|
||||
actions: <Widget>[
|
||||
@@ -340,8 +376,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
);
|
||||
));
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -350,4 +385,10 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_saveAndBack(ExpensesRepository db) {
|
||||
db.add(category, value / 100.0, date, _selectedPicture);
|
||||
|
||||
_controller.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flare_flutter/flare_actor.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flare_dart/actor.dart';
|
||||
|
||||
import '../login_state.dart';
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DayExpenseListTile extends StatelessWidget {
|
||||
|
||||
@@ -186,6 +186,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.8"
|
||||
local_auth:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: local_auth
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -25,6 +25,7 @@ dependencies:
|
||||
firebase_storage: ^3.0.8
|
||||
image_picker: ^0.6.1+11
|
||||
uuid:
|
||||
local_auth: ^0.6.1
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
|
||||
Reference in New Issue
Block a user