I am trying to run my first flutter app and I am getting a redscreen error when I run it on my iPhone but it runs without a problem on the simulator:
type '_CompactLinkedHashSet' is not a subtype of type 'Widget'.
Does anyone know what this error refers to? The error-causing widget is a FutureBuilder. The type of the FutureBuilder is the same as the Future.
Flutter doctor:
[✓] Flutter (Channel dev, v1.18.0, on Mac OS X 10.15.4 19E287, locale en-AU)
• Flutter version 1.18.0 at /Users/Josh/Developer/flutter
• Framework revision 8f7327f83a (11 days ago), 2020-04-06 22:11:01 -0400
• Engine revision 49891e0653
• Dart version 2.8.0 (build 2.8.0-dev.20.0 1210d27678)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/Josh/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
class DisclaimerData {
bool agreed;
String version;
DisclaimerData({this.agreed, this.version});
}
class DisclaimerView extends StatefulWidget {
#override
_DisclaimerViewState createState() => _DisclaimerViewState();
}
class _DisclaimerViewState extends State<DisclaimerView> {
Future<DisclaimerData> _getAgreed() async {
final preferences = await SharedPreferences.getInstance();
final disclaimerValues = DisclaimerData();
disclaimerValues.agreed = preferences.getBool('disclaimer_agreed') ?? false;
disclaimerValues.version =
preferences.getString('disclaimer_version') ?? '0';
return disclaimerValues;
}
#override
Widget build(BuildContext context) {
return FutureBuilder<DisclaimerData>(
future: _getAgreed(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Scaffold(
...
_CompactLinkedHashSet is an alternative name for Set. It is internal default Set implementation that dart uses to optimize Set's data structure.
_CompactLinkedHashSet (default Set implementation) and _InternalLinkedHashMap (default Map) have good asymptotic storage efficiency as the size of the collection grows. They are always better than conveniently available alternatives above 10 elements and are designed for a better locality.
source:
https://github.com/dart-lang/sdk/issues/26081
Related
Expected Result:
Navigate to Previous page
Actual Result
Closing whole application
To Reproduce :
Wrap that page's Scaffold in a WillPopScope widget
return new WillPopScope(
onWillPop: () async {
return true;
},
child: new Scaffold(
…
),
);
GetX Version
get: ^5.0.0-beta.52
[✓] Flutter (Channel stable, 3.3.0, on Ubuntu 21.04 5.11.0-49-generic, locale en_IN)
• Flutter version 3.3.0 on channel stable at /home/pradeep/snap/flutter/common/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ffccd96b62 (8 days ago), 2022-08-29 17:28:57 -0700
• Engine revision 5e9e0e0aa8
• Dart version 2.18.0
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
• Android SDK at /home/pradeep/Android/Sdk
• Platform android-33, build-tools 33.0.0-rc1
• Java binary at: /snap/android-studio/123/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
• cmake version 3.10.2
• ninja version 1.8.2
• pkg-config version 0.29.1
[✓] Android Studio (version 2021.2)
• Android Studio at /snap/android-studio/123/android-studio
• Flutter plugin version 70.0.2
• Dart plugin version 212.5744
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
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!');
}
When the user increases the Display Font Size of mobile phone Android/iOS the application UI is completed broken.
Requirement: I need to fix the size of all the TextFields though the user increases the display font size. (Give no support for Accessibility)
Note: I have already given "fontSize" to my textfields, though it enlarges when font size is increase.
Steps to reproduce it:
iOS Mobile: Settings -> Accessibilities -> Display and Text Size -> Large Text -> On -> Maximum
Android Mobile: Settings -> Display -> Font Size -> Huge
Please let me know if any solution prevails.
Help will be appreciated.
Here is my flutter doctor -v
Flutter (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-arm, locale en-IN)
• Flutter version 1.22.6 at /Users/sunflower/Documents/flutter
• Framework revision 9b2d32b (3 months ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/sunflower/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/sunflower/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin installed
• Dart plugin version 201.9317
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
Please find the attached files to get the highlight of the issue.
When Font Size is increased Application UI
Everything is overflowed
this might help, font size change prohibited,
MaterialApp(
builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
child: child,
);
},
title: 'Home Page',
);
Lock the textScaleFactor to 1.0 in your 'MaterialApp`:
MaterialApp(
title: 'My App',
builder: (BuildContext context, Widget _) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), // like this
child: Home(), // Your widgets go here
);
},
);
shared_preferences: ^0.5.12+4
Error log:
MissingException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
flutter sdk details:
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.14.6 18G7016 darwin-x64, locale en-US)
• Flutter version 1.22.5 at /Users/taleb/Developer/flutter
• Framework revision 7891006299 (6 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/taleb/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/taleb/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
• CocoaPods version 1.8.3
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin installed
• Dart plugin version 201.9317
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.3)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 45.1.2
• Dart plugin version 193.7547
[✓] Connected device (1 available)
• SM A107F (mobile) • R9AM905ZREJ • android-arm • Android 10 (API 29)
! Doctor found issues in 1 category.
If you're using shared_preferences 0.2.4 and above, use setMockInitialValues:
SharedPreferences.setMockInitialValues({}); // set initial values here if desired
For earlier versions you can do it manually:
const MethodChannel('plugins.flutter.io/shared_preferences')
.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'getAll') {
return <String, dynamic>{}; // set initial values here if desired
}
return null;
});
When running UI tests with flutter driver the assets are not displayed on iPhone simulator. They are displayed when app is run in debug mode from VS Code.
I tried to reproduce it on the example project generated by flutter create -i swift -a kotlin --androidx --org com.example example but without success. I followed exactly the same process of introducing flutter_driver tests in both apps according to this article. Unfortunately, in my app the images are not shown, and in example app they appear just fine. I compared project.pbxproj and pubspec.yaml files and they look fine to me.
For instance my pubspec.yaml:
dev_dependencies:
flutter_driver:
sdk: flutter
test: any
flutter_test:
sdk: flutter
screenshots:
flutter:
uses-material-design: true
assets:
- assets/lang/pl.json
- assets/images/
Is there anything that can help me with this issue? What can I do to debug the problem?
Logs
Beware, this is a very long log output.
flutter drive --target=test_driver/app.dart --verbose
https://gist.github.com/orestesgaolin/861c4f191773ca152b400d97ced2daeb
Flutter doctor
flutter doctor -v
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale pl-PL)
• Flutter version 1.7.8+hotfix.4 at /Users/dominik/Library/flutter
• Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/dominik/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_SDK_ROOT = /Users/dominik/Library/Android/sdk
• Java binary at: /Users/dominik/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.5791312/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5
[✓] iOS tools - develop for iOS devices
• ios-deploy 1.9.4
[✓] Android Studio (version 3.5)
• Android Studio at /Users/dominik/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.5791312/Android Studio.app/Contents
• Flutter plugin version 37.1.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.37.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.3.0
[✓] Connected device (1 available)
• iPhone Xs Max • C1A5534A-AE3A-4FB3-95F6-993E351FF2D3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
• No issues found!
So the solution was to create separate main_test.dart file that wraps whole app in DefaultAssetBundle like so:
runApp(DefaultAssetBundle(
bundle: TestAssetBundle(),
child: App(),
));
and TestAssetBundle is like so:
class TestAssetBundle extends CachingAssetBundle {
#override
Future<String> loadString(String key, {bool cache = true}) async {
final ByteData data = await load(key);
if (data == null) throw FlutterError('Unable to load asset');
return utf8.decode(data.buffer.asUint8List());
}
#override
Future<ByteData> load(String key) async => rootBundle.load(key);
}
And in app.dart you have to reference correct file:
import 'package:flutter_driver/driver_extension.dart';
import 'package:playoo_league_player/main_test.dart' as app;
void main() {
// This line enables the extension.
enableFlutterDriverExtension();
// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}
Full explanation can be found here: https://medium.com/#sardox.vl/flutter-test-and-randomly-missing-assets-in-goldens-ea959cdd336a
Those Images are not loading because of cache issues .For that we can
use
PRE CACHE IMAGES to preload the images
class App extends StatefulWidget {
#override
State<App> createState() => _AppState();
}
class _AppState extends State<App>{
late image image1
late image image2
#override
void initState() {
super.initState();
image1 = Image.asset('assets/images/');
image2 = Image.asset('assets/images/');
}
#override
void didChangeDependencies() {
pre cacheImage(image1.image, context);
pre cacheImage(image2.image, context);
super.didChangeDependencies();
}
#override
Widget build(BuildContext context) {
return Container
}
if it is multiple assets or images you can save this method as class and
initialise it from main.dart .