What am I trying to do?
As usual, I am trying to sending data from one screen to another onGenerateRoute() but I screen does not accept arguments type and showing error The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'.
I also tried to change the argument type Object? on the receiver screen but now I am not able to extract data from Object to Map<String, dynamic>. I think both are the same data type but the null-safety version is treated differently. I think this is a bug.
I have seen flutter official documentation for navigate-with-arguments and when I switched to null-safety in Interactive example section then it also showing error. See this screenshot or try it yourself.
It's working properly in the non-null-safety version of flutter
Here's the snippet
RouteGenerator Class
class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
// Getting arguments passed while calling Navigator.pushNamed
final args = settings.arguments;
switch (settings.name) {
case HomeScreen.routeName:
return MaterialPageRoute(
builder: (context) => HomeScreen(),
);
case LoginScreen.routeName:
return MaterialPageRoute(
builder: (context) => LoginScreen(),
);
case VerifyFirebaseOtpScreen.routeName:
return MaterialPageRoute(
builder: (context) => VerifyFirebaseOtpScreen(data: args), // Here is the error: The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'.
);
case AboutScreen.routeName:
return MaterialPageRoute(
builder: (context) => AboutScreen(),
);
default:
return MaterialPageRoute(
builder: (context) => Scaffold(
body: SafeArea(
child: Center(
child: Text('No route defined for ${settings.name}'),
),
),
),
);
}
}
}
VerifyFirebaseOtpScreen
class VerifyFirebaseOtpScreen extends StatelessWidget {
static const String routeName = '/verify_firebase_otp_screen';
final Map<String, dynamic> data;
const VerifyFirebaseOtpScreen({
Key? key,
required this.data,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(8.0),
child: Container(
width: double.infinity,
child: VerifyFirebaseOtpScreenDataSection(
mobile: '${data['mobile']}',
),
),
),
),
),
);
}
}
Logs
abhishekkumar#Abhisheks-MacBook-Air ~ % flutter doctor -v
[✓] Flutter (Channel beta, 2.1.0-12.2.pre, on macOS 11.2.3 20D91 darwin-x64, locale en-IN)
• Flutter version 2.1.0-12.2.pre at /Users/abhishekkumar/flutter
• Framework revision 5bedb7b1d5 (13 days ago), 2021-03-17 17:06:30 -0700
• Engine revision 711ab3fda0
• Dart version 2.13.0 (build 2.13.0-116.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/abhishekkumar/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /Users/abhishekkumar/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 at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• 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 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.51.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.17.0
[✓] Connected device (3 available)
• iPhone SE (1st generation) (mobile) • 035FA189-09FF-46B5-96AC-C34E8D068C21 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 11.2.3 20D91 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.90
• No issues found!
Answer in short
Use typecast operator as
so above question's answer will be like final args = settings.arguments as Map<String, dynamic>;
Answer explanation
I also filed this question as an issue on GitHub and thanks to goderbauer (A Flutter Team Member) who identify correctly this issue and closed it by giving an appropriate solution.
goderbauer says
In your example settings.arguments is typed as Object? and you're passing it to VerifyFirebaseOtpScreen.data which is typed as Map<String, dynamic>. Prior to null-safety this was legal and is called an implicit downcast. But with null safety Dart has removed implicit downcast altogether (you can read more about that here https://dart.dev/null-safety/understanding-null-safety, just search for "implicit downcast" on the page). So now, if you're sure that settings.arguments is in deed of type Map<String, dynamic> you need to do an explicit cast, something like: settings.arguments as Map<String, dynamic>.
He also said
(The example on the page will have to be updated as well once we migrate them to null safety)
dart.dev explanation and example
Referred documentation page Understanding null-safety & using-nullable-types explanation also covering this.
Their below example is explain enough
// Without null safety:
requireStringNotObject(String definitelyString) {
print(definitelyString.length);
}
main() {
Object maybeString = 'it is';
requireStringNotObject(maybeString);
}
// Using null safety:
requireStringNotObject(String definitelyString) {
print(definitelyString.length);
}
main() {
Object maybeString = 'it is';
requireStringNotObject(maybeString as String);
}
Related
I'm trying to fetch the names of countries from an API and display it in a drop-down box. I'm using the bloc library for state management.
Here's my Code.
select_input_field.dart - Custom wrapper widget for DropdownButtonField
import 'package:flutter/material.dart';
class SelectInputField extends StatelessWidget {
final String label;
final List<String> options;
final TextEditingController controller;
final EdgeInsets padding;
const SelectInputField(this.label, this.options,
{ Key? key,
required this.controller,
this.padding =
const EdgeInsets.only(top: 8, bottom: 8, left: 30, right: 30)})
: super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: padding,
child: DropdownButtonFormField(
decoration: InputDecoration(
labelText: label,
labelStyle: Theme.of(context).textTheme.bodyMedium,
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColorDark,
width: 1,
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColorDark,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.secondary,
width: 1,
),
),
fillColor: Theme.of(context).primaryColorLight),
style: Theme.of(context).textTheme.bodyMedium,
items: options.map((String value) {
print(value);
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? value) {
controller.text = value ?? '';
},
),
);
}
}
This is the method I'm using to build it.
Widget _countriesDropDown(BuildContext context, TextEditingController controller){
return BlocProvider(
create: (context) => _signupBloc,
child: BlocBuilder<SignupBloc,SignupState>(
buildWhen: ((previous, current) => previous is! Loaded && current is Loaded),
builder: (context, state){
if (state is Initial){
_signupBloc.add(LoadEvent());
}
else if (state is Loaded){
countries = state.countries;
return SelectInputField("Country", countries, controller: controller);
}
return CircularProgressIndicator(color: Theme.of(context).colorScheme.secondary,);
},
)
);
}
And my bloc class is as follows.
class SignupBloc extends Bloc<SignupEvent, SignupState> {
static const String countriesUrl = "https://api.first.org/data/v1/countries";
SignupBloc() : super(Initial()) {
on<LoadEvent>((event, emit) async{
emit(Loading());
List<String> countries = [];
try{
final response = await http.get(Uri.parse(countriesUrl));
if(response.statusCode == 200){
var responseJson = jsonDecode(response.body);
responseJson['data'].values.forEach((element) {
countries.add(element['country']);
});
emit(Loaded(countries));
}
else{
emit(Failed("Error in getting data"));
}
}
catch(e){
print(e);
emit(Failed("Failed to access internet. Try again later!"));
}
});
}
The error appears to look like this. I cannot understand where this error occurs
======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
Tried to paint a RenderObject reentrantly.
The following RenderObject was already being painted when it was painted again: RenderPointerListener#c100e relayoutBoundary=up20 NEEDS-PAINT
... needs compositing
... parentData: <none> (can use size)
... constraints: BoxConstraints(0.0<=w<=351.4, 0.0<=h<=Infinity)
... size: Size(351.4, 64.0)
... behavior: opaque
... listeners: down, panZoomStart
Since this typically indicates an infinite recursion, it is disallowed.
The relevant error-causing widget was:
DropdownButtonFormField<String> DropdownButtonFormField:file:///D:/Projects/sem5/iblock/lib/widgets/forms/select_input_field.dart:20:14
When the exception was thrown, this was the stack:
#0 RenderObject._paintWithContext.<anonymous closure> (package:flutter/src/rendering/object.dart:2693:9)
#1 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2706:6)
#2 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:239:13)
#3 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:144:15)
#4 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2796:7)
#5 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:239:13)
#6 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:144:15)
#7 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2796:7)
I need an explanation about what's wrong with my code and how to fix this.
Output of flutter doctor
[√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.22621.608], locale en-US)
• Flutter version 3.3.2 on channel stable at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision e3c29ec00c (3 weeks ago), 2022-09-14 08:46:55 -0500
• Engine revision a4ff2c53d8
• Dart version 2.18.1
• DevTools version 2.15.0
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\ISHAD\AppData\Local\Android\sdk
• Platform android-32, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[√] Chrome - develop for the web
• CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.18)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
• Visual Studio Build Tools 2019 version 16.11.32802.440
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.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.13+0-b1751.21-8125866)
[√] IntelliJ IDEA Ultimate Edition (version 2022.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.2
• Flutter plugin version 70.2.5
• Dart plugin version 222.4167.21
[√] VS Code (version 1.71.2)
• VS Code at C:\Users\ISHAD\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.48.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.608]
• Chrome (web) • chrome • web-javascript • unknown
• Edge (web) • edge • web-javascript • Microsoft Edge 105.0.1343.53
! Device DRGGAM5890805202 is not authorized.
You might need to check your device for an authorization dialog.
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
PS:
I'm not much familiar with Flutter/ bloc library.
Not sure if you still having this issue but I had a similar issue and I added isExpanded: true to my DropdownButtonFormField which resolved the error. My problem was caused by the length of the words in my DropdownMenuItem. When I look at the response of your API call I see some very long names. I could be wrong though
Converting the SelectInputField to a StatefulWidget solved the issue.
I think DropdownButtonFormField need to be rendered itself upon activities on it. So, StatelessWidget cannot rerender itself causing this problem.
I'm trying to simulate a tap event in flutter using hitTest as described in this post: How can I simulate a tap event on a Flutter widget?
Even though the hitTest returns true, the onTap event of the GestureDetector is not triggered
heres my code:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class TestHitTest extends StatefulWidget {
const TestHitTest({Key? key}) : super(key: key);
#override
State<TestHitTest> createState() => _TestHitTestState();
}
class _TestHitTestState extends State<TestHitTest> {
bool _testSuccessfull = false;
final GlobalKey _globalKey = GlobalKey();
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
key: _globalKey,
onTap: (){
setState(() {
_testSuccessfull = true;
});
},
child: Container(
width: 200,
height: 100,
color: _testSuccessfull? Colors.green:Colors.red,
),
),
SizedBox(height: 100,),
GestureDetector(
onTap: () {
final RenderObject? renderObject = _globalKey.currentContext?.findRenderObject();
final RenderBox? renderBox = renderObject is RenderBox? renderObject:null;
final hitTestResult = BoxHitTestResult();
print(renderBox?.hitTest(hitTestResult, position: Offset(renderBox.size.width/2,renderBox.size.height/2)));
},
child: Container(
width: 200,
height: 100,
color: Colors.blue,
child: Text(
'Perform hittest',
),
),
),
],
),
),
);
}
}
Since my final use case involves triggering onTap methods of widgets that might be covered by other widgets, I can't just use GestureBinding. The problem also occurs when obtaining the context directly instead of via the global key.
Note: I don't want to call the onTap method directly
output of flutter doctor -v:
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-x64, locale de-DE)
• Flutter version 2.10.4 at /Users/test/Developer/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c860cba910 (2 weeks ago), 2022-03-25 00:23:12 -0500
• Engine revision 57d3bac3dd
• Dart version 2.16.2
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/test/Library/Android/sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: /Applications/Development/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• 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 2021.1)
• Android Studio at /Applications/Development/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.11+0-b60-7590822)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.3)
• IntelliJ at /Applications/Development/IntelliJ IDEA.app
• 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.66.1)
• VS Code at /Applications/Development/Visual Studio Code.app/Contents
• Flutter extension version 3.38.1
[✓] Connected device (3 available)
• iPhone 13 (mobile) • 8EB86ECB-B851-40C7-B70B-3E93A91646B6 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.3.1 21E258 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.75
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Finally figured it out: it is possible to use GestureBindings.handleEvent() instead of GestureBindings.handlePointerEvent(). That way, the specific HitTestResult can be passed and no Widgets that are before that widget can absorb the event.
Example:
//get render Box and perform hitTest
final RenderObject? renderObject = _globalKey.currentContext?.findRenderObject();
final RenderBox? renderBox = renderObject is RenderBox? renderObject:null;
final hitTestResult = BoxHitTestResult();
renderBox?.hitTest(hitTestResult, position: Offset(renderBox.size.width/2,renderBox.size.height/2));
//get BoxHitTestEntry
BoxHitTestEntry entry = hitTestResult.path.firstWhere((element) => element is BoxHitTestEntry) as BoxHitTestEntry;
//create Events and get GestureBinding Instance
GestureBinding instance = GestureBinding.instance!;
var event1 = PointerDownEvent(position: renderBox!.localToGlobal(Offset(renderBox.size.width/2,renderBox.size.height/2)));
var event2 = PointerUpEvent(position: renderBox.localToGlobal(Offset(renderBox.size.width/2,renderBox.size.height/2)));
//dispatch and handle events using GestureBinding
instance.dispatchEvent(event1, hitTestResult);
instance.dispatchEvent(event2, hitTestResult);
instance.handleEvent(event1, entry);
instance.handleEvent(event2, entry);
Hi I have spent a couple of days on trying to figure out why my user looses there "session" on my app when I close the app. How do I keep them signed in or what might cause this?
I am running the app on my google pixel 5 using the simulator option on android studio.
yaml file:
firebase_core: ^0.4.0+9
firebase_auth: ^0.14.0+9
cloud_firestore: ^0.13.6
firebase_storage: 3.1.6
firebase_messaging: 6.0.16
firebase_crashlytics: 0.1.4+1
This is what I can see in my logs (Not helpful much):
D/FlutterLocationService(32338): Unbinding from location service.
D/FlutterLocationService(32338): Destroying service.
D/FlutterLocationService(32338): Creating service.
D/FlutterLocationService(32338): Binding to location service.
flutter doctor -v:
(base) darrendupreez#Darrens-MacBook-Pro unavine_app % flutter doctor
-v [✓] Flutter (Channel dev, 1.26.0-12.0.pre, on macOS 11.1 20C69 darwin-x64, locale en-CA)
• Flutter version 1.26.0-12.0.pre at /Applications/flutter
• Framework revision a706cd2112 (2 weeks ago), 2021-01-14 18:20:26 -0500
• Engine revision effb529ece
• Dart version 2.12.0 (build 2.12.0-224.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK
version 30.0.3)
• Android SDK at /Users/darrendupreez/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Users/darrendupreez/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7042882/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 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 /Users/darrendupreez/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7042882/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 1.8.0_242-release-1644-b3-6915495)
[✓] Connected device (1 available)
• Pixel 5 (mobile) • 0C161FDD4000DT • android-arm64 • Android 11 (API 30)
• No issues found!
Providers and AuthCreditental should work here is an example for google login with firebase
main.dart
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return Provider(
create: (context) => AuthBloc(),
child: MaterialApp(
title: 'Your App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: MaterialColor(0xff360A36, color),
accentColor: Colors.limeAccent,
),
//darkTheme: ThemeData.dark(),
home: LogInPage(),
),
);
}
}
auth_bloc.dart
class AuthBloc {
final authService = AuthService();
final googleSignin = GoogleSignIn(scopes: ['email']);
Stream<User> get currentUser => authService.currentUser;
loginGoogle() async {
try {
final GoogleSignInAccount googleUser = await googleSignin.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
idToken: googleAuth.idToken, accessToken: googleAuth.accessToken);
//Firebase Sign in
final result = await authService.signInWithCredential(credential);
print('${result.user.displayName}');
} catch (error) {
print(error);
}
}
logout() {
authService.logout();
googleSignin.signOut();
}
sign in button
SignInButton(
Buttons.Google,
text: "Sign in with Google",
onPressed: () => authBloc.loginGoogle(),
),
Also you can watch this tutorial for using credentials and providers
https://www.youtube.com/watch?v=_uYO2ht5Nl4&list=PL19w2HZFNl2BsftambzhFE7tVrqGEVwzy&index=1&t=1924s
You can use shared_preferences: ^0.5.12+4 to save the session.Just check whether it is null or not. And when you need you can update the data with new login.
Sample:
SharedPreferences prefs = await SharedPreferences.getInstance(); int counter = (prefs.getInt('counter') ?? 0) + 1; print('Pressed $counter times.');
Firebase auth automatically manage the auth state for your project but you have to access that auth state in your project to keep user data in the application.
You can use the authStateChange function to make it work.
Stream<User> get currentUser => _auth.authStateChanges();
And the user state in your main function using the Provider Package. Also wrap your `MaterialApp()' function by the following code:
MultiProvider(
providers: [
StreamProvider<User>.value(
value: Auth().currentUser,
)
],
child: GetMaterialApp()
)
I'm using the flutter_linkify package, running on iOS.
I've got it working fine using the Linkify widget.
BUT when I use SelectableLinkify: links still show using the link style (blue underline) BUT links no longer load when clicked.
Any ideas on what might be wrong / how to debug?
Thank you!
code to replicate:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
class TestingScreen extends StatefulWidget {
#override
_TestingScreenState createState() => _TestingScreenState();
}
class _TestingScreenState extends State<TestingScreen> {
_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url, forceWebView: true);
} else {
throw 'Could not launch $url';
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: SelectableLinkify(
onOpen: (link) {
_launchURL(link.url);
},
text:
'I have an awesome website https://google.com',
),
),
),
);
}
}
Flutter Doctor output (note I'm not using VS Code so shouldn't impact this project!)
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Android Studio (version 3.5)
[!] VS Code (version 1.40.2)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
I have been using Geocoder-0.1.2, from starting, and it did not cause me any problem. I have just upgraded my flutter and while running my project, I get this error:
Compiler message:
file:///Users/alok/flutter/.pub-cache/hosted/pub.dartlang.org/geocoder-0.1.2/lib/services/d
istant_google.dart:38:56: Error: The argument type 'Utf8Decoder' can't be assigned to the
parameter type 'StreamTransformer<Uint8List, dynamic>'.
- 'Utf8Decoder' is from 'dart:convert'.
- 'StreamTransformer' is from 'dart:async'.
- 'Uint8List' is from 'dart:typed_data'.
Try changing the type of the parameter, or casting the argument to
'StreamTransformer<Uint8List, dynamic>'.
final responseBody = await response.transform(utf8.decoder).join();
^
Compiler failed on /Users/alok/MyProjects/newmonkapp/lib/main.dart
Error launching application on iPhone 7.
Since the error shows it is in the main.dart, there is no code related to that, I have doubled checked it. Here you go.
main.dart
import 'package:flutter/material.dart';
void main() => runApp(NewMonkApp());
class NewMonkApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
print("in the main builder");
return MaterialApp(
title: 'XYZ',
debugShowCheckedModeBanner: false,
theme: ThemeData(
backgroundColor: Color.fromRGBO(249, 249, 251, 1),
fontFamily: 'SF Pro',
primaryColor: Color.fromRGBO(253, 92, 99, 1),
textTheme: TextTheme(
headline: TextStyle(
fontSize: 34.0, fontWeight: FontWeight.bold,
color: Color.fromRGBO(64, 72, 82, 1)
)
)
),
initialRoute: "/",
routes: {
"/": (context) => InitPage(),
// "/": (context) => SearchFilterPage()
}
);
}
}
And it exits the application. Don't know what the problem is, and how should I fix this. I have tried to google it, seems like couldn't find a better solution for this. Any help would be appreciated.
Flutter Doctor results:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.8.1-pre.44, on Mac OS X 10.14.5 18F132, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Chrome - develop for the web
[!] Android Studio (version 3.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (3 available)
! Doctor found issues in 1 category.
Any help would be appreciated. Thanks :)
change this line final response = await request. close().
to
final response = await request.close().then((response){ response.cast>().transform(utf8.decoder).listen((content) { return content; }); });
This worked for me😘
Inside flutter plugins, geocoder and file name distant_google.dart