Когда я нажимаю на значок, он не отображает страницу (LISTVIEW IndexedStack)

#android #firebase #flutter #dart #flutter-dependencies

#Android #firebase #флаттер #dart #флаттер-зависимости

Вопрос:

 import 'package:flutter/material.dart';
import 'package:self_cargo/Profile/profil_ayarlari.dart';
import 'package:self_cargo/pages/mesaj.dart';

class ProfilHome extends StatefulWidget {
  ProfilHome({Key key}) : super(key: key);

  @override
  _ProfilHomeState createState() => _ProfilHomeState();
}

class _ProfilHomeState extends State<ProfilHome> {
  int selectIndex = 0;
  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      body: sayfaAlani(size),
    );
  }

  Widget sayfaAlani(size) {
    return ListView(
      children: [
        Padding(
          padding: const EdgeInsets.only(left: 10, right: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    width: (size.width - 20) * 0.3,
                    child: Stack(
                      children: [
                        Container(
                          height: 100,
                          width: 100,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            border: Border.all(width: 1, color: Colors.blue),
                            image: DecorationImage(
                              image: AssetImage("assets/images/user.png"),
                              fit: BoxFit.cover,
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                      width: (size.width - 50) * 0.7,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Kargo İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Yolculuk İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Alışveriş İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                        ],
                      ))
                ],
              ),
              SizedBox(height: 15),
              Row(
                children: [
                  Icon(Icons.account_circle),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "Enahra Technology",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Icon(Icons.location_on),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "İstanbul-Ataşehir",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Icon(Icons.work),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "Yazılımcı",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              SizedBox(height: 15),
              FlatButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => ProfilAyarlari()),
                  );
                },
                child: Container(
                  height: 35,
                  width: (size.width - 20),
                  decoration: BoxDecoration(
                    border: Border.all(width: 1, color: Colors.grey),
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.transparent,
                  ),
                  child: Center(
                    child: Text("Profil Ayarları"),
                  ),
                ),
              ),
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 3),
          child: Row(
            children: [
              Container(
                width: (size.width * 0.3),
                child: IconButton(
                  icon: Icon(Icons.view_in_ar),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 0;
                    });
                  },
                ),
              ),
              Container(
                width: (size.width * 0.4),
                child: IconButton(
                  icon: Icon(Icons.location_on),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 1;
                    });
                  },
                ),
              ),
              Container(
                width: (size.width * 0.3),
                child: IconButton(
                  icon: Icon(Icons.add_shopping_cart),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 2;
                    });
                  },
                ),
              ),
            ],
          ),
        ),
        Column(
          children: [
            Row(
              children: [
                Container(
                  height: 1,
                  width: (size.width * 0.3),
                  decoration: BoxDecoration(
                    color: selectIndex == 0
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
                Container(
                  height: 1,
                  width: (size.width * 0.4),
                  decoration: BoxDecoration(
                    color: selectIndex == 1
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
                Container(
                  height: 1,
                  width: (size.width * 0.3),
                  decoration: BoxDecoration(
                    color: selectIndex == 2
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
              ],
            ),
          ],
        ),
        SizedBox(
          height: 3,
        ),
        IndexedStack(
          index: selectIndex,
          children: [
            Text("Kargo İlanları"),
            Text("Yolculuk İlanları"),
            Text("Alışveriş İlanları"),
          ],
        ),
      ],
    );
  }
}

 

Я хочу вызвать страницу вместо текста в поле индексированного стека. Например, текст («Сообщение»); Не сообщение (); как
Я ввел инструкцию ListView, но не смог ее найти, пожалуйста, помогите мне, пожалуйста
Я хочу вызвать страницу вместо текста в поле индексированного стека. Например, текст («Сообщение»); Не сообщение (); как
Я ввел инструкцию ListView, но не смог ее найти, пожалуйста, помогите мне, пожалуйста
Я хочу вызвать страницу вместо текста в поле индексированного стека. Например, текст («Сообщение»); Не сообщение (); как
Я ввел инструкцию ListView, но не смог ее найти, пожалуйста, помогите мне, пожалуйста

Комментарии:

1. Пожалуйста, помогите мне:((

2. Привет, пожалуйста, удалите дублированные предложения по вашему вопросу. Это не помогает SEO вашему вопросу, если это то, к чему вы стремитесь.

Ответ №1:

Вы можете поместить страницу (виджет с отслеживанием состояния) вместо текстового виджета, просто указав высоту,

Ваш IndexedStack выглядит следующим образом,

 IndexedStack(
          index: selectIndex,
          children: [
            Container(
              height: 300, //You can change height using media query
                child: MyHomePage(title: "test",)),
//            Text("Kargo İlanları"),
            Text("Yolculuk İlanları"),
            Text("Alışveriş İlanları"),
          ],
        )
 

Полный код

 import 'package:flutter/material.dart';

import 'main.dart';

class ProfilHome extends StatefulWidget {
  ProfilHome({Key key}) : super(key: key);

  @override
  _ProfilHomeState createState() => _ProfilHomeState();
}

class _ProfilHomeState extends State<ProfilHome> {
  int selectIndex = 0;
  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      body: sayfaAlani(size),
    );
  }

  Widget sayfaAlani(size) {
    return ListView(
      children: [
        Padding(
          padding: const EdgeInsets.only(left: 10, right: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    width: (size.width - 20) * 0.3,
                    child: Stack(
                      children: [
                        Container(
                          height: 100,
                          width: 100,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            border: Border.all(width: 1, color: Colors.blue),
                            image: DecorationImage(
                              image: AssetImage("assets/images/user.png"),
                              fit: BoxFit.cover,
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                      width: (size.width - 50) * 0.7,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Kargo İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Yolculuk İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                          Column(
                            children: [
                              Text(
                                "61",
                                style: TextStyle(
                                    fontSize: 18, fontWeight: FontWeight.bold),
                              ),
                              Text(
                                "Alışveriş İlanı",
                                style: TextStyle(
                                    fontSize: 12, fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                        ],
                      ))
                ],
              ),
              SizedBox(height: 15),
              Row(
                children: [
                  Icon(Icons.account_circle),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "Enahra Technology",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Icon(Icons.location_on),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "İstanbul-Ataşehir",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              Row(
                children: [
                  Icon(Icons.work),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    "Yazılımcı",
                    style: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                ],
              ),
              SizedBox(height: 15),
              FlatButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => ProfilHome()),
                  );
                },
                child: Container(
                  height: 35,
                  width: (size.width - 20),
                  decoration: BoxDecoration(
                    border: Border.all(width: 1, color: Colors.grey),
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.transparent,
                  ),
                  child: Center(
                    child: Text("Profil Ayarları"),
                  ),
                ),
              ),
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 3),
          child: Row(
            children: [
              Container(
                width: (size.width * 0.3),
                child: IconButton(
                  icon: Icon(Icons.view_in_ar),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 0;
                    });
                  },
                ),
              ),
              Container(
                width: (size.width * 0.4),
                child: IconButton(
                  icon: Icon(Icons.location_on),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 1;
                    });
                  },
                ),
              ),
              Container(
                width: (size.width * 0.3),
                child: IconButton(
                  icon: Icon(Icons.add_shopping_cart),
                  splashRadius: 25,
                  iconSize: 30,
                  color: Colors.redAccent[200],
                  onPressed: () {
                    setState(() {
                      selectIndex = 2;
                    });
                  },
                ),
              ),
            ],
          ),
        ),
        Column(
          children: [
            Row(
              children: [
                Container(
                  height: 1,
                  width: (size.width * 0.3),
                  decoration: BoxDecoration(
                    color: selectIndex == 0
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
                Container(
                  height: 1,
                  width: (size.width * 0.4),
                  decoration: BoxDecoration(
                    color: selectIndex == 1
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
                Container(
                  height: 1,
                  width: (size.width * 0.3),
                  decoration: BoxDecoration(
                    color: selectIndex == 2
                        ? Colors.redAccent[200]
                        : Colors.transparent,
                  ),
                ),
              ],
            ),
          ],
        ),
        SizedBox(
          height: 3,
        ),
        IndexedStack(
          index: selectIndex,
          children: [
            Container(
              height: 300,
                child: MyHomePage(title: "test",)),
//            Text("Kargo İlanları"),
            Text("Yolculuk İlanları"),
            Text("Alışveriş İlanları"),
          ],
        ),
      ],
    );
  }
}


class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter  ;
    });
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
 

вы также можете поместить listview внутри этого контейнера (внутри IndexedStack).