my database suddenly stopped working, i created an app till yesterday it was logging in but suddenly it stopped working its not logging in it keeps coming invalid password or username,I havent made any changes to the code as well nor did I touch the DB i will share a part of my code logic for retreival of the username and password from the db im using flutter with dart.
I’ve even doubled checked the data everything i never made any changes
I’ve tried making a new db still not working,tried restarting,changed the device as well for testing,uninstall and reinstalled the app as well
void _initDatabase() async {
try {
_database = await openDatabase(
join('G:/hello', 'my_database.db'),
version: 1,
onCreate: (db, version) async {
await db.execute(
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, password TEXT, user_type TEXT)',
);
await db.execute(
'CREATE TABLE IF NOT EXISTS user_details (user_id INTEGER, shift TEXT, shift_code TEXT, FOREIGN KEY(user_id) REFERENCES users(id))',
);
},
);
} catch (e) {
print("Error initializing database: $e");
}
}
Future<Map<String, dynamic>?> _getUserDetails(String username) async {
final List<Map<String, dynamic>> users = await _database.query(
'users',
where: 'username = ?',
whereArgs: [username],
);
return users.isNotEmpty ? users.first : null;
}
ElevatedButton(
onPressed: () async {
final String username = _usernameController.text;
final String password = _passwordController.text;
final bool isLoggedIn = await _checkUser(username, password);
if (isLoggedIn) {
final userDetails = await _getUserDetails(username);
if (userDetails != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UserInfoPage(
userId: userDetails['id'].toString(),
shift: userDetails['shift'].toString(),
shiftCode: userDetails['shift_code'].toString(),
isGL: userDetails['user_type'] == 'GL', // Determine GL or TK based on user_type
presentDate: DateTime.now().toString(), // Automatically get the present date
),
),
);
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Invalid Username or Password'),
backgroundColor: Colors.red,
),
);
}
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(vertical: 15),
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
child: Text(
'Log in',
style: TextStyle(fontSize: 16, color: Colors.black),
),
),
shashank s is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.