@@ -2,32 +2,29 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flutter code sample for [Image.errorBuilder].
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
/// Flutter code sample for [Image.errorBuilder].
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
void main() => runApp(const ErrorBuilderExampleApp());
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class ErrorBuilderExampleApp extends StatelessWidget {
|
||||
const ErrorBuilderExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: MyStatelessWidget(),
|
||||
child: ErrorBuilderExample(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({super.key});
|
||||
class ErrorBuilderExample extends StatelessWidget {
|
||||
const ErrorBuilderExample({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -39,8 +36,7 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
),
|
||||
child: Image.network(
|
||||
'https://example.does.not.exist/image.jpg',
|
||||
errorBuilder:
|
||||
(BuildContext context, Object exception, StackTrace? stackTrace) {
|
||||
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
|
||||
// Appropriate logging or analytics, e.g.
|
||||
// myAnalytics.recordError(
|
||||
// 'An error occurred loading "https://example.does.not.exist/image.jpg"',
|
||||
|
||||
@@ -2,28 +2,25 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flutter code sample for [Image.frameBuilder].
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
/// Flutter code sample for [Image.frameBuilder].
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
void main() => runApp(const FrameBuilderExampleApp());
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class FrameBuilderExampleApp extends StatelessWidget {
|
||||
const FrameBuilderExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: FrameBuilderExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({super.key});
|
||||
class FrameBuilderExample extends StatelessWidget {
|
||||
const FrameBuilderExample({super.key});
|
||||
|
||||
@override
|
||||
@override
|
||||
@@ -36,8 +33,7 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
),
|
||||
child: Image.network(
|
||||
'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg',
|
||||
frameBuilder: (BuildContext context, Widget child, int? frame,
|
||||
bool wasSynchronouslyLoaded) {
|
||||
frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
|
||||
if (wasSynchronouslyLoaded) {
|
||||
return child;
|
||||
}
|
||||
|
||||
@@ -2,28 +2,25 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flutter code sample for [Image.loadingBuilder].
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
/// Flutter code sample for [Image.loadingBuilder].
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
void main() => runApp(const LoadingBuilderExampleApp());
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
class LoadingBuilderExampleApp extends StatelessWidget {
|
||||
const LoadingBuilderExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: LoadingBuilderExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({super.key});
|
||||
class LoadingBuilderExample extends StatelessWidget {
|
||||
const LoadingBuilderExample({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -35,16 +32,14 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
),
|
||||
child: Image.network(
|
||||
'https://flutter.github.io/assets-for-api-docs/assets/widgets/falcon.jpg',
|
||||
loadingBuilder: (BuildContext context, Widget child,
|
||||
ImageChunkEvent? loadingProgress) {
|
||||
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
|
||||
if (loadingProgress == null) {
|
||||
return child;
|
||||
}
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
value: loadingProgress.expectedTotalBytes != null
|
||||
? loadingProgress.cumulativeBytesLoaded /
|
||||
loadingProgress.expectedTotalBytes!
|
||||
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
|
||||
: null,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user