|
|
|
import 'dart:collection';
|
|
|
|
import 'dart:ffi';
|
|
|
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
|
|
import 'package:local_auth/local_auth.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
DrAppSharedPreferances SharedPref = new DrAppSharedPreferances();
|
|
|
|
|
|
|
|
class KnownUserLogin extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_KnownUserLoginState createState() => _KnownUserLoginState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _KnownUserLoginState extends State<KnownUserLogin> {
|
|
|
|
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
|
|
|
final LocalAuthentication auth = LocalAuthentication();
|
|
|
|
String _authorized = "not Authorized";
|
|
|
|
bool _isAuthenticating = false;
|
|
|
|
Future<String> loggedUserFuture;
|
|
|
|
var loggedUser;
|
|
|
|
Future<void> getSharedPref() async {
|
|
|
|
SharedPref.getObj('loggedUser').then((userInfo) {
|
|
|
|
// if(loggedUser == null){}
|
|
|
|
loggedUser = userInfo;
|
|
|
|
// print('dddddddddddddddd${loggedUser}');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
loggedUserFuture = _prefs.then((SharedPreferences prefs) {
|
|
|
|
return (prefs.getString('platformImei'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
getSharedPref();
|
|
|
|
|
|
|
|
return FutureBuilder(
|
|
|
|
future: loggedUserFuture,
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
|
|
|
switch (snapshot.connectionState) {
|
|
|
|
case ConnectionState.waiting:
|
|
|
|
return DrAppCircularProgressIndeicator();
|
|
|
|
default:
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Text('Error: ${snapshot.error}');
|
|
|
|
} else {
|
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (ctx, constraints) {
|
|
|
|
int maxSmallScreenSize = MAX_SMALL_SCREEN;
|
|
|
|
bool isSmallScreen =
|
|
|
|
constraints.maxWidth <= maxSmallScreenSize;
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Stack(children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: Hexcolor('#CCCCCC'),
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(50)),
|
|
|
|
margin: const EdgeInsets.fromLTRB(0, 20.0, 30, 0),
|
|
|
|
child: Row(
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
height: 100,
|
|
|
|
width: 100,
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
// color: Colors.green, // border color
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
border: Border.all(
|
|
|
|
color: Hexcolor('#CCCCCC'))),
|
|
|
|
child: CircleAvatar(
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/dr_avatar.png',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.symmetric(
|
|
|
|
vertical: 3, horizontal: 15),
|
|
|
|
child: Column(
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
loggedUser['List_MemberInformation'][0]
|
|
|
|
['MemberName'],
|
|
|
|
style: TextStyle(
|
|
|
|
color: Hexcolor('515A5D'),
|
|
|
|
fontSize: isSmallScreen
|
|
|
|
? 24
|
|
|
|
: constraints.maxWidth * 0.029,
|
|
|
|
fontWeight: FontWeight.w800),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'ENT Spec',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Hexcolor('515A5D'),
|
|
|
|
fontSize: isSmallScreen
|
|
|
|
? 20
|
|
|
|
: constraints.maxWidth * 0.025),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
top: 7,
|
|
|
|
right: 70,
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/close_icon.png',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
))
|
|
|
|
]),
|
|
|
|
Container(
|
|
|
|
height: 200,
|
|
|
|
width: 200,
|
|
|
|
child: Center(
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/images/verification_fingerprint_lg_icon.png',
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
buildButtonsContainer(
|
|
|
|
isSmallScreen, constraints, context)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
Container buildButtonsContainer(
|
|
|
|
bool isSmallScreen, BoxConstraints constraints, BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsetsDirectional.fromSTEB(0, 0, 30, 0),
|
|
|
|
width: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
RaisedButton(
|
|
|
|
onPressed:_authenticate,
|
|
|
|
elevation: 0.0,
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 50,
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
"Verify using FingerPRint ${_authorized}".toUpperCase(),
|
|
|
|
// textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize:
|
|
|
|
isSmallScreen ? 20 : constraints.maxWidth * 0.029),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
side: BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 50,
|
|
|
|
child: FlatButton(
|
|
|
|
onPressed: () {
|
|
|
|
navigateToMoreOption();
|
|
|
|
},
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
side: BorderSide(
|
|
|
|
width: 1, color: Theme.of(context).primaryColor)),
|
|
|
|
child: Text(
|
|
|
|
"More verification Options".toUpperCase(),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontSize:
|
|
|
|
isSmallScreen ? 20 : constraints.maxWidth * 0.029),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
navigateToMoreOption() {
|
|
|
|
Navigator.of(context).pushNamed('routeName');
|
|
|
|
}
|
|
|
|
|
|
|
|
silentLogin() {
|
|
|
|
_authenticate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _authenticate() async {
|
|
|
|
_getAvailableBiometrics();
|
|
|
|
bool authenticated = false;
|
|
|
|
try {
|
|
|
|
setState(() {
|
|
|
|
_isAuthenticating = true;
|
|
|
|
_authorized = 'Authenticating';
|
|
|
|
});
|
|
|
|
authenticated = await auth.authenticateWithBiometrics(
|
|
|
|
localizedReason: 'Scan your fingerprint to authenticate',
|
|
|
|
useErrorDialogs: true,
|
|
|
|
stickyAuth: true);
|
|
|
|
setState(() {
|
|
|
|
_isAuthenticating = false;
|
|
|
|
_authorized = 'Authenticating';
|
|
|
|
});
|
|
|
|
} on PlatformException catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
final String message = authenticated ? 'Authorized' : 'Not Authorized';
|
|
|
|
setState(() {
|
|
|
|
print('_authorized'+_authorized);
|
|
|
|
_authorized = message;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _getAvailableBiometrics() async {
|
|
|
|
List<BiometricType> availableBiometrics;
|
|
|
|
try {
|
|
|
|
availableBiometrics = await auth.getAvailableBiometrics();
|
|
|
|
} on PlatformException catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
print('availableBiometrics $availableBiometrics');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|