-
Notifications
You must be signed in to change notification settings - Fork 609
Open
Labels
area-executiontype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
Relevant console output
Script error.When did the error happen?
please fix it
Your Dart code
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class AppColors {
static const primary = Color(0xFFF26C0D);
static const textDark = Color(0xFF181411);
static const textLight = Color(0xFF8A7260);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Navigator Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: AppColors.primary,
appBarTheme: AppBarTheme(
backgroundColor: AppColors.primary,
foregroundColor: Colors.white,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primary,
foregroundColor: Colors.white,
),
),
),
home: MainMenuPage(),
);
}
}
class MainMenuPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Navigator Örnekleri')),
body: ListView(
padding: EdgeInsets.all(16),
children: [
_menuCard(context, '1. Temel push/pop', Icons.arrow_forward,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => BasicNavigationPage()))),
_menuCard(context, '2. Veri Gönderme', Icons.shopping_bag,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => ProductListPage()))),
_menuCard(context, '3. Veri Alma (pop ile)', Icons.location_city,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => SelectCityPage()))),
_menuCard(context, '4. pushReplacement', Icons.login,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => LoginPage()))),
_menuCard(context, '5. PopScope (Geri Tuşu)', Icons.back_hand,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => PopScopeExample()))),
],
),
);
}
Widget _menuCard(BuildContext context, String title, IconData icon, VoidCallback onTap) {
return Card(
margin: EdgeInsets.only(bottom: 12),
child: ListTile(
leading: Icon(icon, color: AppColors.primary),
title: Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
trailing: Icon(Icons.arrow_forward_ios, size: 16),
onTap: onTap,
),
);
}
}
// 1. Temel Navigation
class BasicNavigationPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Temel Navigation')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.home, size: 60, color: AppColors.primary),
SizedBox(height: 20),
ElevatedButton(
child: Text('Detay Sayfasına Git'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => DetailPage()),
),
),
],
),
),
);
}
}
class DetailPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Detay')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.info, size: 60, color: AppColors.primary),
SizedBox(height: 20),
ElevatedButton(
child: Text('Geri Dön'),
onPressed: () => Navigator.pop(context),
),
],
),
),
);
}
}
// 2. Veri Gönderme
class ProductListPage extends StatelessWidget {
final products = [
{'name': 'iPhone 15', 'price': 50000},
{'name': 'Samsung S24', 'price': 45000},
{'name': 'Xiaomi 14', 'price': 35000},
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Ürünler')),
body: ListView.builder(
itemCount: products.length,
itemBuilder: (context, index) {
final product = products[index];
return ListTile(
leading: Icon(Icons.phone_android, color: AppColors.primary),
title: Text(product['name'] as String),
subtitle: Text('${product['price']} TL'),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ProductDetailPage(
name: product['name'] as String,
price: product['price'] as int,
),
),
),
);
},
),
);
}
}
class ProductDetailPage extends StatelessWidget {
final String name;
final int price;
const ProductDetailPage({required this.name, required this.price});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(name)),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.phone_android, size: 80, color: AppColors.primary),
SizedBox(height: 20),
Text(name, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
Text('$price TL', style: TextStyle(fontSize: 20, color: Colors.green)),
],
),
),
);
}
}
// 3. Veri Alma (pop ile)
class SelectCityPage extends StatefulWidget {
@override
_SelectCityPageState createState() => _SelectCityPageState();
}
class _SelectCityPageState extends State<SelectCityPage> {
String selectedCity = 'Henüz seçilmedi';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Şehir Seç')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.location_city, size: 60, color: AppColors.primary),
SizedBox(height: 20),
Text(selectedCity, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 30),
ElevatedButton(
child: Text('Şehir Listesi'),
onPressed: () async {
final result = await Navigator.push(
context,
MaterialPageRoute(builder: (_) => CityListPage()),
);
if (result != null) {
setState(() => selectedCity = result);
}
},
),
],
),
),
);
}
}
class CityListPage extends StatelessWidget {
final cities = ['İstanbul', 'Ankara', 'İzmir', 'Antalya', 'Bursa'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Şehirler')),
body: ListView.builder(
itemCount: cities.length,
itemBuilder: (context, index) => ListTile(
leading: Icon(Icons.location_city, color: AppColors.primary),
title: Text(cities[index]),
onTap: () => Navigator.pop(context, cities[index]),
),
),
);
}
}
// 4. pushReplacement
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Giriş')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.login, size: 60, color: AppColors.primary),
SizedBox(height: 20),
Text('Giriş Yap', style: TextStyle(fontSize: 24)),
SizedBox(height: 30),
ElevatedButton(
child: Text('Giriş Yap'),
onPressed: () => Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => DashboardPage()),
),
),
],
),
),
);
}
}
class DashboardPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Ana Sayfa'),
automaticallyImplyLeading: false, // Geri tuşunu gizle
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.dashboard, size: 60, color: AppColors.primary),
SizedBox(height: 20),
Text('Hoş Geldiniz!', style: TextStyle(fontSize: 24)),
Text('(Geri tuşu Login\'e dönmez)', style: TextStyle(fontSize: 12)),
SizedBox(height: 30),
ElevatedButton(
child: Text('Çıkış (pushAndRemoveUntil)'),
onPressed: () => Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => LoginPage()),
(route) => false,
),
),
],
),
),
);
}
}
// 5. PopScope (Geri Tuşunu Yakalama)
class PopScopeExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) async {
if (didPop) return;
final shouldPop = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Çıkmak İstiyor musunuz?'),
actions: [
TextButton(
child: Text('Hayır'),
onPressed: () => Navigator.pop(context, false),
),
TextButton(
child: Text('Evet'),
onPressed: () => Navigator.pop(context, true),
),
],
),
);
if (context.mounted && shouldPop == true) {
Navigator.pop(context);
}
},
child: Scaffold(
appBar: AppBar(title: Text('PopScope Örneği')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.back_hand, size: 60, color: Colors.red),
SizedBox(height: 20),
Text('Geri Tuşu Kontrolü', style: TextStyle(fontSize: 20)),
SizedBox(height: 10),
Padding(
padding: EdgeInsets.all(32),
child: Text(
'Geri tuşuna basın, onay dialogu çıkacak!',
textAlign: TextAlign.center,
),
),
],
),
),
),
);
}
}
What OS did this error occur on?
macOS
What browser(s) did this error occur on?
Chromium based (Chrome, Edge)
Do you have any additional information?
No response
Metadata
Metadata
Assignees
Labels
area-executiontype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)