当我点击列表时,如何在详细信息屏幕中传递数据?

时间:2020-03-14 13:00:45

标签: json flutter

我在youtube的某个地方遵循了以下代码行,显示数据很好,并且我添加了 刷新指示器。

现在我有以下问题:当我点击列表之一时,如何在详细信息屏幕中传递数据?并且需要在获取数据时显示加载文本。

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;

import 'main_drawer.dart';

class NotificationScr extends StatefulWidget {
  @override
  _NotificationScrState createState() => _NotificationScrState();
}

class _NotificationScrState extends State<NotificationScr> {

  final String url = "https://ikns.info/api/announcement_data.php";
  List data;

  Future<String> getSWData() async {
    refreshKey.currentState?.show(atTop: false);
    //await Future.delayed(Duration(seconds: 2));
    var res = await http.get(Uri.parse(url), headers: {"Accept": "application/json"});

    setState(() {
       data = json.decode(res.body);  
      });



    return null;
  }

    var refreshKey = GlobalKey<RefreshIndicatorState>();

    @override
    void initState() {
      super.initState();
        this.getSWData();
    }

    //initialize the icon in appbar
    Icon actionIcon = new Icon(Icons.more_vert);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colors.white,
      appBar: new AppBar(
          centerTitle: true,  //centering the title
          title: new Text('Notification', style: TextStyle(color: Colors.white)),
          backgroundColor: Colors.red,
          actions: <Widget>[
            new IconButton(
              icon: actionIcon,
              onPressed:(){
                  Navigator.of(context).pushNamed('emailRoute');
              },
            ),
          ],
        ),
      drawer: MainDrawer(),


      body: RefreshIndicator(
        key: refreshKey,


        child: ListView.builder(


           itemCount: data == null ? 0 : data.length,
            itemBuilder: (BuildContext context, int index) {
          return Container(
            child: Center(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                   Container(
                        padding: EdgeInsets.all(15.0),
                        child: Row(
                          children: <Widget>[
                            Text(data[index]["title"],
                                style: TextStyle(
                                    fontSize: 18.0, color: Colors.black87)),
                          ],
                        )),
                ],
              ),
            ),
          );
        },
        ),
        onRefresh: getSWData,
      ),
    );
  }
}

0 个答案:

没有答案