如何使图像随机发电机在颤动中?
大家好我是新手Flutter& DART ,我正在尝试制作一个应用程序,该应用每次用户打开它时都会显示不同的图像, 我标记了此方法Randomnum
,但我知道它不会长时间工作,因为我希望用户使用我拥有的默认图像下载自己的图像,
我的方法是使图像具有相同的名称但是使用不同的数字并制作一个随机数发电机:
Random random = new Random();
int randomNum = random.nextInt(3) + 1;
class _qouteeState extends State<qoutee> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: SafeArea(
child: Expanded(
flex: 3,
child: Container(
color: Colors.grey[300],
child: Center(
child: Image.asset('images/q$randomNum.jpg'),
),
),
),
),
),
);
}
}
因此,如何在不使图像具有相同名称的情况下使随机图像功能
hey guys I'm new to Flutter & Dart and I'm trying to make an app that will show a different image every time the user opens it,,
I marked this method randomNum
but I know it will not work for long because I want the user to download their own images with the default images that I have,
my method is to make the images have the same name but with different numbers and make a RandomNumber generator :
Random random = new Random();
int randomNum = random.nextInt(3) + 1;
class _qouteeState extends State<qoutee> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: SafeArea(
child: Expanded(
flex: 3,
child: Container(
color: Colors.grey[300],
child: Center(
child: Image.asset('images/q$randomNum.jpg'),
),
),
),
),
),
);
}
}
So how can I make Random image function without making the images have the same name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您可以将图像的路径保存在字符串列表中。然后制作一个取决于此列表的长度的随机对象。例如,如果随机值为1,则返回列表中索引1的值。这是一个非常简单的例子。
列表路径= [path_of_image1,image2 ...];
如果您询问如何添加用户添加图像并采取路径,则可以找到大量资源和解决方案。
you can save the path of your images in a list of String. then make a random object that depends on the length of this list. For example, if the random value was 1 then return the value of the index 1 in the list. here is a very simple example.
List paths = [path_of_image1, image2 ...];
If you ask about how to add an image by the user and take the path you can find a lot of resources and solutions.