Advertisement
mjamilasfihani

modul-2

Dec 2nd, 2021
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.51 KB | None | 0 0
  1. import 'dart:math';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/rendering.dart';
  5.  
  6. void main() {
  7.   runApp(MyApp());
  8. }
  9.  
  10. class MyApp extends StatelessWidget {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       title: 'Flutter Demo',
  15.       theme: ThemeData(primarySwatch: Colors.green),
  16.       home: Scaffold(
  17.         appBar: AppBar(title: Text('Stateful Widget')),
  18.         body: Column(children: [RandomImages()]),
  19.       ),
  20.     );
  21.   }
  22. }
  23.  
  24. class RandomImages extends StatefulWidget {
  25.   const RandomImages({Key? key}) : super(key: key);
  26.   @override RandomImageState createState() => RandomImageState();
  27. }
  28.  
  29. class RandomImageState extends State<RandomImages> {
  30.   Random random = new Random();
  31.   int imageId = 1;
  32.   @override
  33.   Widget build(BuildContext context) {
  34.     return Center(
  35.       child: FractionallySizedBox(
  36.         widthFactor: 0.8,
  37.         child: Column(
  38.           children: <Widget>[
  39.             Container(child: Image.network('https://picsum.photos/id/$imageId/200/300')),
  40.             Container(
  41.               width: 120,
  42.               height: 70,
  43.               child: Column(
  44.                 mainAxisAlignment: MainAxisAlignment.center,
  45.                 crossAxisAlignment: CrossAxisAlignment.center,
  46.                 children: <Widget>[RaisedButton(child: Text('Load Another Image'), onPressed: () {setState(() => imageId = random.nextInt(1000));}, color: Colors.yellow)],
  47.               ),
  48.             )
  49.           ])
  50.       ),
  51.     );
  52.   }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement