on click randomly image showing

Hello dev, in this blog post in randomly image showing using “dart:math” Library. And this is tutorial Follow step by step and you get the easy solution

Yes this is the step by step using Dart:math and get the library showing use the code and stateful widget & get the not any error and get the sucessfully get the output and code provide all source fully on click randomly image showing.

Step 1:

import 'dart:math';

Step 2:

Random().nextInt(6) + 1 

Step 2:

main.dart

class ShowPage extends StatefulWidget {
  const ShowPage({Key? key}) : super(key: key);

  @override
  _ShowPageState createState() => _ShowPageState();
}

class _ShowPageState extends State<ShowPage> {
  int leftPagenumber = 5;
  int rightPagenumber = 1;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        children: <Widget>[
          Expanded(
            child: FlatButton(
              onPressed: () {
                setState(() {
                  rightPagenumber = Random().nextInt(6) + 1;
                  leftPagenumber = Random().nextInt(6) + 1;
                });
              },
              child: Image.asset('images/Image$rightPagenumber .png'),
            ),
          ),
          Expanded(
            child: FlatButton(
              onPressed: () {
                setState(() {
                  rightPagenumber = Random().nextInt(6) + 1;
                  leftPagenumber = Random().nextInt(6) + 1;
                });
              },
              child: Image(
                image: AssetImage('images/Image$rightPagenumber .png'),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Output for on click randomly image showing:

Leave a Comment