Reputation: 85
Hello there so I have a set of images which I want it to bee shown in the splash screen in my flutter app every time user opens it. But what I want is that every time the user opens it a random new image as a splash screen is shown.. Is there anyway to achieve it?
Upvotes: 0
Views: 210
Reputation: 2040
Yes, it's possible, use example below:
import 'dart:math';
import 'package:flutter/material.dart';
class SplashScreen extends StatelessWidget {
SplashScreen({Key? key}) : super(key: key);
final images = [
"assets/img1.jpg",
"assets/img2.jpg",
"assets/img3.jpg",
"assets/img4.jpg",
//...
];
late final index = Random().nextInt(images.length);
@override
Widget build(BuildContext context) {
return Center(
child: Image.asset(images[index]),
);
}
}
Upvotes: 2