Skip to content

CircleAvatar widget throws Exception if the foregroundImage property changed #84258

@damphat

Description

@damphat

Exception has occurred.
"Error: Expected a value of type 'Decoration', but got one of type 'Null'

I believe the bug is somewhere in AnimatedContainer class and AnimationController class

Steps to Reproduce

  1. Run flutter create bug.
  2. Update the main.dart as follows:
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(body: BugWidget()),
    ),
  );
}

class BugWidget extends StatefulWidget {
  @override
  _BugWidgetState createState() => _BugWidgetState();
}

class _BugWidgetState extends State<BugWidget> {
  final photoURL = "https://gravatar.com/avatar/11ef7c4b9749807b121e74cd353be3eb";
  var radius = 20.0;
  var toggleForegroundImage = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        CircleAvatar(
          radius: radius,
          foregroundImage:
              toggleForegroundImage ? NetworkImage(photoURL) : null,
        ),
        TextButton(
          onPressed: () {
            setState(() {
              radius = radius == 20 ? 40 : 20;
            });
          },
          child: Text('toggle Radius'),
        ),
        TextButton(
          onPressed: () {
            setState(() {
              toggleForegroundImage = !toggleForegroundImage;
            });
          },
          child: Text('toggle ForegroundImage'),
        ),
      ],
    );
  }
}
  1. Run the app and click 2 buttons
  • Click button toggle Radius
  • Then click button toggle ForegroundImage

Expected results:
it should show the foregroundImage which is my avatar image

Actual results:

Exception has occurred.
"Error: Expected a value of type 'Decoration', but got one of type 'Null'
Details ``` Flutter 2.2.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 02c026b (13 days ago) • 2021-05-27 12:24:44 -0700 Engine • revision 0fdb562ac8 Tools • Dart 2.13.1 ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: error messageError messages from the Flutter frameworka: imagesLoading, displaying, rendering imagesa: null-safetySupport for Dart's null safety featuref: material designflutter/packages/flutter/material repository.found in release: 2.2Found to occur in 2.2frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions