Pixel Family
 · We make simple apps for social and personal awareness. Self-care, self-love, self-growth

Custom Action to randomly redirect to a page

would like to create an action to randomly redirect to a page. This code doesn't work and I don't understand why... could you help me fix it please? It would help me a lot to move forward with the project. Thank you very much in advance

// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!

import 'dart:math';

Future<void> randomPageRedirect(BuildContext context) async {
  List<String> pages = ['page01', 'page02', 'page03', 'page04'];
  // Asegúrate de que estos nombres coincidan con los nombres de tus rutas en FlutterFlow
  Random random = new Random();
  int randomNumber = random.nextInt(pages.length);
  String randomPage = pages[randomNumber];
  await Navigator.pushNamed(context, '/$randomPage');
}
1 reply