I am currently able to share the text on top of the image using share package but I want to share the image and text along with it without my icons of refresh and share. Couldn't find any answers for this. Have used multiple share packages but couldn't achieve the expected result.
Widget build(BuildContext context) {
return Scaffold(
body: Stack(children: <Widget>[
Container(
constraints: BoxConstraints.expand(),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage("${imgUrl}$count"),
fit: BoxFit.fill)
),
),
FutureBuilder<Advice>(
future: advice,
builder: (context, snapshot) {
if (snapshot.hasData) {
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 30.0),
child: FadeTransition(
opacity: _animation,
child: Text(
snapshot.data!.adviceText,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 30.0,
color: Colors.white,
fontFamily: 'quoteScript'),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.refresh, color: Colors.white),
onPressed: () async {
setState(() {
_controller.reset();
_controller.forward();
count++;
advice = fetchAdvice();
});
},
),
IconButton(
icon: Icon(Icons.share, color: Colors.white),
onPressed: () {
Share.share("Here's an advice for you: ${snapshot.data!.adviceText}");
},
),
],
),
],
),
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
// By default, show a loading spinner.
return Center(child: CircularProgressIndicator());
},
),
]),
);
}
This is the text and image widget. Can be shared with the dynamic text.
SHARE: The best way I think is to use screenshot package to capture the widget which contains both image and text that you need to share, then share it as a picture with share_plus package.
For instance:
// Create a controller
ScreenshotController screenshotController = ScreenshotController();
[...]
// Wrap the widget which you want to capture with `Screenshot`
Screenshot<Widget>(
controller: screenshotController,
child: Container(
child: [...]
),
),
[...]
// Create a method to take a screenshot and share it
// This method I get from my project, so you can modify it to fit your purpose
Future<void> shareScreen(String title, String name) async {
final screenShot = await screenshotController.capture();
if (screenShot != null) {
final Directory tempDir = await getTemporaryDirectory();
final File file = await File('${tempDir.path}/$name').create();
await file.writeAsBytes(screenShot);
await Share.shareFiles(<String>[file.path], subject: title, text: name);
file.delete();
}
}
Then replace the Share.share method in the below example with the shareScreen method just created above.
HIDE BUTTON: You can create a new variable like bool isSharing = false; to control the visible state of those 2 buttons. The important part is the Share.share method must be an async method to make the code works because it needs await to know when the share action is done.
For instance:
[...]
if (!isSharing) // <--- Add this line
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.refresh, color: Colors.white),
onPressed: () async {
setState(() {
_controller.reset();
_controller.forward();
count++;
advice = fetchAdvice();
});
},
),
IconButton(
icon: Icon(Icons.share, color: Colors.white),
// And modify here <---
onPressed: () async {
setState(() => isSharing = true); // Hide the buttons
await Share.share(
"Here's an advice for you: ${snapshot.data!.adviceText}");
setState(() => isSharing = false); // Show the buttons
},
),
],
),
[...]
Related
Hello there hope you all are doing well. Coming to the point I am developing a weather application in flutter its working fine but when it comes to getting weather by city its not working actually its getting all the data but not updating data in UI.
Updating UI
void updateUI(var weatherData) {
if (weatherData == null) {
city = '';
temperature = 0;
weatherMessage = 'Unable to fetch data';
}
id = weatherData['weather'][0]['id'];
weatherIcon = weatherModel.getWeatherIcon(id);
city = weatherData['name'];
double temp = weatherData['main']['temp'];
temperature = temp.toInt();
weatherMessage = weatherModel.getMessage(temperature);
description = weatherData['weather'][0]['description'];
}
Recieving city name(Here is the actual problem i guess)
FlatButton(
onPressed: () async {
dynamic typedname = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Cityscreen()));
setState(
() async {
dynamic weatherData =
await weatherModel.getCityLocation(typedname);
updateUI(weatherData);
},
);
},
Getting city location
Future<dynamic> getCityLocation(String cityname) async
{
Network_helper network_helper=Network_helper('https://api.openweathermap.org/data/2.5/weather?q=$cityname&appid=$key');
var weatherData=await network_helper.getData();
return weatherData;
}
City screen stateful widget
class _CityscreenState extends State<Cityscreen> {
late String cityName;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/back1.jpg'),
fit: BoxFit.fill,
),
),
constraints: BoxConstraints.expand(),
child: SafeArea(
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Icon(
Icons.arrow_back_ios,
size: 50.0,
),
),
),
Container(
padding: EdgeInsets.all(20.0),
child: TextField(
style: TextStyle(
color: Colors.black,
),
decoration: kTextFieldDecoration,
onChanged: (value)
{
cityName=value;
},
),
),
FlatButton(
onPressed: (){
Navigator.pop(context,cityName);
},
child: Text(
'Get weather',
style: TextStyle(
fontSize: 30,
),
),
color: Colors.deepPurpleAccent,
),
],
),
),
),
Thanks in advance.
Use setstate in then section in navigation push code.
Navigator.push(context,MaterialPageRoute(
builder: (context) => Cityscreen())).then((value) {
setState(() async {
dynamic weatherData =
await weatherModel.getCityLocation(typedname);
updateUI(weatherData);
});
});
If answer by Laxman doesn't work well try separating setState and async code...
you can call getCityLocation() store value in a temp variable and then call setState() on assignment.
Some reference to back my answer SO post
Hello guys I have registration form with checkbox to be enabled in order to allow registration.
I need my user to do checkbox checked to have button enabled otherwise an tooltip will be shown.. like... " u need to accept terms and condition to register... "
This is the part of the CheckBox:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Theme(
data: ThemeData(unselectedWidgetColor: Colors.white,),
child: Checkbox(
focusColor: Colors.lightBlue,
activeColor: Colors.orange,
value: rememberMe,
onChanged: (newValue) {
setState(() {
rememberMe = (newValue);
});
},
),
),
RichText(
text: TextSpan(children: [
TextSpan(
text: 'Accetto le condizioni e ',
style: TextStyle(fontSize: 10),
),
TextSpan(
text: 'il trattamento dei dati personali ',
style: TextStyle(fontSize: 10,decoration: TextDecoration.underline,),
),
]),
)
],
),
and this the "registration Button"
ButtonTheme(
minWidth: 100,
height: 50.0,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 10,
onPressed: () async {
setState(() {
showSpinner = true;
});
try {
final newUser =
await _auth.createUserWithEmailAndPassword(
email: email, password: password);
if (newUser != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
}
setState(() {
showSpinner = false;
});
} catch (e) {
print(e);
}
},
color: Color(0xFF1f2032),
child: Text(
'SIGNUP',
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
),
There are certain things which I would like to give you an insight about. Which will help you surely, so follow along.
Pointers
Read upon Flutter Form and it's Validation, which answers your question on showing up the error message under your forms for the validations
One very useful widget to achieve what you want is Flutter Tooltip Unfortunately, you cannot bring up the tooltip which you wanted to do programmatically
Workaround: Do use any of these to show up you message
Snackbar Flutter
Flutter AlerDialog
Simply show up a text, like a validator for the form under the checkbox like I will demonstrate in the code for you
Now, I have demonstrated both of them in this code, but the code is not similar. It would be enough to you let you know the best practices you can do along with your tooltip message showcase
Please note: To make a tooltip like structure using Container(), you can follow this answer, will help you in a great extent
class _MyHomePageState extends State<MyHomePage> {
bool rememberMe = false;
// this bool will check rememberMe is checked
bool showErrorMessage = false;
//for form Validation
final _formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: TextFormField(
validator: (value) {
// retiurning the validator message here
return value.isEmpty ? "Please enter the message" : null;
}
)
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Accept Terms & Conditions'),
SizedBox(width: 20.0),
Checkbox(
focusColor: Colors.lightBlue,
activeColor: Colors.orange,
value: rememberMe,
onChanged: (newValue) {
setState(() => rememberMe = newValue);
}
)
]
),
// based up on this bool value
showErrorMessage ?
Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(80.0)
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text('Please accept the terms and conditions to proceed...')
)
)
: Container(),
SizedBox(height: 20.0),
RaisedButton(
child: Text('Submit'),
onPressed: (){
// for your form validation
if(_formKey.currentState.validate()){
// do your success operation here!
// checking for the rememberValue
// and setting the message bool data
if(rememberMe != true)
setState(() => showErrorMessage = true);
else
setState(() => showErrorMessage = false);
}
}
)
]
)
)
);
}
}
How it works?
It will first check whether the form is empty, if it not, then checks whether the checkbox is empty or not
Fun Fact
You can use the above logic or bool showErrorMessage, to show anything, be it, SnackBar, AlertDialog or the message which I showed in the above code.
Result
You need to pass null to the onPressed of a Button to make it disabled. So you'll need to pass null to the onPressed of the RaisedButton when rememberMe is false.
ButtonTheme(
minWidth: 100,
height: 50.0,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 10,
onPressed: rememberMe ? () async {
setState(() {
showSpinner = true;
});
try {
final newUser =
await _auth.createUserWithEmailAndPassword(
email: email, password: password);
if (newUser != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
}
setState(() {
showSpinner = false;
});
} catch (e) {
print(e);
}
} : null, // make it null if false
color: Color(0xFF1f2032),
child: Text(
'SIGNUP',
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
),
I have a Dialog class in which I want to show different designations that could be assigned to an employee.
In the beginning, I tried to use only a RaisedButton to select the desired designations. Within the App, the Button should change Colors. This part is found within a StatefulWidget.
I also tried a modified version, where I created a new StatefulWidget only for the Dialog part but this part did not have any effect, thus I thought to implement a SwitchListTile to do the same thing.
The SwitchListTile gets activated and deactivated although only the true value gets registered. This means that when I deactivate (swipe to left) the code does not go within the following setState:
setState(() { hEnabled[hDesignations[index].designation] = value; });
Also when the hEnabled Map gets changed within the setState method the following code does not re-run to change the color of the container:
color: hEnabled[hDesignations[index].designation] ? Colors.green : Colors.grey,
Part with the Dialog:
Widget buildChooseDesignations(
BuildContext context, List<Designation> hDesignations) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(8.0),
),
child: _buildDialogChild(context, hDesignations),
);
}
_buildDialogChild(BuildContext context, List<Designation> hDesignations) {
//todo: when editing an employee I need the chosen designations (have to pass a list)
Map<String, bool> hEnabled = new Map<String, bool>();
for (var i = 0; i < hDesignations.length; i++) {
hEnabled[hDesignations[i].designation] = false;
}
return Container(
height: 200.0,
//todo: width not working properly
width: 50,
child: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: hDesignations.length,
itemBuilder: (context, index) {
return Row(
children: <Widget>[
Expanded(
child: Container(
width: 10,
color: hEnabled[hDesignations[index].designation]
? Colors.green
: Colors.grey,
padding: EdgeInsets.only(left: 80),
child: Text(hDesignations[index].designation,
style: TextStyle(fontWeight: FontWeight.bold),),
),
),
Expanded(
child: SwitchListTile(
value: hEnabled[hDesignations[index].designation],
onChanged: (bool value) {
setState(() {
hEnabled[hDesignations[index].designation] =
value;
});
}),
)
],
);
}),
),
SizedBox(
height: 15.0,
),
RaisedButton(
color: Colors.blueGrey,
child: Text(
'set',
style: TextStyle(color: Colors.white),
),
onPressed: () {
//todo: save the 'newly' selected designations in a list on set click
},
)
],
),
);
}
The Dialog is called when I click on the Add + FlatButton and looks like this:
ButtonTheme(
height: 30.0,
// child: Container(),
child: FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
color: Colors.blueGrey.shade200,
onPressed: () {
//todo add Dialog
// List<Designation> hList = state.designations;
showDialog(
context: context,
builder: (context) => buildChooseDesignations(
context, state.designations));
// DesignationDialog(
// designations:state.designations));
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0)),
child: Text(
'Add +',
style: TextStyle(color: Colors.black),
),
),
),
Found the problem :)
First I did re-write everything into a new StatefulWidget. This I needed since I want that my widget gets re-build after I click on the SwitchListTile to re-color my Container.
Then I had to move my hEnabled (re-named hChecked) map outside the state. The reason was that the widget would re-build all the everything including the initialization of this map, making the user's input useless.
The same applies to the RaisedButton Widget.
Here is my code:
class DesignationDialog extends StatefulWidget {
final List<Designation> designations;
final Map<String, bool> hChecked;
DesignationDialog({Key key, this.designations, this.hChecked}) : super(key: key);
#override
_DesignationDialogState createState() => _DesignationDialogState();
}
class _DesignationDialogState extends State<DesignationDialog> {
_buildDialogChild(BuildContext context, List<Designation> hDesignations) {
//todo: when editing an employee I need the chosen designations (have to pass a list)
// for (var i = 0; i < hDesignations.length; i++) {
// hChecked[hDesignations[i].designation] = false;
// }
return Container(
height: 200.0,
child: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: hDesignations.length,
itemBuilder: (context, index) {
// return ButtonTheme(
// //todo: fix the width of the buttons is not working
// minWidth: 20,
// child: RaisedButton(
// color: widget.hChecked[hDesignations[index].designation]
// ? Colors.green
// : Colors.grey,
// child: Text(hDesignations[index].designation),
// onPressed: () {
// //todo mark designation and add to an array
// setState(() {
// widget.hChecked[hDesignations[index].designation] =
// !widget
// .hChecked[hDesignations[index].designation];
// });
// },
// ),
// );
// -- With Switch
return Row(
children: <Widget>[
Expanded(
child: Container(
child: Text(hDesignations[index].designation),
width: 10,
color: widget.hChecked[hDesignations[index].designation]
? Colors.green
: Colors.grey,
)),
Expanded(
child: SwitchListTile(
value: widget.hChecked[hDesignations[index].designation],
onChanged: (bool value) {
setState(() {
widget.hChecked[hDesignations[index].designation] =
value;
});
}),
)
],
);
// -- end
}),
),
SizedBox(
height: 15.0,
),
RaisedButton(
color: Colors.blueGrey,
child: Text(
'set',
style: TextStyle(color: Colors.white),
),
onPressed: () {
//todo: save the 'newly' selected designations in a list on set click
},
)
],
),
);
}
#override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(8.0),
),
child: _buildDialogChild(context, widget.designations),
);
}
I am trying to call a method from navbar, when I call the object the image has been selected not appears in the screen.
My goal is to do this, when I Click in Gallery and select new image, show this like in Screen 2.
The code for this interactions,
File imageFile;
_openGallery(BuildContext context) async{
var picture = await ImagePicker.pickImage(source:ImageSource.gallery);
this.setState((){
imageFile = picture;
});
Navigator.of(context).pop();
}
_openCamera(BuildContext context) async{
var picture = await ImagePicker.pickImage(source:ImageSource.camera);
this.setState((){
imageFile = picture;
});
Navigator.of(context).pop();
}
And the build widget
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
_decideImageView(),
RaisedButton(onPressed: (){
_showChoiceDialog(context);
},child: Text('Select Image'),),
_decideButton(context)
],
),
),
),
bottomNavigationBar: BottomNavigationBar(
type:BottomNavigationBarType.fixed,
onTap: (int index) {
if (index==0)
_openGallery(context);
if (index == 1)
_openCamera(context);
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.photo_library),
title: Text('Home')
),
BottomNavigationBarItem(
icon: Icon(Icons.camera_alt),
title: Text('Camera')
),
],
),
);
}
The function to decide if you will see a text asking for select a image or return the image on the screen is this one below, the method is called _decideImageView.
Widget _decideImageView(){
if(imageFile == null){
return Text('Kein Bild ausgewählt',
style: TextStyle(
color:Colors.black,
fontFamily: 'Lato',
fontSize: 25,
letterSpacing: 1.0
), );
}
else{
return Image.file(imageFile,width:400,height:400);
}
}
Try to remove this: Navigator.of(context).pop();
on the two ways to pick the picture, that's work for me, but you need to know that's not the best way to create an image picker.
I am passing data from my alertdialog to item of listview.
Where I can find information about it?
I tried use TextEditingController, with Navigation Routes. And I used materials from this Tutorial
This is my code:
class MeasurementsScreen extends StatefulWidget {
#override
_MeasurementsScreenState createState() => _MeasurementsScreenState();
}
class _MeasurementsScreenState extends State<MeasurementsScreen> {
List<_ListItem> listItems;
String lastSelectedValue;
var name = ["Рост", "Вес"];
var indication = ["Введите ваш рост", "Введите ваш вес"];
TextEditingController customcintroller;
void navigationPageProgrammTrainingHandler() {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => ProgrammTrainingHandler()),
);
}
#override
void initState() {
super.initState();
initListItems();
}
Future<String> createAlertDialog(BuildContext context, int indexAl){
customcintroller = TextEditingController();
if(indexAl < 2){
return showDialog(context: context, builder: (context){
return AlertDialog(
title: Text(name[indexAl]),
content: TextField(
textDirection: TextDirection.ltr,
controller: customcintroller,
style: TextStyle(
color: Colors.lightGreen[400],
fontSize: 18.5),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(bottom: 4.0),
labelText: indication[indexAl],
alignLabelWithHint: false,
),
keyboardType: TextInputType.phone,
textInputAction: TextInputAction.done,
),
actions: <Widget>[
FlatButton(
child: const Text('ОТМЕНА'),
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: const Text('ОК'),
onPressed: () {
Navigator.of(context).pop(customcintroller.text.toString());
},
),
],
);
});
} else if (indexAl > 1){
navigationPageProgrammTrainingHandler();
}
}
#override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Color(0xff2b2b2b),
appBar: AppBar(
title: Text(
'Замеры',
style: new TextStyle(
color: Colors.white,
),),
leading: IconButton(
icon:Icon(Icons.arrow_back),
color: Colors.white ,
onPressed:() => Navigator.of(context).pop(),
),
),
body: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: listItems.length,
itemBuilder: (BuildContext ctxt, int index){
return GestureDetector(
child: listItems[index],
onTap: () {
createAlertDialog(context, index).then((onValue){
});
}
);
},
),
);
}
void initListItems() {
listItems = [
new _ListItem(
bgName: 'assets/images/soso_growth.jpg',
name: customcintroller.text.toString().isEmpty == false ? customcintroller.text.toString() : "Рост",
detail: "Нажми, чтобы добавить свой рост"),
new _ListItem(
bgName: 'assets/images/soso_weight.jpg',
name: customcintroller.text.toString().isEmpty == false ? customcintroller.text.toString() : "Вес",
detail: "Нажми, чтобы добавить свой вес"),
new _ListItem(
bgName: 'assets/images/soso_chest.jpg',
name: "Грудь",
detail: "PRO-версия"),
new _ListItem(
bgName: 'assets/images/soso_shoulder.jpg',
name: "Плечи",
detail: "PRO-версия"),
new _ListItem(
bgName: 'assets/images/soso_biceps.jpg',
name: "Бицепс",
detail: "PRO-версия")
];
}
}
class _ListItem extends StatelessWidget {
_ListItem({this.bgName, this.name, this.detail});
// final int index;
final String bgName;
final String name;
final String detail;
#override
Widget build(BuildContext context) {
return Container(
height: 180.0,
margin: const EdgeInsets.symmetric(
vertical: 1.0,
),
child: new Stack(
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage(bgName),
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.45), BlendMode.darken),
fit: BoxFit.cover,
alignment: Alignment.center),
),
child: new SizedBox.expand(
child: Container(
alignment: Alignment.center,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Text(
name,
style: new TextStyle(fontSize: 29.0, color: Colors.white),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: new Text(
detail,
style:
new TextStyle(fontSize: 16.0, color: Colors.white),
),
)
],
),
),
),
),
],
),
);
}
}
I expect to get text from alertdialog.
Do you want to update data in your current screen or in another Scaffold/screen? Solution for the first option would be to set your desired data in a setState or pass it to a Model (with ScopedModel) and update the view. E.g. :
FlatButton(
child: const Text('ОТМЕНА'),
onPressed: () {
setState(() {
myData = data;
Navigator.of(context).pop();
}); // not sure if this will work, could you try?
}
),
If it is in a new/other screen, you can pass it in the Navigator like for example:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewScreen(data: myData),
),
);
},
Does this solve your problem? Otherwise, please elaborate on what it is you need.
I tried to use Navigator.of(context).pop("OK"); in the AlertDialog but it doesn't work.
use ValueChanged as a param on the showDialog method and it works well.
class Dialogs{
static showAlertDialog(BuildContext context, String title, String message,
{List<String> actions, ValueChanged onChanged}) async {
if (actions == null) {
actions = ["OK"];//default OK button.
}
await showDialog(
context: context,
child: AlertDialog(
title: Text(title ?? 'Message'),
content: Text(message),
actions: actions
.map((e) => new FlatButton(
child: Text(e.trim()),
onPressed: () {
Navigator.of(context).pop(e.trim());
if (onChanged != null) {
onChanged(e.trim());
}
}))
.toList(),
),
);
}
}
the caller looks like
_onProcess(){
String result = "";
await Dialogs.showAlertDialog(context, "Warning", "Warning message", actions: ["OK", "Cancel"],
onChanged: (value) {
result = value;
});
if (result != "OK") {
Dialogs.showSnackBarMessage(context, "Cancel This PTN");
return;
}
....process with the OK logic.
}
If you want to change an item of the list you can do that with setState() before calling Navigator.pop(). It is not possible to pass data through Navigator.pop() though, as you may be able to do with Navigator.push(... MyPage(data)).
You could achieve what you want through State management. You can check for state management tutorials in general. But the two practices that are used most in my opinion are Scoped Model and BLoC pattern. These practices help you pass data through the widget tree back and forward. I would recommend BLoC pattern there are many tutorials about it. Also there is a package which can be very helpful with BLoC pattern: flutter_bloc.