Skip to main content
se añadieron 3957 caracteres en el cuerpo
Origen Enlace

Agrego todo el código del page

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';


class PrePerfil extends StatefulWidget {
  final String id_persona;
  PrePerfil(this.id_persona, {Key key}): super(key: key);

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

class _PrePerfilState extends State<PrePerfil> {
  final Key keyOne = PageStorageKey('pageOne');
  final Key keyTwo = PageStorageKey('pageTwo');


  int currentTab = 0;

  PageOne one;
  PageTwo two;
  List<Widget> pages;
  Widget currentPage;

  List<Data> dataList;
  final PageStorageBucket bucket = PageStorageBucket();

  @override
  void initState() {
    one = PageOne(
      key: keyOne,
      dataList: dataList,
    );
    two = PageTwo(
      key: keyTwo,
    );

    pages = [one, two];

    currentPage = one;

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Persistance Example"),
      ),
      body: PageStorage(
        child: currentPage,
        bucket: bucket,
      ),

      bottomNavigationBar: CurvedNavigationBar(
        onTap: (int index) {
          setState(() {
            currentTab = index;
            currentPage = pages[index];
          });
        },
        items: <Widget>[
          Icon(Icons.account_circle,  color: Colors.white,size: 30),
          Icon(Icons.comment, color: Colors.white,size: 30),
          //Icon(Icons.business_center, color: Colors.white,size: 30),
        ],
        color: Colors.orangeAccent,
        backgroundColor: Colors.white,
      ),
    );
  }
}

class PageOne extends StatefulWidget {
  final List<Data> dataList;
  final String id_persona;
  PageOne({
    Key key,
    this.dataList, this.id_persona
  }) : super(key: key);

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

class PageOneState extends State<PageOne> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: widget.dataList.length,
        itemBuilder: (context, index) {
          return ExpansionTile(
            key: PageStorageKey('${widget.dataList[index].id}'),
            title: Text(widget.id_persona),
            children: <Widget>[
              Container(
                color: index % 2 == 0 ? Colors.orange : Colors.limeAccent,
                height: 100.0,
              ),
            ],
          );
        });
  }
}

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

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

class PageTwoState extends State<PageTwo> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemExtent: 250.0,
      itemBuilder: (context, index) => Container(
        padding: EdgeInsets.all(10.0),
        child: Material(
          elevation: 4.0,
          borderRadius: BorderRadius.circular(5.0),
          color: index % 2 == 0 ? Colors.cyan : Colors.deepOrange,
          child: Center(
            child: Text(index.toString()),
          ),
        ),
      ),
    );
  }
}

class Data {
  final int id;
  bool expanded;
  final String title;
  Data(this.id, this.expanded, this.title);
}

Agrego todo el código del page

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';


class PrePerfil extends StatefulWidget {
  final String id_persona;
  PrePerfil(this.id_persona, {Key key}): super(key: key);

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

class _PrePerfilState extends State<PrePerfil> {
  final Key keyOne = PageStorageKey('pageOne');
  final Key keyTwo = PageStorageKey('pageTwo');


  int currentTab = 0;

  PageOne one;
  PageTwo two;
  List<Widget> pages;
  Widget currentPage;

  List<Data> dataList;
  final PageStorageBucket bucket = PageStorageBucket();

  @override
  void initState() {
    one = PageOne(
      key: keyOne,
      dataList: dataList,
    );
    two = PageTwo(
      key: keyTwo,
    );

    pages = [one, two];

    currentPage = one;

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Persistance Example"),
      ),
      body: PageStorage(
        child: currentPage,
        bucket: bucket,
      ),

      bottomNavigationBar: CurvedNavigationBar(
        onTap: (int index) {
          setState(() {
            currentTab = index;
            currentPage = pages[index];
          });
        },
        items: <Widget>[
          Icon(Icons.account_circle,  color: Colors.white,size: 30),
          Icon(Icons.comment, color: Colors.white,size: 30),
          //Icon(Icons.business_center, color: Colors.white,size: 30),
        ],
        color: Colors.orangeAccent,
        backgroundColor: Colors.white,
      ),
    );
  }
}

class PageOne extends StatefulWidget {
  final List<Data> dataList;
  final String id_persona;
  PageOne({
    Key key,
    this.dataList, this.id_persona
  }) : super(key: key);

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

class PageOneState extends State<PageOne> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: widget.dataList.length,
        itemBuilder: (context, index) {
          return ExpansionTile(
            key: PageStorageKey('${widget.dataList[index].id}'),
            title: Text(widget.id_persona),
            children: <Widget>[
              Container(
                color: index % 2 == 0 ? Colors.orange : Colors.limeAccent,
                height: 100.0,
              ),
            ],
          );
        });
  }
}

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

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

class PageTwoState extends State<PageTwo> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemExtent: 250.0,
      itemBuilder: (context, index) => Container(
        padding: EdgeInsets.all(10.0),
        child: Material(
          elevation: 4.0,
          borderRadius: BorderRadius.circular(5.0),
          color: index % 2 == 0 ? Colors.cyan : Colors.deepOrange,
          child: Center(
            child: Text(index.toString()),
          ),
        ),
      ),
    );
  }
}

class Data {
  final int id;
  bool expanded;
  final String title;
  Data(this.id, this.expanded, this.title);
}
Origen Enlace

Flutter - Pasar datos desde clase a widget

Necesito pasar datos desde la clase de un page a un widget del mismo page:

class PrePerfil extends StatefulWidget {
  final String id_persona;
  PrePerfil(this.id_persona, {Key key}): super(key: key);

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

Necesito pasar el valor de id_persona al widget de otra clase llamada PageOne en el mismo page.

class PageOneState extends State<PageOne> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: widget.dataList.length,
        itemBuilder: (context, index) {
          return ExpansionTile(
            key: PageStorageKey('${widget.dataList[index].id}'),
            //title: Text(widget.dataList[index].title),
            title: Text(id_persona), // Aqui está el error

En la última línea (title) requiero usar el id_persona, pero no logro agregarlo.

Favor vuestro apoyo, muchas gracias.!