如何添加按钮来显示此图像?

How to add button to display this images?

大家好希望大家好!

在这个

我想出了如何将刷新的图像放入网络。 但现在我想添加一些按钮,在开始显示图像之前,以及当我按下时显示新图像。 (这现在发生在“onTap()”)。

我试着放一个按钮,但它不起作用。 有人可以帮助我!!

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'colors.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';
    return MaterialApp(
        theme: ThemeData(
          primarySwatch: primaryBlack,
          accentColor: Colors.white,
        ),
        debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  ':(:',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                Text('FelizTriste'),
                Text(':(:', style: TextStyle(fontWeight: FontWeight.bold)),
              ],
            ),
          ),
          body: ForcePicRefresh(),
        ));
  }
}

class ForcePicRefresh extends StatefulWidget {
  @override
  _ForcePicRefreshState createState() => _ForcePicRefreshState();
}

class _ForcePicRefreshState extends State<ForcePicRefresh> {
  String url = 'http://thecatapi.com/api/images/get?format=src&type=gif';
  Widget _pic;

  @override
  void initState() {
    _pic = Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
              height: 350,
              width: 350,
              decoration: BoxDecoration(
                  border: Border.all(color: Colors.black, width: 6)),
              child: Image.network(
                url,
                width: double.infinity,
                fit: BoxFit.fill,
              )),
          Container(
            child: ElevatedButton(onPressed: () {}, child: Text('GATIT@S')),
          ),
          Container(
            child: Text('¿Quieres ver gatit@s?'),
          )
        ],
      ),
    );

    super.initState();
  }

  _updateImgWidget() async {
    setState(() {
      _pic = Center(child: CircularProgressIndicator());
    });
    Uint8List bytes = (await NetworkAssetBundle(Uri.parse(url)).load(url))
        .buffer
        .asUint8List();
    setState(() {
      _pic = Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            height: 350,
            width: 350,
            decoration: BoxDecoration(
                border: Border.all(color: Colors.black, width: 6)),
            child: Image.memory(
              bytes,
              width: double.infinity,
              fit: BoxFit.fill,
            ),
          ),
          Column(
            children: [
              Container(
                child: ElevatedButton(onPressed: () {}, child: Text('GATIT@S')),
              ),
            ],
          ),
          Container(
            child: Text('¿Quieres ver gatit@s?'),
          )
        ],
      ));
    });
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: _pic,
      onTap: () {
        _updateImgWidget();
      },
    );
  }
}

在按下功能的提升按钮中,你什么也没做

child: ElevatedButton(onPressed: () {}, child: Text('GATIT@S')),

改成这样:

ElevatedButton(
                onPressed: () {
                  _updateImgWidget();
                },
                child: Text('GATIT@S'))