Çözüldü Flutter Navigator.push context hatası veriyor

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

Nazo_2004

Decapat
Katılım
8 Temmuz 2021
Mesajlar
259
Daha fazla  
Cinsiyet
Erkek
Flutter Navigator.push context hatası veriyor bunun sebebi nedir?

asda.PNG
 
Son düzenleyen: Moderatör:
Çözüm
@Nazo_2004 uygulama sınıfını belirtmemişsin. Bunla değiştir:

Kod:
class AnaEkran extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(title: Text("BlockMedia")),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Container(
              height: 50,
              width: 610,
              child: Row(
                children: <Widget>[
                  Container(
                    width: 175,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("iMAGES"),
                        onPressed: () {}),
                  ),
                  SizedBox(width: 1),
                  Container(
                    width: 174,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("Thougths"),
                        onPressed: () {
                          Navigator.push(
                            context,
                              MaterialPageRoute(
                                builder: (context) => Thougths(),
                              ));
                  },),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400],
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Çakar"),
                          ],
                        ),
                        SizedBox(height: 5),
                        Image(image: NetworkImage("https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcR963Za-yYdBvBdOh2yAC28a-fLOaZ3ltNuXDeOmJXLs78d61RuFBfXXQ&s=19"))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.green,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.blue,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  );
  }
}
Kod:
import 'package:flutter/material.dart';
import 'Images.dart';
import 'Thougths.dart';

Widget AnaEkran() {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(title: Text("BlockMedia")),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Container(
              height: 50,
              width: 610,
              child: Row(
                children: <Widget>[
                  Container(
                    width: 175,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("iMAGES"),
                        onPressed: () {}),
                  ),
                  SizedBox(width: 1),
                  Container(
                    width: 174,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("Thougths"),
                        onPressed: () {
                          Navigator.push(
                            context,
                              MaterialPageRoute(
                                builder: (context) => Thougths(),
                              ));
                  },),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400],
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Çakar"),
                          ],
                        ),
                        SizedBox(height: 5),
                        Image(image: NetworkImage("https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcR963Za-yYdBvBdOh2yAC28a-fLOaZ3ltNuXDeOmJXLs78d61RuFBfXXQ&s=19"))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.green,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.blue,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  );
}
Hocam hatayı ve kodları görebilir miyiz acaba?
Kod:
import 'package:flutter/material.dart';
import 'Images.dart';
import 'Thougths.dart';

Widget AnaEkran() {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(title: Text("BlockMedia")),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Container(
              height: 50,
              width: 610,
              child: Row(
                children: <Widget>[
                  Container(
                    width: 175,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("iMAGES"),
                        onPressed: () {}),
                  ),
                  SizedBox(width: 1),
                  Container(
                    width: 174,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("Thougths"),
                        onPressed: () {
                          Navigator.push(
                            context,
                              MaterialPageRoute(
                                builder: (context) => Thougths(),
                              ));
                  },),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400],
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Çakar"),
                          ],
                        ),
                        SizedBox(height: 5),
                        Image(image: NetworkImage("https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcR963Za-yYdBvBdOh2yAC28a-fLOaZ3ltNuXDeOmJXLs78d61RuFBfXXQ&s=19"))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.green,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.blue,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  );
}
 
@Nazo_2004 uygulama sınıfını belirtmemişsin. Bunla değiştir:

Kod:
class AnaEkran extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(title: Text("BlockMedia")),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Container(
              height: 50,
              width: 610,
              child: Row(
                children: <Widget>[
                  Container(
                    width: 175,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("iMAGES"),
                        onPressed: () {}),
                  ),
                  SizedBox(width: 1),
                  Container(
                    width: 174,
                    child: TextButton(
                        style: TextButton.styleFrom(
                          primary: Colors.red,
                        ),
                        child: Text("Thougths"),
                        onPressed: () {
                          Navigator.push(
                            context,
                              MaterialPageRoute(
                                builder: (context) => Thougths(),
                              ));
                  },),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400],
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Çakar"),
                          ],
                        ),
                        SizedBox(height: 5),
                        Image(image: NetworkImage("https://encrypted-tbn0.gstatic.com/licensed-image?q=tbn:ANd9GcR963Za-yYdBvBdOh2yAC28a-fLOaZ3ltNuXDeOmJXLs78d61RuFBfXXQ&s=19"))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.green,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 450,
              width: 610,
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1,
                ),
                borderRadius: BorderRadius.circular(20),
                color: Colors.blue,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Row(
                          children: [
                            Padding(
                                padding: EdgeInsets.all(16.0),
                                child: CircleAvatar(
                                  backgroundColor: Colors.brown.shade800,
                                  child: const Text('AH'),
                                )),
                            Text("Ahmet Horoz"),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  );
  }
}
 
Çözüm

Yeni konular

Geri
Yukarı