How to create Connection Snackbar with toast like Skype on Flutter? - dart

I used this code for check connection, Now I use showDialog. How to create like Skype connection snack bar with toast?
like this, https://imgur.com/a/jOlhe1M
try{
final result = await InternetAddress.lookup('google.com');
if(result.isNotEmpty && result[0].rawAddress.isNotEmpty){
showDialog(...)
}else{
showDialog(...)
}

You can benefit from the flutter toast package which will enable you to create the connecting.. toast. As for the SnackBar you can call it using Scaffold.of(context).showSnackBar().
I have added this picture from the Flutter toast package examples

Related

How to call a function is renderer.js/main.js from web page in electron

Newbie to electron here, I have built a simple web application with React JS and able to view it in a window by calling
window.loadFile('./build/index.html');
Now i would want to call a function located in say renderer.js/main.js which should read file system and return data to the web application.
I have already tried this in renderer.js
const { ipcRenderer } = require('electron');
document.getElementById('#button').addEventListener('click', function (event) {
//read file contents
console.log('file contents');
});
But there are 2 issues around here
The control is from the renderer.js, instead i would want the
control to be on the web page of React.
The data that is read should be returned back to web page, so that it can be displayed in the web page.
You should be able to import/require ipcRenderer directly on your react component scripts and maybe load the file on a lifecycle hook. The 'renderer.js' is just one way to execute client side javascript on the (electron-)web page but any other way also does the trick.
If you can't import or require electron from the webapp (I didn't play with the electron-react-boilerplate yet), then you could write a so called preload script, load that when you create the browser window (see that documentation) and put the ipcRenderer on window like so:
const {ipcRenderer} = require('electron')
window.ipcRenderer = ipcRenderer
Then you can access it from the react app.
You could directly use fs inside the event listener
const { ipcRenderer } = require('electron');
const fs = require("fs");
document.getElementById('#button').addEventListener('click', function (event) {
console.log(fs.readFileSync("some/file/path", "utf8"));
});
Electron exposes full access to Node.js both on main and renderer process
https://www.electronjs.org/docs/tutorial/application-architecture#using-nodejs-apis
You are building your electron renderer using React.
Please check this to clear what main process is and renderer is.
how to communicate between react and electron
This is the answer I posted before. Feel free to check this.
And here is the pre-requirement.
let mainWindow = new BrowserWindow(
{
width: 800,
height: 600,
webPreferences:{
nodeIntegration:true
}
});
You should enable the nodeIntegration flag when you are creating the BrowserWindow. So that you can use any Nodejs API at your renderer

How to mimic a pressing ENTER on a TextField in Flutter Tests

Given that tester.enterText will allow me to enter the text on a TextField in a flutter test, how would I mock pressing the DONE key on the android keyboard or pressing ENTER on my keyboard inside the textfield?
This would also be equivalent to checking for the pressing of the DONE button on the IOS/android keyboard
I found the implementation in the flutter repo tests # https://github.com/flutter/flutter/blob/7e445a17324ee7e615ef2c886d0cb9407853f338/packages/flutter/test/widgets/editable_text_test.dart#L558:
ex: await tester.testTextInput.receiveAction(TextInputAction.done);
// example
await tester.enterText(find.byKey(new Key('txtFieldKey')), 'Hello World!');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();

In Flutter How can I use my sign in Page to directly update the app drawer details?

How can I use my sign in Page to directly update the app drawer details?
Problems i am facing right now is that.
I have a sign in function and 2 classes.
1 that displays app drawer and 1 for login page which calls signinFunction.
Now I am not able to get where to place that sign in function.
if i make that global then it was unable to use setState function.
if i put that in appDrawer class.
i am unable to call my signin function from another class
I tried to understand you problem, did you try to use a StreamController to send event between your widgets ?
// global or common parent widget
final controller = new StreamController<MyEvent>();
// widget A
controller.add(new MyEvent());
controller.close(); // on dispose
// widget B
final subscription = controller.listen((event) { setState(() {}); });
subscription.cancel(); // on dispose

How to get text from alertbox in spectron-mocha-webdiverio

I am testing my electron app using spectron.
I am trying to get text from alertbox but getting an error.
I want to get the text from alert and if that is expected then accept it.
Test :
it('Check alert message', function() {
return this.app.client
.waitForExist('#associates', 20000).should.eventually.equal(true)
.click('#pq-associates')
.click('#submit-selection')
.alertText().should.eventually.equal("You have to select any one")
.should.eventually.exist
});
I am getting the following error
no alert open
Error: An attempt was made to operate on a modal dialog when one was not open.
But I can see the alert.
As discussed with the WebDriverio community it is difficult to handle the default alert() function. They suggested to implement my own alert() like function. So using https://github.com/limonte/sweetalert2 I implemented my own alert and the test is working fine.
Community discussion : https://gitter.im/webdriverio/webdriverio/archives/2017/10/04
Spectron issue : https://github.com/electron/spectron/issues/23

PCL Acr.UserDialogs. Custom styling for android

I am using Acr.UserDialogs plugin in my Xamarin MvvmCross project.
And everything was fine, but found that on Android 7.0 Alert dialogs has invisible Ok button (on previous versions it's displayed correctly).
I found only the way to redefine style, through AndroidResourceId property, when creating Alert dialog, but in my case this dialogs are created in PCL:
await userDialogs.AlertAsync(new AlertConfig { Message = message });
So it's not suitable for me to hardcode resourceId (they are regenerated, and common PCL embedded resources is a bad idea).
I tryed to implement my own class, derived from UserDialogImpl, or AbstractUserDialog, but there's a problem with resolving Activity in constructor.
I initialize dialogs in a such way:
UserDialogs.Init(() => Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity);
userDialogs = Mvx.Resolve<IUserDialogs>();
Saw, there is also an action parameter, passed to AlertAsync, but cannot find a way to handle it in android project.
Is there another way to customize a style for userDialog in android project ?
If you have a dialog theme...
<style name="YourDialogThemeHere" parent="Theme.AppCompat.DayNight.Dialog">
<item name="colorAccent">#color/accent</item>
</style>
...then you can theme all of the dialogs in one go like this in your Droid project:
var dialogStyle = Resource.Style.YourDialogThemeHere;
AlertConfig.DefaultAndroidStyleId = dialogStyle;
PromptConfig.DefaultAndroidStyleId = dialogStyle;
ConfirmConfig.DefaultAndroidStyleId = dialogStyle;
ActionSheetConfig.DefaultAndroidStyleId = dialogStyle;
DatePromptConfig.DefaultAndroidStyleId = dialogStyle;
TimePromptConfig.DefaultAndroidStyleId = dialogStyle;
LoginConfig.DefaultAndroidStyleId = dialogStyle;
If you want to react to the dialog in the Droid project then you can send a message from the PCL project using the MvvmCross Messenger plugin. The platform specific view can subscribe to the message while the PCL project publishes the message.

Resources