I have created this class.But I am getting this error
Functions must have an explicit list of parameters. Try adding a parameter list
class DatabaseHelper{
static late DatabaseHelper? _databaseHelper;
factory DatabaseHelper{
if(_databaseHelper==null ){
_databaseHelper=DatabaseHelper.internal();
return _databaseHelper!;
}else{
return _databaseHelper!;
}
}
DatabaseHelper.internal();
}
What I tried
Upgrade Flutter
Upgrade Android Studio
Invalidate Cache/Restart
flutter clean
Switch between channels
Flutter Doctor output
[√] Flutter (Channel beta, 2.5.0-5.2.pre, on Microsoft Windows [Version 10.0.19042.1110], locale tr-TR)
• Flutter version 2.5.0-5.2.pre at C:\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 19c61fed0d (4 days ago), 2021-08-18 17:10:31 -0700
• Engine revision 7a4c4505f6
• Dart version 2.14.0 (build 2.14.0-377.7.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\alige\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code (version 1.59.1)
• VS Code at C:\Users\alige\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.25.0
[√] Connected device (3 available)
• SM G532F (mobile) • 4200c1b8c4d94413 • android-arm • Android 6.0.1 (API 23)
• Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.159
• Edge (web) • edge • web-javascript • Microsoft Edge 92.0.902.78
• No issues found!
No need to update your IDE or Flutter.
You're defining a Factory constructor, but it's missing the parenthesis at the end of it. It's defined as a class, which it isn't. just add the missing parenthesis like this, so it behaves as a function, and the error will be gone:
class DatabaseHelper {
static late DatabaseHelper? _databaseHelper;
factory DatabaseHelper() {
if (_databaseHelper == null) {
_databaseHelper = DatabaseHelper.internal();
return _databaseHelper!;
} else {
return _databaseHelper!;
}
}
DatabaseHelper.internal();
}
No need to update your IDE or Flutter.
Error Code:
void answerQuestion {
print('Answer Chosen!');
}
Correct Code:
void answerQuestion() {
print('Answer Chosen!');
}
Related
I am trying to use the following function in flutter:
Future<File> getFile(String fileName) async {
final appDir = await getTemporaryDirectory();
final appPath = appDir.path;
final fileOnDevice = File('$appPath/$fileName');
final rawAssetFile = await rootBundle.load(fileName);
final rawBytes = rawAssetFile.buffer.asUint8List();
await fileOnDevice.writeAsBytes(rawBytes, flush: true);
return fileOnDevice;
}
But somehow i keep getting this error, failed PathNotFoundException: Cannot open file, path = '/var/mobile/Containers/Data/Application/352527E9-XXXX-XXXX-XXXX-DCFXXXXXXXXX/Library/Caches/assets/
The function is called by final dataFile = await getFile('assets/sample.txt');
Does anyone know how to solve this? Any help is appreciated!
This is my flutter doctor -v
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-arm64, locale en-SG)
• Flutter version 3.7.0 on channel stable at /Users/xaviertoh/Documents/Flutter/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (3 weeks ago), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/xaviertoh/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] VS Code (version 1.75.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• iPhone (mobile) • 00008020-000D05313C02002E • ios • iOS 13.5 17F75
• macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65
darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.77
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Thank you for reading!
Things i have tried:
I have confirmed that my file name is correct in the assets folder and i also tried running this code in various locations in the code such as in a widget and also in main() just to test it out.
I also tried running flutter in xcode and visual studio code.
Also tried to run the code in android emulator and also on iPhone physical device.
The /var/mobile/Containers/Data/Application/.../Library/Caches/assets/ directory must already exist. File.writeAsBytes won't automatically create parent directories for you.
You can do that step by first doing:
await fileOnDevice.parent.create(recursive: true);
I'm trying to assign null to a specific key in Map<String, dynamic> in order to nullify the value in my SQL DB.
But I keep getting an error Error: Expected a value of type 'Object', but got one of type 'Null', in dartpad it works fine without any errors.
Here is the error I'm getting:
Error: Expected a value of type 'Object', but got one of type 'Null'
Here is my code:
Map<String, dynamic> map = {};
map["key2"] = null;
Flutter doctor:
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1014, on macOS 12.5.1 21G83 darwin-x64, locale en-IL)
• Flutter version 3.1.0-0.0.pre.1014 at /Users/daniel/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 08e61c3be2 (6 months ago), 2022-05-31 00:18:09 -0400
• Engine revision 693f95391e
• Dart version 2.18.0 (build 2.18.0-152.0.dev)
• DevTools version 2.13.1
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/daniel/Library/Android/sdk
• Platform android-32, build-tools 32.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.73.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.52.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.5.1 21G83 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
every time I run a debug session (may it be on chrome or on edge) the page appears entirely blank, but no errors are thrown.
So far I´ve tried:
reducing the code to a minimum to exclude errors in the widgets code
running on different devices
running via flutter run -d chrome --web-port=8080 --web-hostname=the value of IPv4 Address
adding localhost to my "safe-list" on my antivirus
Here you can see my flutter doctor -v:
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1237], locale de-DE)
• Flutter version 2.2.3 at C:\src\flutter
• Framework revision f4abaa0735 (3 months ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\marcu\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = C:\Program Files\Android\Android Studio
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] IntelliJ IDEA Ultimate Edition (version 2019.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.60.2)
• VS Code at C:\Users\marcu\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.27.0
[√] Connected device (2 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 94.0.4606.61
• Edge (web) • edge • web-javascript • Microsoft Edge 94.0.992.38
• No issues found!
Also my code in textform:
import 'package:flutter/material.dart';
void main() {
runApp(TestingWidget());
}
class TestingWidget extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
print("Performing test on testwidget.dart");
return MaterialApp(
home: Scaffold(body: Text("Testwidget") //MethodWidget(),
)
//home: Text("test")
);
}
}
I am sorry if I provided anything in the wrong way, it is my first time writing on stackoverflow.
Thank you for your help!
I just had this issue, and It turned out to be a poor internet connection, ran out of subscription in the middle of building the application. Restored my internet and it built successfully
I tried to use google signin and facebbok auth or facebook sigin in my flutter app . I got a perfect output when i add anyone of the faceebook auth or google sigin package . When i try to add both I got a package conflict error
I also tried for both like this : import 'package:google_sign_in/google_sign_in.dart' as google;
But that does not work
**flutter_facebook_login: ^3.0.0
google_sign_in: ^4.1.1**
And the error which i got is :I/flutter (13976): MissingPluginException(No implementation found for method init on channel plugins.flutter.io/google_sign_in)
This is my flutter doctor:
C:\Users\Administrator>flutter doctor -v
[√] Flutter (Channel stable, 2.0.5, on Microsoft Windows [Version 10.0.19042.867], locale en-IN)
• Flutter version 2.0.5 at C:\src\flutter\flutter
• Framework revision adc687823a (6 weeks ago), 2021-04-16 09:40:20 -0700
• Engine revision b09f014e96
• Dart version 2.12.3
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (3 available)
• HD1901 (mobile) • 5c628c62 • android-arm64 • Android 11 (API 30)
• Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.212
• Edge (web) • edge • web-javascript • Microsoft Edge 90.0.818.66
• No issues found!
I am having issues running my flutter application. I am using objectbox-dart for storing data in my app. So far so good, but when I create a store using path_provider, the getApplicationSupportDirectory() throws _CastError: Null check operator on a null value. Below is the output of flutter doctor -v
[✓] Flutter (Channel stable, 2.2.1, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-PK)
• Flutter version 2.2.1 at /Users/muhammadumar/sdks/flutter
• Framework revision 02c026b03c (11 days ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/muhammadumar/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
[✓] VS Code (version 1.56.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.23.0
[✓] Connected device (2 available)
• MI 8 Lite (mobile) • bb4e8ab • android-arm64 • Android 10 (API 29)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.77
• No issues found!
Below is the exact line of code of path_provider file where exception is being caught
Future<Directory> getApplicationSupportDirectory() async {
final String? path = await _platform.getApplicationSupportPath();
if (path == null) {
throw MissingPlatformDirectoryException(
'Unable to get application support directory');
}
return Directory(path);
}
I am unable to run my app. Any help would be appreciated.
Thanks