Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:flutter/rendering.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(primarySwatch: Colors.green),
- home: Scaffold(
- appBar: AppBar(title: Text('Stateful Widget')),
- body: Column(children: [RandomImages()]),
- ),
- );
- }
- }
- class RandomImages extends StatefulWidget {
- const RandomImages({Key? key}) : super(key: key);
- @override RandomImageState createState() => RandomImageState();
- }
- class RandomImageState extends State<RandomImages> {
- Random random = new Random();
- int imageId = 1;
- @override
- Widget build(BuildContext context) {
- return Center(
- child: FractionallySizedBox(
- widthFactor: 0.8,
- child: Column(
- children: <Widget>[
- Container(child: Image.network('https://picsum.photos/id/$imageId/200/300')),
- Container(
- width: 120,
- height: 70,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[RaisedButton(child: Text('Load Another Image'), onPressed: () {setState(() => imageId = random.nextInt(1000));}, color: Colors.yellow)],
- ),
- )
- ])
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement