StoryItem.pageProviderImage constructor

StoryItem.pageProviderImage(
  1. ImageProvider<Object> image, {
  2. Key? key,
  3. BoxFit imageFit = BoxFit.fitWidth,
  4. String? caption,
  5. bool shown = false,
  6. Duration? duration,
})

Shorthand for creating a story item from an image provider such as AssetImage or NetworkImage. However, the story continues to play while the image loads up.

Implementation

factory StoryItem.pageProviderImage(
  ImageProvider image, {
  Key? key,
  BoxFit imageFit = BoxFit.fitWidth,
  String? caption,
  bool shown = false,
  Duration? duration,
}) {
  return StoryItem(
      Container(
        key: key,
        color: Colors.black,
        child: Stack(
          children: <Widget>[
            Center(
              child: Image(
                image: image,
                height: double.infinity,
                width: double.infinity,
                fit: imageFit,
              ),
            ),
            SafeArea(
              child: Align(
                alignment: Alignment.bottomCenter,
                child: Container(
                  width: double.infinity,
                  margin: EdgeInsets.only(
                    bottom: 24,
                  ),
                  padding: EdgeInsets.symmetric(
                    horizontal: 24,
                    vertical: 8,
                  ),
                  color:
                      caption != null ? Colors.black54 : Colors.transparent,
                  child: caption != null
                      ? Text(
                          caption,
                          style: TextStyle(
                            fontSize: 15,
                            color: Colors.white,
                          ),
                          textAlign: TextAlign.center,
                        )
                      : SizedBox(),
                ),
              ),
            )
          ],
        ),
      ),
      shown: shown,
      duration: duration ?? Duration(seconds: 3));
}