Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

// Unused import - issue
import 'dart:async';
import 'dart:typed_data'; // Another unused import
import 'dart:math'; // Yet another unused import

void main() {
// Missing error handling
Expand All @@ -14,8 +16,14 @@

// Missing key in widget constructor
class MyApp extends StatelessWidget {
// Unused variable in class
final String unusedAppVersion = '1.0.0';

@override
Widget build(BuildContext context) {
// Unused variable in method
var unusedThemeMode = ThemeMode.light;

Check warning on line 25 in lib/main.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/main.dart#L25

The value of the local variable 'unusedThemeMode' isn't used.

return MaterialApp(
title: 'Sample Flutter App',
theme: ThemeData(
Expand All @@ -27,16 +35,20 @@
}
}

// Global variable - bad practice
// Global variables - bad practice
var globalCounter = 0;
String globalUserName = '';
List globalItems = []; // Missing type annotation

// Function with no return type declaration
getData() {
// Using print instead of proper logging
print('Getting data...');

// Unused variable
// Unused variables
var unusedVar = 'This is never used';
int anotherUnusedVar = 42;
DateTime unnecessaryTimestamp = DateTime.now();

Check warning on line 51 in lib/main.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/main.dart#L51

The value of the local variable 'unnecessaryTimestamp' isn't used.

return 'Some data';
}
Expand All @@ -46,3 +58,31 @@
// Security issue: hardcoded secret
return 'sk_live_51234567890abcdefghijklmno';
}

// Function with hardcoded database credentials
getDbConnection() {

Check warning on line 63 in lib/main.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/main.dart#L63

The function 'getDbConnection' should have a return type but doesn't.
// Multiple security issues
var host = 'prod-db.example.com';
var username = 'root';
var password = 'admin123'; // Hardcoded password
var apiSecret = 'secret_key_xyz_12345';

print('Connecting to database...'); // Logging sensitive info
return 'mongodb://$username:$password@$host/myapp';
}

// Dead code that's never called
void deadFunction() {
print('This function is never used');

Check warning on line 76 in lib/main.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/main.dart#L76

Don't invoke 'print' in production code.
var deadVariable = 'This will never be used';
}

// Function with poor null safety
processUser(user) { // Missing type annotation
// Potential null pointer exception
print(user.name);

Check warning on line 83 in lib/main.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/main.dart#L83

Don't invoke 'print' in production code.
print(user.email.toLowerCase());

// Unused variable
var processingTime = DateTime.now();
}
54 changes: 51 additions & 3 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import 'dart:math';
import 'profile_screen.dart';

// Unused import
// Unused imports
import 'dart:io';
import 'dart:convert';
import 'dart:async';
import 'dart:typed_data';

// Missing key
class HomeScreen extends StatefulWidget {
Expand All @@ -15,8 +18,11 @@
// Should be final
List<String> _items = [];

// Unused variable
// Unused variables
int _counter = 0;
String _unusedTitle = 'Home Screen';

Check notice on line 23 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L23

The private field _unusedTitle could be 'final'.

Check warning on line 23 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L23

The value of the field '_unusedTitle' isn't used.
bool _isDataLoaded = false;

Check notice on line 24 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L24

The private field _isDataLoaded could be 'final'.
DateTime _lastRefresh = DateTime.now();

Check warning on line 25 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L25

The value of the field '_lastRefresh' isn't used.

// Should use @override
void initState() {
Expand All @@ -29,6 +35,11 @@
// Using print
print('Loading data...');

// Unused variables in method
var startTime = DateTime.now();
String loadingMessage = 'Please wait...';

Check warning on line 40 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L40

The value of the local variable 'loadingMessage' isn't used.
int maxRetries = 3;

// Insecure random number generation - security issue
var random = Random();
var randomNumber = random.nextInt(100);
Expand All @@ -43,15 +54,43 @@

// Function with no return type
navigateToProfile() {
// Unused variable
var navigationTime = DateTime.now();

// Potential null issue
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProfileScreen()),
);
}

// Dead code - never called
void _deleteItem(int index) {

Check notice on line 68 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L68

The declaration '_deleteItem' isn't referenced.
print('Deleting item at index: $index');
// Unused variables
var deletionTime = DateTime.now();

Check warning on line 71 in lib/screens/home_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/home_screen.dart#L71

The value of the local variable 'deletionTime' isn't used.
String confirmMessage = 'Are you sure?';

setState(() {
_items.removeAt(index);
});
}

// Function missing return type and has unused parameter
_processData(String data) {
print('Processing: $data');
var processedData = data.toUpperCase();
// Return value never used - dead code
return processedData;
}

@override
Widget build(BuildContext context) {
// Unused variables in build method
var screenWidth = MediaQuery.of(context).size.width;
Color primaryColor = Theme.of(context).primaryColor;
bool isDarkMode = Theme.of(context).brightness == Brightness.dark;

// Unnecessary container
return Container(
child: Scaffold(
Expand All @@ -78,7 +117,8 @@
child: ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
// Missing const and key
// Missing const and key, unused variable
var itemColor = Colors.grey[100];
return ListTile(
title: Text(_items[index]),
trailing: Icon(Icons.arrow_forward),
Expand All @@ -95,4 +135,12 @@
),
);
}

// Missing @override annotation
void dispose() {
// Unused variable
var disposeTime = DateTime.now();
print('Disposing HomeScreen');
super.dispose();
}
}
71 changes: 68 additions & 3 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import 'home_screen.dart';
import '../utils/auth_helper.dart';

// Unused imports
import 'dart:convert';
import 'dart:io';
import 'dart:async';
import 'dart:math';

// Missing key
class LoginScreen extends StatefulWidget {
@override
Expand All @@ -13,21 +19,33 @@
TextEditingController _usernameController = TextEditingController();
TextEditingController _passwordController = TextEditingController();

// Unused variable
// Unused variables
bool _isLoading = false;
String _errorMessage = '';

Check notice on line 24 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L24

The private field _errorMessage could be 'final'.
int _loginAttempts = 0;

Check warning on line 25 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L25

The value of the field '_loginAttempts' isn't used.
DateTime _lastLoginAttempt = DateTime.now();
bool _rememberMe = false;

Check notice on line 27 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L27

The private field _rememberMe could be 'final'.

Check warning on line 27 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L27

The value of the field '_rememberMe' isn't used.

// Security issue: hardcoded credentials
// Security issues: hardcoded credentials
final String ADMIN_USERNAME = 'admin';
final String ADMIN_PASSWORD = 'password123';
final String ROOT_PASSWORD = 'root';

Check notice on line 32 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L32

The variable name 'ROOT_PASSWORD' isn't a lowerCamelCase identifier.
final String API_SECRET = 'secret_abc_123';

Check notice on line 33 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L33

The variable name 'API_SECRET' isn't a lowerCamelCase identifier.

// Security issue: hardcoded database connection string
final String DB_CONNECTION = 'mongodb://admin:pass123@localhost:27017/mydb';
final String POSTGRES_CONN = 'postgresql://postgres:password@localhost/mydb';

Check notice on line 37 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L37

The variable name 'POSTGRES_CONN' isn't a lowerCamelCase identifier.

void _login() {
// Using print instead of proper logging
print('Login attempt');
print('Username: ${_usernameController.text}');
print('Password: ${_passwordController.text}');
print('Password: ${_passwordController.text}'); // Logging sensitive data

Check warning on line 43 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L43

Don't invoke 'print' in production code.

// Unused variables in method
var loginTime = DateTime.now();

Check warning on line 46 in lib/screens/login_screen.dart

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/screens/login_screen.dart#L46

The value of the local variable 'loginTime' isn't used.
String userAgent = 'MyApp/1.0';
int sessionTimeout = 3600;

// Insecure comparison
if (_usernameController.text == ADMIN_USERNAME &&
Expand All @@ -43,8 +61,46 @@
}
}

// Dead code - never called
void _resetPassword() {
print('Resetting password...');
// Unused variables
var resetTime = DateTime.now();
String resetToken = 'reset_123';

// Poor implementation
_passwordController.text = 'newpassword123';
}

// Function with no return type and unused parameter
_validateInput(String input) {
print('Validating: $input');
// Unused variables
var minLength = 3;
var maxLength = 50;
bool isValid = input.length >= minLength;

return isValid;
}

// Function missing return type
_encryptPassword(String password) {
// Poor security practice - just reversing
print('Encrypting password: $password'); // Logging sensitive data
var encrypted = password.split('').reversed.join('');
// Unused variable
var encryptionKey = 'simple_key';
return encrypted;
}

@override
Widget build(BuildContext context) {
// Unused variables in build
var screenHeight = MediaQuery.of(context).size.height;
Color backgroundColor = Colors.white;
double buttonWidth = 200.0;
EdgeInsets margin = EdgeInsets.all(8.0);

// Missing const
return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -79,6 +135,12 @@
onPressed: _login,
child: Text('Login'),
),
SizedBox(height: 16),
// Dead code - button that doesn't work
TextButton(
onPressed: null, // Never functional
child: Text('Forgot Password?'),
),
],
),
),
Expand All @@ -87,6 +149,9 @@

// Missing @override
void dispose() {
// Unused variable
var disposeTime = DateTime.now();

_usernameController.dispose();
_passwordController.dispose();
super.dispose();
Expand Down
Loading