1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [Image.loadingBuilder].
8
9void main() => runApp(const LoadingBuilderExampleApp());
10
11class LoadingBuilderExampleApp extends StatelessWidget {
12 const LoadingBuilderExampleApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const MaterialApp(
17 home: LoadingBuilderExample(),
18 );
19 }
20}
21
22class LoadingBuilderExample extends StatelessWidget {
23 const LoadingBuilderExample({super.key});
24
25 @override
26 Widget build(BuildContext context) {
27 return DecoratedBox(
28 decoration: BoxDecoration(
29 color: Colors.white,
30 border: Border.all(),
31 borderRadius: BorderRadius.circular(20),
32 ),
33 child: Image.network(
34 'https://flutter.github.io/assets-for-api-docs/assets/widgets/falcon.jpg',
35 loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
36 if (loadingProgress == null) {
37 return child;
38 }
39 return Center(
40 child: CircularProgressIndicator(
41 value: loadingProgress.expectedTotalBytes != null
42 ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
43 : null,
44 ),
45 );
46 },
47 ),
48 );
49 }
50}
51

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com