Akashptl
Akashptl

Reputation: 55

how to access the list of string to another screen?

for example i have this list of string

List ceoname = [
    "Elon Musk",
    "Tim Cook",
    "Guenter Butschek",
    "Sundar pichai",
    "Thierry Delaporte",
    "Salil Parekh",
    "William Cho",
    "Satya Nadella",
    "Kenichiro Yoshida",
    "James Quincey"
  ];

and i also have image list which i have to use on another screen. how i access this list on another screen using only default navigation....??

Upvotes: 0

Views: 39

Answers (1)

Sadhik
Sadhik

Reputation: 300

Create a getter in the second screen and pass the list to there while navigating

import 'package:flutter/material.dart';

void main() {
  runApp( Screen1());
}

class Screen1 extends StatelessWidget {
  List ceoname = [
    "Elon Musk",
    "Tim Cook",
    "Guenter Butschek",
    "Sundar pichai",
    "Thierry Delaporte",
    "Salil Parekh",
    "William Cho",
    "Satya Nadella",
    "Kenichiro Yoshida",
    "James Quincey"
  ];

  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      home: InkWell(
          onTap: (){
            Navigator.push(context, MaterialPageRoute(builder:(context)=>
            Screen2(ceoname: ceoname)));
          },
          child: Container()),
    );
  }
}

class Screen2 extends StatelessWidget {
  Screen2({required this.ceoname});
List ceoname;
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      home: Container(),
    );
  }
}


Upvotes: 1

Related Questions