I am using Flutter to build a simple app, and I want to use the PaletteGenerator package to change the color theme of my components based on the current image. I'm a beginner to asynchronous programming. The following is the smallest relevant code:
PaletteGenerator a = await PaletteGenerator.fromImageProvider(NetworkImage('https://picsum.photos/250?image=9'));
I get this error:
I tried to use .then() and other means of asynchronous structure, but all of them give this same error.
Related
I want to load data continuously from server when app is start and stop it when app is closed.
So, how to achieve this ?
for example in flutter
start app.
method is start to running, whatever widget on screen .
close app.
method stop.
you can execute your funtion on bakcground.
people are usually use workmanager package. here : https://pub.dev/packages/workmanager
another option, you also can use flutter_isolate
final isolate = await FlutterIsolate.spawn(your-asycn-funtion, "hello2");
I am developing a flutter application in which I am using Mapbox to add turn-by-turn navigation. I have been looking at some tutorials to add markers to the map. However, I also want to give the user awareness of these specific points through voice output.
Is it possible to achieve this objective? Any resources or advice that you could provide, please?
Edit: How can I integrate the text to speech with the custom mapbox on my flutter app? For the Mapbox, we simply run the following code to enable voice instructions.
voiceInstructionsEnabled: true,
So how can I add the text conversion with it?
Truly appreciate any help
You can do it separately.
You can show markers on map with Mapbox
and prepare a string with all marker labels and use flutter_tts package to convert to speech as follows:
Future _speak() async {
await flutterTts.setVolume(volume);
await flutterTts.setSpeechRate(rate);
await flutterTts.setPitch(pitch);
if (_newVoiceText != null) {
if (_newVoiceText!.isNotEmpty) {
await flutterTts.speak(_newVoiceText!);
}
}
}
This snippet is taken from the example given in documentation:
https://pub.dev/packages/flutter_tts/example
I have a simple flutter app available on github having both Light and dark themes with a "Theme switch" button. On the main page, I have a Scaffold widget that takes it's background color property from the theme. Is there a way to check the background color of the Scaffold before and after switching themes during integration test with driver ?
Tried checking the active theme before and after switching themes, but fails:
group('Theme Test', () {
final themeButton = find.byValueKey('Button');
final themeProvider = ThemeProvider();
test('Switch between light and dark themes', () async {
expect(themeProvider.mode, ThemeMode.light); //check initial theme
await driver.tap(themeButton);
expect(themeProvider.mode, ThemeMode.dark); //check new theme
});
});
Full integration test here
My goal is getting the background color of the Scaffold before and after switching themes with driver
You are creating a new instance of the ThemeProvider() in your test group. The driver is creating your app, but won't be using the ThemeProvider() you created in the test.
It is not easy to communicate with your running app in Flutter Driver (you'll have to use driver request_data, but I don't recommend that for this problem).
You might want to look into the new integration tests for Flutter using the integration_test package. The new Integration tests are a combination of widgetTests and flutter driver tests. More info here; https://flutter.dev/docs/testing/integration-tests
The new integration test package will make it possible to communicate with the ThemeProvider() instance created by your app if you make it accessible. It will be possible to read the themeProvider.mode value then / check if the actual background color changed.
I run my application, but show this error. Before this i can run it. But now, It says "pr.dismiss is not defined in progress dialog." I have install package,and my code in flutter is not red colour but run it that got error in debug.
So how i can solves this problem?
I RUN THIS GOT PROBLEM
as per your source code you use https://pub.dev/packages/progress_dialog package for display progress dialog. so as per this package for dismiss dialog you need to use the below method.
pr.hide().then((isHidden) {
print(isHidden);
});
// or
await pr.hide();
So replace pr.dismiss() with the above method.
dart code
I expected this code to paint a black colored rectangle to screen but it didn't .I'm using flutter framework and I want to know that don't flutter support making apps like these or any mistake in my code. I just
wanted to make run flutter code without built-in flutter framework library
}
Yes, it's necessary. In dart only execute code inside the main method. Not like JavaScript or Python. It's like java/c. The only execution is the main method.