我拍摄了要在Listview生成器中显示的图片,但我发现我的图像没有显示.我使用Image.Network来拉取图片,以显示我的哪些图片存储在文件夹Problem_image中,图像的名称存储在数据库中.我怎样才能修改它来显示我的形象?

Enter image description here

Expanded(
    child: StreamBuilder(
       stream: _streamController.stream,
       builder: (context, snapshots) {
        if (snapshots.hasData) {
          return ListView.builder(
              itemCount: problemlist.length,
               itemBuilder: ((context, index) {
                 problemModel problem = problemlist[index];
                 return Card(
                  margin: EdgeInsets.all(10),
                  child: ListTile(
                    leading: Image.network(
                      'http://192.168.1.148/skc/Problem_image/${problem.image}',
                      fit: BoxFit.cover,
                      width: 100,
                    ),
                    title: Text(
                      problem.name_surname,
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 19),
                    ),
                    subtitle: Text(
                      problem.status,
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 17),
                    ),
                    trailing: Text(
                     problem.area,
                     style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 16),
                    ),
                  ),
                );
              }));
        }
         return Center(
          child: CircularProgressIndicator(),
        );
      },
    ),
)

推荐答案

您的URL似乎无法访问.您可以try 这种方式:

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final queryParameters = {
    'country': 'us',
    'category': 'business',
    'apiKey': 'Your API Key',
  };
  //Get API key from https://newsapi.org/

  HashMap<dynamic, dynamic> data = HashMap<dynamic, dynamic>();
  double _currentSliderValue = 0;
  late final Future myFuture;

  @override
  void initState() {
    myFuture = apiCall();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder(
          future: myFuture,
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.done) {
              if (snapshot.hasError) {
                return const Center(child: Text("No data available"));
              } else if (snapshot.hasData) {
                return SizedBox(
                  child: ListView.builder(
                    itemCount: snapshot.data?.length ?? 0,
                    scrollDirection: Axis.vertical,
                    itemBuilder: (context, index) {
                      return Card(
                        margin: const EdgeInsets.all(10),
                        child: ListTile(
                          leading: SizedBox(
                            width: 100,
                            child: CachedNetworkImage(
                              fit: BoxFit.fitHeight,
                              imageUrl:
                                  snapshot.data[_currentSliderValue.toInt()],
                              placeholder: (context, url) =>
                                  const CircularProgressIndicator(),
                              errorWidget: (context, url, error) =>
                                  const Icon(Icons.error),
                            ),
                          ),
                          title: const Text("Your Title here"),
                          subtitle: const Text("Your SubTitle here"),
                          trailing: const Text("Your Training here"),
                        ),
                      );
                    },
                  ),
                );
              }
            }
            return const Center(child: CircularProgressIndicator());
          }),
    );
  }

  Future apiCall() async {
    List<String> list = [];
    var url = Uri.https('newsapi.org', 'v2/top-headlines', queryParameters);

    var response = await http.get(url);
    if (response.statusCode == 200) {
      var jsonResponse =
          convert.jsonDecode(response.body) as Map<String, dynamic>;

      var articles = jsonResponse['articles'];

      for (var i = 0; i < articles.length; i++) {
        var articleData = articles[i];
        var urls = articleData["urlToImage"];
        if (urls != null) {
          list.add(urls);
        }
      }

      return list;
    } else {
      debugPrint('Request failed with status: ${response.statusCode}.');
    }
  }
}

Enter image description here

Flutter相关问答推荐

关闭视频通话,相机仍在运行!(Flutter WebRTC)

audioQuery不会等待判断存储权限

如何在2024年使用Ffltter将用户数据保存在云FireStore中?

我不能在Fighting中裁剪图片输入错误,否则应用程序会崩溃

如何让经过Firebase身份验证的用户能够将Zip文件上载到Firebase云存储?

dart /长笛中的返回早期模式和拆分方法

StateNotifer正在riverpod中提供初始状态值(bool)

Flutter中不使用Container是否可以做margin

Flutter:如何在现有布局之上显示圆角布局?

Flutter 判断 Uint8List 是否有效 Image

如何停止折线图的抖动

当我使用 Confetti Widget 时,Flutter Android 和 IOS 应用程序崩溃

底部工作表顶部的一块 Flutter

如何格式化网址?

Flutter sliver 持久化

为什么容器会填满整个空间?

Flutter 中的无效日期格式 2022 年 11 月 14 日

Flutter 用户过滤器

未处理的异常:FileSystemException:无法打开文件,路径 = 'assets/res.zip'(操作系统错误:没有这样的文件或目录,errno = 2)

在右侧从 a 到 z Flutter 字母列表