Custom Code

Hi unable to change [ import 'dart:math' as math; ] to [ import 'dart:math' show Random; ] i can change in the code when i try to test the code is auto reverted to [math] any suggestions on how to solve this?

What have you tried so far?

This is the code I have

-------------------------

When I change the auto fetched [ import 'dart:math' as math; ] to [ import 'dart:math' show Random; ] the code auto changes to [match when I click on test.

-----------------------

import 'dart:convert';

import 'dart:math'; // Ensure you import dart:math for Random

import 'package:flutter/material.dart';

import 'package:google_fonts/google_fonts.dart';

import 'package:intl/intl.dart';

import 'package:timeago/timeago.dart' as timeago;

import '/flutter_flow/lat_lng.dart';

import '/flutter_flow/place.dart';

import '/flutter_flow/uploaded_file.dart';

import '/flutter_flow/custom_functions.dart';

import '/backend/backend.dart';

import 'package:cloud_firestore/cloud_firestore.dart';

import '/auth/firebase_auth/auth_util.dart';

String? textGenUserIntro(

String? otherUserName,

int? age,

String? gender,

String? city,

String? title,

String? authUserName,

int? aUAge,

String? aUcity,

String? aUtitle,

String? aUgender,

) {

/// MODIFY CODE ONLY BELOW THIS LINE

// Define different sentences for each scenario

final List<String> userAToBTemplates = [

"Hey there, $otherUserName! I see you're $age years young and a $title! 🌟 What are you passionate about?",

"Hi $otherUserName! It’s awesome to connect! Being a $title at $age must be an adventure!",

"What’s up, $otherUserName? I’m curious about your journey as a $title at just $age! Let’s chat!",

];

final List<String> userAToCTemplates = [

"Greetings, $otherUserName! I’d love to share our stories as $title! 🌍",

"Hello $otherUserName! At $age, being a $title sounds exciting! Let’s connect!",

"Hi $otherUserName! I’m intrigued by your experiences as a $title at $age! What’s your story?",

];

final List<String> userCToBTemplates = [

"Hi there, $otherUserName! As a $title, I'm curious about your insights! 😊",

"Hey $otherUserName! I’d love to hear your thoughts as a $title at $age!",

"What’s going on, $otherUserName? Being a $title sounds interesting at $age! Let's chat!",

];

// Create an instance of Random for generating random numbers

Random random = Random();

// Assume the introduction type is determined by some logic. For this example, we'll hardcode it.

String generatedText;

int introType = 1; // 1: A to B, 2: A to C, 3: C to B

// Generate random text based on the introType

if (introType == 1) {

generatedText = userAToBTemplates[random.nextInt(userAToBTemplates.length)];

} else if (introType == 2) {

generatedText = userAToCTemplates[random.nextInt(userAToCTemplates.length)];

} else {

generatedText = userCToBTemplates[random.nextInt(userCToBTemplates.length)];

}

// Return the formatted string with variables intact

return generatedText

.replaceAll(RegExp(r'\$otherUserName'), otherUserName ?? 'User')

.replaceAll(RegExp(r'\$age'), age?.toString() ?? 'unknown')

.replaceAll(RegExp(r'\$title'), title ?? 'the mystery');

/// MODIFY CODE ONLY ABOVE THIS LINE

}

Did you check FlutterFlow's Documentation for this topic?
No
1