i tryed testdrive for flutter installed on windows as here https://flutter.dev/docs/get-started/test-drive
defaut application generated work, well, but when i try to follow the snd part at
https://flutter.dev/docs/get-started/codelab
i get errors:
error: The function 'MyApp' isn't defined. (undefined_function at [flutter_app007] lib\main.dart:3)
error: 'MaterialApp' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:8)
error: 'Scaffold' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:10)
error: 'AppBar' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:11)
for this code in main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: const Text('Hello World'),
),
),
);
}
}
i checked flutter doctor, but show nothing bad.. any idea?
go to the project directory and open windows cmd. and try flutter run
ok, i finally resolved the problem.
when i was typed 'flutter_console.bat', i was get after, 'mysql is unknow program '. i finally founded that an install of MySQL Fabric 1.5 & MySQL Utilities 1.5\ setted his path in PATH env variable. this path poisonned result path integration , returning 'mysql is unknow program' and stopping project generation.. . desinstalling the mysql software solved the problem by cleaning path from his entry and now, the project can be created and work as expected..
very strange, no..?
Related
I'm trying to create an app that performs a Firebase authorization on a desktop.
I didn't find any full sample code for this so I started by create a basic demo project on VScode.
As soon as I add the package flutter pub add firebase_auth_desktop (without adding code to the app), I get errors when I try to run the app.
/C:/Users/yvan_/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core-1.24.0/lib/src/firebase_app.dart(18,25): error G75B77105: Member not found: 'FirebaseAppPlatform.verifyExtends'.
[C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
/C:/Users/yvan_/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_platform_interface-6.10.1/lib/src/action_code_info.dart(65,15): error GE5CFE876: The method 'FallThroughError' isn't defined for the class 'ActionCodeInfo'. [C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(247,5): error MSB8066: Custom build for 'C:\FDSTiming\Project\Flutter\app3\build\windows\CMakeFiles\18de2b4c67371752531dc30d7008f913\flutter_windows.dll.rule;C:\FDSTiming\Project\Flutter\app3\build\windows\CMakeFiles\122a37675ed5a5d637290377de62a3e1\flutter_assemble.rule;C:\FDSTiming\Project\Flutter\app3\windows\flutter\CMakeLists.txt' exited with code 1. [C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
Exception: Build process failed.
The code is:
import 'package:flutter/material.dart';
//import 'package:firebase_auth_desktop/firebase_auth_desktop.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello World!'),
),
),
);
}
}
And pubspec.yaml:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
firebase_auth_desktop: ^1.0.2
Any idea?
I managed to get rid of the first error by adding:
firebase_core_platform_interface: 4.5.1
firebase_messaging: ^13.0.4
But didn't find any clues for the others errors
The flutter firebase_core dependency currently not supported by windows platform.
I have this question. My code actually working but when I click my button there is no new sound. I actually change the name of directory folder but it didn't work.
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'dart:math';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
void playSound () {
final player = AudioPlayer();
int soundNumber = Random().nextInt(5) + 1;
player.setSource(AssetSource('sounds/note$soundNumber.wav'));
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child:TextButton
(onPressed: () {
playSound();
},
child:const Text('Click Me')),
),
),
),
);
}
}
Here is the result:
E/flutter ( 8119): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)]
Unhandled Exception: Unable to load asset: assets/audios/note1.wav
E/flutter ( 8119): #0 PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:237:7)
E/flutter ( 8119): <asynchronous suspension>
yaml file :
assets:
- assets/sounds/
You have to add this file in assets section in pubspec.yaml file
assets:
- assets/audios/note1.wav
try to move your sub audio folder out of your former asset folder that comes by default . and place it direct to your project new folder like lib folder in the first level
sometimes flutter does not see the external files .
and for better work done clean your engine .
As I'm working in the Xylophone project
I did this to run my APP:
You can add new project and then rewrite your code line by line and debug it
probably it is because of some change that you have done.
Change the package I recommend you to add the new package in new projects
PS: If you are in windows before everything quit the Android Studio from the Task Manager and shut down your computer then start everything from the beginning
If you find new solution let me know
Thank you
The flutter team has given the following flutter project created by them, to learn from. https://github.com/flutter/codelabs/tree/main/boring_to_beautiful
through their codelab.
I cloned the repo and tried to start the app. But it throws the following error.
════════ Exception caught by widgets library
The following assertion was thrown building IconTheme(color: Color(0xdd000000)):
This GoRouteInformationParser needs to be used with GoRouteInformationProvider, did you forget to pass in GoRouter.routeInformationProvider to the Router constructor?
'package:go_router/src/go_route_information_parser.dart':
package:go_router/src/go_route_information_parser.dart:1
Failed assertion: line 148 pos 13: 'routeInformation is DebugGoRouteInformation'
From this error msg, I could understand that 'routeInformationProvider' seems to be missing. But is that possible in a working demo project given by the flutter team to learn from? Should I pass the routeInformationProvider? if so any docs, please.
Just add routeInformationProvider to MaterialApp.router.
Example:
final _router = GoRouter(
...
);
#override
Widget build(BuildContext context) {
return MaterialApp.router(
routeInformationProvider: _router.routeInformationProvider,
...
);
}
I also had this problem, but with the go_router version: ^4.1.0 and following this guide the problem is solved.
Edit: - This should not be marked as the correct answer, as it was just a workaround. Please mark Luca Iaconelli answer as the correct one
Previous answer:
Just go back to version 3.1.1 of GoRouter. It seems latest version has an issue
Add routeinformationProvider at MaterialApp root:
MaterialApp.router(
routeInformationProvider: goRouter.routeInformationProvider,//Add this line
routerDelegate: goRouter.routerDelegate,
routeInformationParser: goRouter.routeInformationParser,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.amber,
),
);
For me, it was solved when I added
the following line of code
routeInformationProvider: _router.routeInformationProvider,
before the following two lines of codes
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,
After adding a get:^4.6.1 I got the below error.
Code:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter web One',
home: HomePage(),
);
}
}
Error:
const CupertinoApp({
^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:275:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/app.dart:217:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp.router({
^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:322:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/app.dart:166:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp({
^^^^^^^^^^^
and also if I try to downgrade getx version 4.6.1 to 4.3.8 still i am getting the same error and in the error, it shows get-4.6.1 version.
The above problem is happening in get version >= 4.6.0. Use the exact version below 4.6.0 withing using ^ sign, which upgrades the package to the maximum compatible version.
In pubspec.yaml use get package like below:
get: 4.5.1 #Don't use ^
i recently started learning flutter. I was working on the 'package:english_words/english_words.dart' package. I have successfully imported it by modifying the pubspec.yaml file by adding 'english_words: ^3.1.0 inside dependencies and on the main.dart file child:Text(wordPair.asPascalCase) is throwing an error. The output I got after running it is :
Compiler message:
lib/main.dart:17:23: Error: Getter not found: 'wordPair'.
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
and here is my code:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: Text(wordPair.asPascalCase),
),
),
);
}
}
my english.dart file is
/// Support for working with English text.
library english_words;
export 'src/syllables.dart';
export 'src/word_pair.dart';
export 'src/words/adjectives.dart';
export 'src/words/all.dart';
export 'src/words/nouns.dart';
This file comes from the flutter package, you won't have to modify it.
library english_words;
export 'src/syllables.dart';
export 'src/word_pair.dart';
export 'src/words/adjectives.dart';
export 'src/words/all.dart';
export 'src/words/nouns.dart';
The problem is the understanding of the english_words package. Using wordPair makes no sense since you didn't declared it.
You can't access the asPascalCase getter with a static instance of WordPair. So you will have to create an instance of WordPair and then use the pascalCase getter.
import 'package:english_words/english_words.dart';
var wordpair = WordPair("first,", "second");
String pascalCase = wordpair.asPascalCase;
The working code for this question is also available here