Reputation: 197
I'm working on a Flutter project and encountering the following error:
Error: Error when reading 'lib/data/soru_bankasi.dart': No such file or directory
This error occurs when I try to run the app. However, I have not created a file named soru_bankasi.dart in my project, and there are no references to this file in my code.
file structure
My Code: lib/main.dart:
import 'package:flutter/material.dart';
import 'screens/ana_sayfa.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'History Quiz App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: AnaSayfa(),
);
}
}
lib/screens/ana_sayfa.dart:
import 'package:flutter/material.dart';
import 'test_sayfasi.dart'; // Importing the TestSayfasi widget
class AnaSayfa extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Welcome!',
style: TextStyle(fontSize: 24),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TestSayfasi()),
);
},
child: Text('Start Quiz'),
),
],
),
),
);
}
}
lib/screens/test_sayfasi.dart:
import 'package:flutter/material.dart';
import 'test_secim_sayfasi.dart';
class TestSayfasi extends StatelessWidget {
final List<String> topics = [
'Pre-Islamic Turkish History',
'First Turkish-Islamic States',
'Ottoman Empire: Foundation and Rise Periods',
'Culture and Civilization in the Ottoman Empire',
'17th Century Ottoman Empire (Stagnation Period)',
'18th Century Ottoman Empire (Decline Period)',
'19th Century Ottoman Empire (Collapse Period)',
'20th Century Ottoman Empire',
'War of Independence: Preparatory Period',
'First Turkish Grand National Assembly',
'War of Independence: Battle Period',
'Ataturk’s Reforms',
'Ataturk’s Principles',
'Political Parties and Internal Politics',
'Ataturk’s Foreign Policy',
'Post-Ataturk Period',
'Life and Personality of Ataturk',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Topics'),
),
body: ListView.builder(
itemCount: topics.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TestSecimSayfasi(topic: topics[index]),
),
);
},
child: Text(topics[index]),
),
);
},
),
);
}
}
lib/screens/test_secim_sayfasi.dart:
import 'package:flutter/material.dart';
class TestSecimSayfasi extends StatelessWidget {
final String topic;
TestSecimSayfasi({required this.topic});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('$topic - Test Selection'),
),
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TestDetailsPage(
topic: topic,
testNo: index + 1,
),
),
);
},
child: Text('Test-${index + 1}'),
),
);
},
),
);
}
}
class TestDetailsPage extends StatelessWidget {
final String topic;
final int testNo;
TestDetailsPage({required this.topic, required this.testNo});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('$topic - Test-$testNo'),
),
body: Center(
child: Text(
'Content for $topic - Test-$testNo will be displayed here.',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.center,
),
),
);
}
}
What I've Tried:
1)I searched all my project files for any references to soru_bankasi.dart but couldn't find any. 2)Used the "Find in Files" feature in my IDE (VS Code) to search for soru_bankasi, but no results were found. 3)Cleaned and rebuilt the project using the following commands.
flutter clean
flutter pub get
flutter run
4)Deleted the .dart_tool and build directories manually and ran the project again.
Question:
Why is Flutter looking for a soru_bankasi.dart file when I haven't created or referenced it anywhere in my project? How can I resolve this issue?
Upvotes: 1
Views: 31
Reputation: 1352
I think something wrong with the package import: I can run this code :
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_application_2/screen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'History Quiz App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: AnaSayfa(),
);
}
}
class AnaSayfa extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Welcome!',
style: TextStyle(fontSize: 24),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TestSayfasi()),
);
},
child: Text('Start Quiz'),
),
],
),
),
);
}
}
Screen:
import 'package:flutter/material.dart';
class TestSayfasi extends StatelessWidget {
final List<String> topics = [
'Pre-Islamic Turkish History',
'First Turkish-Islamic States',
'Ottoman Empire: Foundation and Rise Periods',
'Culture and Civilization in the Ottoman Empire',
'17th Century Ottoman Empire (Stagnation Period)',
'18th Century Ottoman Empire (Decline Period)',
'19th Century Ottoman Empire (Collapse Period)',
'20th Century Ottoman Empire',
'War of Independence: Preparatory Period',
'First Turkish Grand National Assembly',
'War of Independence: Battle Period',
'Ataturk’s Reforms',
'Ataturk’s Principles',
'Political Parties and Internal Politics',
'Ataturk’s Foreign Policy',
'Post-Ataturk Period',
'Life and Personality of Ataturk',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Topics'),
),
body: ListView.builder(
itemCount: topics.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: ElevatedButton(
onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => TestSecimSayfasi(topic: topics[index]),
// ),
// );
},
child: Text(topics[index]),
),
);
},
),
);
}
}
Upvotes: 0