samedi 23 septembre 2023

Generate Random String Flutterflow

I'm new in Flutterflow and I'm a little confused on using 'Custom Code'. I want to create something that will generate random string. I don't know if this is in a category of Widget, Action, or Function. I tried to follow the steps in Youtube but it's not working. I'm stuck and still can't find similar situation

Here's my current code. I copied it here

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

import 'package:random_string/random_string.dart';
import 'dart:math' show Random;

class GenStringRandom extends StatefulWidget {
  const GenStringRandom({
    Key? key,
    this.width,
    this.height,
  }) : super(key: key);

  final double? width;
  final double? height;

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

class _GenStringRandomState extends State<GenStringRandom> {
  main() {
  print(randomBetween(10, 20)); // some integer between 10 and 20
  print(randomNumeric(4)); // sequence of 4 random numbers i.e. 3259
  print(randomString(10)); // random sequence of 10 characters i.e. e~f93(4l-
  print(randomAlpha(5)); // random sequence of 5 alpha characters i.e. aRztC
  print(randomAlphaNumeric(
      10)); // random sequence of 10 alpha numeric i.e. aRztC1y32B

  var r = Random.secure();
  print(randomBetween(10, 20,
      provider:
          CoreRandomProvider.from(r))); // You can use a provider from Random.
  print(randomBetween(10, 20,
      provider: _Provider())); // Or you can implement your own.
}

class _Provider with AbstractRandomProvider {
  _Provider();
  double nextDouble() => 0.5;
}

Here's the error message image error

I hope someone can help me fix it and explain in a simple way and what Custom Code to use here. Thank you in advance. :)




Aucun commentaire:

Enregistrer un commentaire