From 857ec3682707d876dbb0c8f3969c0386001156e8 Mon Sep 17 00:00:00 2001 From: Moe Date: Sat, 28 May 2022 21:36:47 +0700 Subject: [PATCH] Avoid using local assets to reduce app size --- lib/components/carousel.dart | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/components/carousel.dart b/lib/components/carousel.dart index 5f03f71..371446a 100644 --- a/lib/components/carousel.dart +++ b/lib/components/carousel.dart @@ -1,5 +1,6 @@ // ignore_for_file: dead_code +import 'package:cached_network_image/cached_network_image.dart'; import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; @@ -11,9 +12,9 @@ class Carousel extends StatefulWidget { } final List imgList = [ - 'assets/images/carousel_1.webp', - 'assets/images/carousel_2.webp', - 'assets/images/carousel_3.webp', + 'https://nekoya.moe.team/img/Carousel_1.webp', + 'https://nekoya.moe.team/img/Carousel_2.webp', + 'https://nekoya.moe.team/img/Carousel_3.webp', ]; class _CarouselState extends State { @@ -27,7 +28,24 @@ class _CarouselState extends State { borderRadius: const BorderRadius.all(Radius.circular(5.0)), child: Stack( children: [ - Image.asset(item, fit: BoxFit.cover, width: 1000.0), + CachedNetworkImage( + imageUrl: item, + placeholder: (context, url) => Container( + width: 1000, + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/images/image_empty.webp'), fit: BoxFit.cover)), + ), + errorWidget: (context, url, error) => + Image.asset('assets/images/image_error.webp'), + fadeOutDuration: const Duration(milliseconds: 5), + imageBuilder: (context, imageProvider) => Container( + width: 1000, + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, fit: BoxFit.cover)), + ), + ), Positioned( bottom: 0.0, left: 0.0,