How to use conditional if statement in flutter for ontap () - flutter

How do i use conditional ontap() on flutter, when i press the button the app checks if im singed in then if not it goes to the other function.
onTap: () if (appStore.isLoggedIn) {
async {
await userService.getUser(
email: widget.providerData.email.validate()).then((
value) {
widget.providerData.uid = value.uid;
}).catchError((e) {
log(e.toString());
});
UserChatScreen(receiverUser: widget.providerData).launch(
context);
}
else {
SignInScreen().launch(context);
}
},
).expand(),

onTap: () {
if(conditions) {
...
}
},

Related

how to wait till firebase function get all necessary values

i wanted to wait till firebase auth retrive verification_id and then return function
but in current code variable value newVerificationId is getting return first as error without updating from firebase
Future<String> phoneAuthontication(
phoneNumberController,
) async {
String newVerificationId = "error";
try {
await auth.verifyPhoneNumber(
phoneNumber: phoneNumberController.text,
verificationCompleted: (_) {},
verificationFailed: (e) {
print(e);
},
codeSent: (String verificationId, int? token) {
print("====" + verificationId);
newVerificationId = verificationId;
},
codeAutoRetrievalTimeout: (e) {
print(e);
});
} catch (e) {
print(e);
}
print("---" + newVerificationId);
return newVerificationId;
}

Black Screen agora remote view flutter

I am trying to implement the flutter Agora SDK Livestream with agora and I'm getting a black screen on remote view, local view works fine.
Please what am I doing wrongly?
What I tried:
double-check if all permissions are enabled
recreate a new application In agora.io
switch devices
check internet connectivity
This is the code for the implementation:
void initEngine() async {
_engine = await RtcEngine.create(agoraKey);
addListeners();
_engine.enableVideo();
_engine.startPreview();
_engine.enableAudio();
_engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
print(widget.isBroadcaster);
if (("${widget.userData.uid}${widget.userData.name}" == widget.channeId)) {
_engine.setClientRole(ClientRole.Broadcaster);
print('broadcaster');
} else {
_engine.setClientRole(ClientRole.Audience);
print('audience');
}
_joinChannel();
}
_renderVideo(
user,
isScreenSharing,
) {
return AspectRatio(
aspectRatio: 16 / 9,
child: "${user.uid}${user.name}" == widget.channeId
? isScreenSharing
? kIsWeb
? const RtcLocalView.SurfaceView.screenShare()
: const RtcLocalView.TextureView.screenShare()
: const RtcLocalView.SurfaceView(
zOrderMediaOverlay: true,
zOrderOnTop: true,
)
: isScreenSharing
? kIsWeb
? const RtcLocalView.SurfaceView.screenShare()
: const RtcLocalView.TextureView.screenShare()
: isRendered
? RtcRemoteView.TextureView(
uid: _remoteUids[0],
channelId: widget.channeId,
)
: Center(
child: Text(
'No Video',
style: GoogleFonts.balooPaaji2(
fontSize: 15,
),
),
),
);
}
void addListeners() {
_engine.setEventHandler(RtcEngineEventHandler(
joinChannelSuccess: (channel, uid, elapsed) async {
debugPrint('joinChannelSuccess $channel $uid $elapsed');
print(
'joinChannelSuccess ======================================================> $uid');
},
leaveChannel: (stats) {
debugPrint('leaveChannel $stats');
setState(() {
_remoteUids.clear();
});
},
userJoined: (uid, elapsed) {
debugPrint('userJoined $uid $elapsed');
setState(() {
print('userJoined=====================>:$_remoteUids');
_remoteUids.add(uid);
setState(() {
isRendered = true;
});
print('=======>====>$_remoteUids');
});
},
userOffline: (uid, reason) {
debugPrint('userOffline=====================> $uid $reason');
setState(() {
_remoteUids.remove(uid);
});
},
userMuteAudio: (uid, muted) {
debugPrint('userMuteAudio $uid $muted');
},
userMuteVideo: (uid, muted) {
debugPrint('userMuteVideo $uid $muted');
},
userEnableVideo: (uid, enabled) {
debugPrint('userEnableVideo $uid $enabled');
},
error: (error) {
debugPrint('error $error');
},
));
print('=====.$_remoteUids========');
}
void _joinChannel() async {
//leave the current channel
if (defaultTargetPlatform == TargetPlatform.iOS) {
await [Permission.microphone, Permission.camera].request();
await _engine.joinChannel(
tempToken, 'testing_channel', widget.channeId, 0);
debugPrint('joinChannelWithUserAccount ${widget.channeId} ');
} else {
await [Permission.microphone, Permission.camera].request();
await _engine.joinChannel(
tempToken, 'testing_channel', widget.channeId, 0);
debugPrint('joinChannelWithUserAccount ${widget.channeId} ');
}
}
}
Make sure the Uid in Rtc remote view is the same with the user went live and the user joined to live
RtcRemoteView.SurfaceView(
uid: ,
channelId:,
)

Flutter await for try catch [duplicate]

