Button click open another screen and pass value in flutter

main.dart
  
  
final TextEditingController _phoneController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
  
  
  
  
  void _sendData() {
    String phoneNumber = _phoneController.text;
    String emailid = _emailController.text;
    if (phoneNumber.isNotEmpty ) {
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => Registerscreen(receivedPhone: phoneNumber, receivedemailid: emailid),
        ),
      );
    } else {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text("Please enter a valid 10-digit phone number")),
      );
    }
  }
  
  
  
  
      TextField(
              controller: _phoneController,
              decoration: InputDecoration(
                labelText: "Phone",
                border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0)),
                filled: true,
                fillColor: Colors.grey[200],
                prefixIcon: Icon(Icons.phone),
              ),
              keyboardType: TextInputType.phone,
            ),

            SizedBox(height: 20),

     TextField(
              controller: _emailController,
              decoration: InputDecoration(
                labelText: "Email",
                border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0)),
                filled: true,
                fillColor: Colors.grey[200],
                prefixIcon: Icon(Icons.phone),
              ),
              keyboardType: TextInputType.emailAddress,
            ),
  
  
  

ElevatedButton(
              onPressed: (){
                _sendData(); // ✅ Function call properly
              },
              style: ElevatedButton.styleFrom(
                padding: EdgeInsets.symmetric(horizontal: 50, vertical: 15),
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
                backgroundColor: Colors.deepPurple,
              ),
              child: Text("Proceed", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white)),
            ),
            
            
   
recieve.dart
  
  final String receivedPhone;
  final String receivedemailid;
  // ✅ Yahan phone number receive hoga

  Registerscreen({Key? key, required this.receivedPhone, required this.receivedemailid }) : super(key: key);
  
  
  Text(
                "OTP sent to ${widget.receivedPhone}",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
              ),

              Text(
                "Your email id ${widget.receivedemailid}",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
              ),

  

Post a Comment

0 Comments