2

I'm trying to create a custom Alert dialogue using this package rflutter_alert . But when return the Alert it gives me this error

The argument type 'Future<bool?>' can't be assigned to the parameter type 'Widget?'.

Update:

here i created a custom widget of dialogue


class DialogueTwoButton extends StatelessWidget {
 DialogueTwoButton(
 {Key? key,
 context,
 required this.text1,
 required this.text2,
 required this.onpres1,
 required this.onpress2})
 : super(key: key);
 final String text1;
 final String text2;
 final Function onpres1;
 final Function onpress2;
 @override
 Widget build(BuildContext context) {
 return _onAlertButtonsPressed(context, text1, text2, onpres1, onpress2);
 }
 var alertStyle = AlertStyle(
 animationType: AnimationType.fromTop,
 isCloseButton: false,
 isOverlayTapDismiss: false,
 descStyle: GoogleFonts.montserrat(color: Colors.black, fontSize: 18),
 titleStyle: GoogleFonts.montserrat(
 color: Colors.red,
 ),
 );
 _onAlertButtonsPressed(context, desc, title, onPressYes, onPressNo) {
 return Alert(
 context: context,
 style: alertStyle,
 title: title,
 desc: desc,
 buttons: [
 DialogButton(
 child: Text(
 "Yes",
 style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressYes,
 color: HexColor("#5344ed")),
 DialogButton(
 child: Text(
 "No",
 style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressNo,
 color: HexColor("#5344ed"),
 )
 ],
 ).show(); // here need to change
 }

and here is my other file where i'm creating a button


 updateProduct() {
 DialogueTwoButton(
 onpres1: () {},
 onpress2: () {},
 text1: 'df',
 text2: 'dsf',
 );
 bottomButton(context, () {
 updateProduct();
 }, "Update Product"),

and updateProduct(); on this mehtod calling the custom class dialogue, but it's not showing , i want to do this something in this way.

please help how to do this.

asked Nov 16, 2021 at 6:55
3
  • try to remove Container( //here error points child: Commented Nov 16, 2021 at 7:08
  • removed, but still error occur Commented Nov 16, 2021 at 7:10
  • also remove Widget keyword Commented Nov 16, 2021 at 7:15

2 Answers 2

1

you missing one closing ) bracket after ).show()

_onAlertButtonsPressed(context,desc,title,onPressYes,onPressNo) {
 return Alert(
 context: context,
 style: alertStyle,
 title: title,
 desc: desc,
 buttons: [
 DialogButton(
 child: Text(
 "Yes",
 style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressYes,
 color: HexColor("#5344ed")),
 DialogButton(
 child: Text(
 "No",
 style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressNo,
 color: HexColor("#5344ed"),
 )
 ],
 ).show(); // here need to change
 }

Complete src code:

import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
 runApp(MyApp());
}
class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return MaterialApp(
 theme: ThemeData.dark().copyWith(
 scaffoldBackgroundColor: darkBlue,
 ),
 debugShowCheckedModeBanner: false,
 home: Scaffold(
 body: Center(
 child: MyHomePage(),
 ),
 ),
 );
 }
}
class MyHomePage extends StatefulWidget {
 const MyHomePage({Key key}) : super(key: key);
 @override
 _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _textEditingController = TextEditingController();
 @override
 Widget build(BuildContext context) {
 return Scaffold(
 appBar: AppBar(
 title: Text("title"),
 ),
 body: Column(
 children: [
 InkWell(onTap: (){
 _onAlertButtonsPressed(context,"test","title",(){},(){});
 }, child: Text("test")),
 
 ],
 ),
 );
 }
}
 _onAlertButtonsPressed(context,String desc,String title,onPressYes,onPressNo) {
 return Alert(
 context: context,
 //style: alertStyle,
 title: title,
 desc: desc,
 buttons: [
 DialogButton(
 child: Text(
 "Yes",
 //style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressYes,
 //color: HexColor("#5344ed")
 ),
 DialogButton(
 child: Text(
 "No",
 // style: GoogleFonts.montserrat(color: Colors.white, fontSize: 18),
 ),
 onPressed: onPressNo,
 // color: HexColor("#5344ed"),
 )
 ],
 ).show(); // here need to change
}
answered Nov 16, 2021 at 7:03
Sign up to request clarification or add additional context in comments.

11 Comments

error still occur!
also you can try to remove the Container, does it return same issue
it gives me this error then A value of type 'Future<bool?>' can't be returned from the function '_onAlertButtonsPressed' because it has a return type of 'Widget'
remove the Widget keyword infront of _onAlertButtonsPressed and updated my answer please have a look it worked my machine
it works, but how can i access it in others files, i mean to say should create stateless widget and then passing this method? because i can't access _onAlertButtonsPressed it in other files.
|
1

Try below code hope its helpful to you. remove Container and Widget

onAlertButtonsPressed(context, desc, title, onPressYes, onPressNo) {
 return Alert(
 context: context,
 style: alertStyle,
 title: title,
 desc: desc,
 buttons: [
 DialogButton(
 child: Text(
 "Yes",
 ),
 onPressed: onPressYes,
 ),
 DialogButton(
 child: Text(
 "No",
 ),
 onPressed: onPressNo,
 )
 ],
 ).show();
 }
answered Nov 16, 2021 at 7:15

2 Comments

what a coincidence you wrote same answer as me
no @JahidulIslam is it not same I try it my machine also

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.