This question already has answers here:
How to Async/await in List.forEach() in Dart
(7 answers)
Closed 2 years ago.
I'm using firebase cloud firestore
inside a Future function I have this
try {
categories.forEach((element) async {
await FirebaseFirestore.instance.collection('Categories').add({
'name': element[0],
'imageUrl': element[1],
});
print('done');
});
print('complete');
} catch (e) {
CoolAlert.show(
context: context,
type: CoolAlertType.error,
content: Text(e),
text: "Upload Failed",
onConfirmBtnTap: () {
Navigator.pop(context);
Navigator.pop(context);
});
}
'completed' printed before 'done'
how to make it the opposite?
how to await for the forEach function to end first then proceed
and even if I moved print('complete'); after the whole try catch block it doesn't work either
so is there a way to wait try catch block?
You can use Future.foreach OR Future.doWhile
Future.doWhile :
int index = 0;
try {
Future.doWhile(() {
if (index < categories.length) {
await FirebaseFirestore.instance.collection('Categories').add({
'name': categories[index][0],
'imageUrl': categories[index][1],
});
print('done');
index++;
return true;
} else {
print('complete');
return false;
}
});
} catch (e) {
CoolAlert.show(
context: context,
type: CoolAlertType.error,
content: Text(e),
text: "Upload Failed",
onConfirmBtnTap: () {
Navigator.pop(context);
Navigator.pop(context);
});
}
Future.foreach:
try {
Future.forEach(categories,(element) async {
await FirebaseFirestore.instance.collection('Categories').add({
'name': element[0],
'imageUrl': element[1],
});
print('done');
});
print('complete');
} catch (e) {
CoolAlert.show(
context: context,
type: CoolAlertType.error,
content: Text(e),
text: "Upload Failed",
onConfirmBtnTap: () {
Navigator.pop(context);
Navigator.pop(context);
});
}

Extj 4 controller this.control listeners debounce?

How can I debounce listeners specified inside of controller using
this.control
?
Using the sample from the docs, you could use Ext.Function.defer() inside your
Ext.define('AM.controller.Users', {
init: function() {
this.control({
'useredit button[action=save]': {
click: function() {
//delay function call for a couple of seconds
Ext.Function.defer(this.updateUser, 2000, this);
}
}
});
},
updateUser: function(button) {
console.log('clicked the Save button');
}
});
Ext.define('AM.controller.Users', {
init: function() {
this.control({
'useredit button[action=save]': {
click: {
buffer:2000,
fn:this.updateUser
}
}
}
});
},
updateUser: function(button) {
console.log('clicked the Save button');
}
});

Changed values of collection not reflected in backbone.js

When i click on submit button i can't see the changes made to collection although on every click of checkbox change event is fired
//Model
Wine = Backbone.Model.extend({
// Toggle the `IsSelected` state of this todo item.
toggle: function () {
debugger;
this.save({
IsSelected: !this.get('IsSelected')
});
}
});
//Collection
WineCollection = Backbone.Collection.extend({
model: Wine,
url: "http://localhost/Industries/data/data.json"
});
//This is a list view collection and individual List item and here we bind the click event of checkbox and in Submit button here we check the the changed values
WineListView = Backbone.View.extend({
el: $('#wineList'),
initialize: function () {
alert($('#divBtnSubmit'));
wineList.bind("reset", this.render, this);
},
render: function () {
wineList.each(function (wine) {
$(this.el).append(new WineListItemView({ model: wine }).render().el);
}, this);
return this;
}
});
//Submit button
WinedivBtnSubmit = Backbone.View.extend({
el: $('#divBtnSubmit'),
initialize: function () {
this.render();
},
render: function () {
// Load the compiled HTML into the Backbone "el"
var template = _.template($("#save-div").html(), {});
this.$el.append(template);
},
events: {
"click #divBtnSubmit1": "saveWine"
},
saveWine: function () {
debugger;
wineList.each(function (wine) {
alert(wine.get('ID') + '<<>>' + wine.get('IsSelected'));
});
return false;
// alert(this.modelmodels);
}
});
//Indiviual list item
WineListItemView = Backbone.View.extend({
tagName: "li",
template: _.template($('#wine-list-item').html()),
initialize: function () {
},
events:
{
'click .toggle': 'toggleVisible'
},
toggleVisible: function () {
this.model.toggle();
},
render: function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
var AppRouter = Backbone.Router.extend({
routes: {
"": "list",
"wines/:id": "wineDetails"
},
initialize: function () {
},
list: function () {
// this.wineList = new WineCollection();
this.wineListView = new WineListView();
this.btn = new WinedivBtnSubmit();
// wineList.fetch();
},
wineDetails: function (id) {
this.wine = this.wineList.get(id);
this.wineView = new WineView({ model: this.wine });
this.wineView.render();
}
});
wineList = new WineCollection();
wineList.fetch();
// on every click of checkbox this event is fired
wineList.bind("change", function () {
alert('list changed');
});
var app = new AppRouter();
Backbone.history.start();