class login extends StatefulWidget {
const login({Key? key}) : super(key: key);
@OverRide
State createState() => _loginState();
}
const kTextFieldDecoration = InputDecoration(
hintText: 'Enter a value',
hintStyle: TextStyle(color: Colors.grey),
contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.lightBlueAccent, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.lightBlueAccent, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
);
class _loginState extends State {
//final _passwordController = TextEditingController();
//String? _passwordError;
final formKey = GlobalKey();
//final _navKey = GlobalKey();
final _auth = FirebaseAuth.instance;
bool showSpinner = false;
// final _emailController = TextEditingController();
// String? _emailError;
void initstate(){
initstate();
requestPermission();
//getToken();
initInfo();
}
FlutterLocalNotificationsPlugin
flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
initInfo() async {
var androidInitialize = const AndroidInitializationSettings(
"@mipmap/ic_launcher");
var iosInitialize = const IOSInitializationSettings(
requestSoundPermission: false,
requestBadgePermission: false,
requestAlertPermission: false,
//onDidReceiveLocalNotification: false
);
final InitializationSettings initializationSettings = InitializationSettings(
android: androidInitialize,
iOS: iosInitialize,
);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onSelectNotification: (String? payload) async {
try {
if (payload != null && payload.isNotEmpty) {
} else {}
} catch (e) {
}
return;
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
print("............onMessage............");
print("onMessage:${message.notification?.title}/${message.notification
?.body}}");
BigTextStyleInformation bigTextStyleInformation = BigTextStyleInformation(
message.notification!.body.toString(),
htmlFormatBigText: true,
contentTitle: message.notification!.title.toString(),
htmlFormatContentTitle: true,
);
AndroidNotificationDetails androidPlatformChannelSpecifcs
= AndroidNotificationDetails('User1', "User", importance: Importance.max,
styleInformation: bigTextStyleInformation,
priority: Priority.max,
playSound: false);
});
var message;
var androidPlatformChannelSpecifics;
NotificationDetails platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: const IOSNotificationDetails()
);
await flutterLocalNotificationsPlugin.show(
0,
"title",
message.notification?.body,
platformChannelSpecifics as NotificationDetails?,
payload: message.data['title']);
}
FuturerequestPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
//authorizationStatus: authorizationStatus,
badge: true,
carPlay: false,
criticalAlert: false,
sound: true);
if(settings.authorizationStatus == AuthorizationStatus.authorized){
print("user granted permission");
}else if(settings.authorizationStatus == AuthorizationStatus.provisional) {
print("User granted provisonal permission");
}else{
print('user declined or hasnot accepted permission');
}
}
String? mtoken = "";
static const users = const {
'[email protected]': '123545',
'[email protected]': 'hunter'
};
Duration get loginTime => Duration(milliseconds: 2250);
Future<String?> authUser(LoginData data) {
debugPrint('Name: ${data.name},'
'Password: ${data.password}');
return Future.delayed(loginTime).then(() {
if (!users.containsKey(data.name)) {
return 'User not exists';
}
if (users[data.name] != data.password) {
return 'Password doesnot match';
}
return null;
});
}
Future<String?> signupUser(SignupData data) {
debugPrint('sign up: ${data.name},Password: ${data.password}');
return Future.delayed(loginTime).then(() =>
null
);
}
void saveToken(String token) async {
await FirebaseFirestore.instance.collection("UserTokens")
.doc("User1").set({
"token": token
});
}
Future<String?> recoverPassword(String name) {
debugPrint('Name: $name');
return Future.delayed(loginTime).then(() {
if (!users.containsKey(name)) {
return 'User doesnot exist';
}
return null;
});
}
void getToken() async {
await FirebaseMessaging.instance.getToken().then(
(token) {
setState(() {
mtoken = token;
if (kDebugMode) {
print("My token is $mtoken");
}
});
saveToken(token!);
}
);
}
static const String routeName = '/list_screen';
//final navKey = GlobalKey();
static int selectedCategory = 0;
static Route route(Map<String, dynamic> args) {
return MaterialPageRoute(
builder: () => login(),
settings: RouteSettings(name: routeName),
);
}
late String email;
late String password;
/** List lists = List.generate(categories.length,
(index) => CategoryItem(
data: categories[index],
selected: index == selectedCategory,));**/
@OverRide
Widget build(BuildContext context) {
final propertyProvider = context.watch();
//var user = Provider.of(context);
final asyncValueOfProps = propertyProvider.asyncValueOfProps;
return Scaffold(
backgroundColor: Colors.white,
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.0
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(
hintText: 'Enter your email')),
SizedBox(height: 4,),
TextField( obscureText: true,
textAlign: TextAlign.center,
onChanged: (value) {
password = value;
//Do something with the user input.
},
decoration: kTextFieldDecoration.copyWith(
hintText: 'Enter your Password')),
SizedBox(
height: 24.0,
),
ElevatedButton(
// statesController: ,
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final newUser = await _auth
.createUserWithEmailAndPassword(
email: email, password: password);
if (newUser != null) {
Navigator.pushNamed(context, 'home_screen');
}
} catch (e) {
print(e);
}
setState(() {
showSpinner = false;
},
);
}, child: const Text("Sign up",
style: CupertinoTextField.cupertinoMisspelledTextStyle,),),
], ),
),
);
}
}
that is my class
for a login page
below is the error message