Flutter local package navigate to root module - flutter

I have a flutter local package, called "profile" and i have included and using this package from my main application as below
on pubspec.yaml file under dependencies i added the below code.
profile:
path: ./profile
Everything working well and good.
My issue is I want to navigate to MaterialApp -> Route when use click on a button in "Profile" package.
I tried to use Global navigation key
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
and from profile package when i use below code on button press
Navigator.pushNamed(context, '/', arguments: null);
It's doing nothing. Could you please help me with this.
Many thanks in advance.

Related

Transparent NavBar with persistent_bottom_nav_bar

I am using persistent_bottom_nav_bar package:
https://pub.dev/packages/persistent_bottom_nav_bar
which does exactly what I want, except it is missing an important Scaffold function:
extendBody: true
The package tells me the following:
NOTE: This widget includes SCAFFOLD (based on CupertinoTabScaffold),
so no need to declare it.
I am looking for a solution to be able have extendedBody: true while using this package
What you can do is modify the package, and add this property to the built-in scaffold.
1- Go to the package directory, example:
C:\Users\UserName\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\PackageFolderName
2- Copy the Package to your project (the whole PackageFolderName, and paste at same level with pubspec.yaml )
3- Modify the Package's code, i.e. find the Scaffold and add the property
4- Modify your Project's pubspec.yaml and change the path of the package to
Package Name:
path: ./PackageFolderName/
5- Save your pubspec.yaml

Why the test folder automatically gets created on flutter projects, inside this folder the file widget_test..dart always showing red line(ilke error)

It comes all of my Flutter Projects. Is the folder necessary or not ?
Do I delete the folder ?
Basically runApp() method(inside main.dart) contains a class and it should be same as defined in this tester.pumpWidget(....) method. If they don't match, it causes this error.
e.g
In your main.dart if runApp() method is having a class HomePage
runApp(const HomePage()); then inside widget_test.dart file it should be like await tester.pumpWidget(const HomePage());
I got the same error and when i move my mouse on it,it shows that MyApp() links to another project,e.g:
and it links to library'package:try_base_flutter/main.dart',then I found every dart file in the lib links to the try_base_flutter.So I search the key word "try_base_flutter",finally I found the wrong code in the pubspec.yaml's first line
,I write the name: try_base_flutter,because I copy the file from the project try_base_flutter,so just change the name,my problem will be fine.
Remove const. like await tester.pumpWidget(MyApp());

Flutter Web: Right click -> Browser Context Menu -> Open Link in New Tab

I have a basic website using GetX for navigation. I have inkwells with ontap functions which navigate to a new view. Right now, if you right click these buttons there is no "open link in new tab/window", "save link as" or "copy link address".
Is there any way to get this functionality for Flutter Web?
Edit:
Since Flutter version 2.10, you no longer need to switch to channel beta for this.
Maybe I'm answering this late, but this may help someone in the future.
At the moment of writing this it is possible to be done, it is bugged on the stable channel, but it works perfectly on channel beta.
Just switch to channel beta:
flutter channel beta
flutter upgrade
Then follow this instructions to add url_launcher dependency to your project and import this package wherever you want to use it:
import 'package:url_launcher/link.dart';
And finally wrap any widget with this:
Link(
uri: Uri.parse('www.google.com'),
builder: (context, function) {
return InkWell(
onTap: () => print('Do something'),
child: Text('Right clickable text')
);
});

Error: Entrypoint doesn't contain a main function Flutter

I got an error Error: Entrypoint doesn't contain a main function Flutter, I tried to restart android studio but it did not work
Depends on what the program is support to do. There should be a main class that is initiated. As an example:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp()); // initiate MyApp as StatelessWidget
// Main class
class MyApp extends StatelessWidget {
// creating main screen and building list of wordpairs
#override
This worked for me:
When new project is created then got the error "Entrypoint doesn't contain a main function Flutter".
To resolve this I followed below step
First make sure your flutter and dart sdk paths are properly configured.
You can re-include the files/project root folder.
Goto File -> Project Structure -> Module
And then add the root folder of the project by clicking + icon, then it will detect a flutter app again.
Build the project and check for the error.
add main function to your project. you might miss that
void main() => runApp(MyApp());
There's another case where this is possible, because of dart package file
delete all that .packages files, should get resolved.
Just do this
File -> Project structure -> Modules
From right select
Sources
form [Source, Paths, Dependencies] Tabs
Select Plus Icon -> Apply -> ok button
Make sure you use same name of project and pubspec.yaml file name Sometime it happens when we copy one pubspec file for another project.
in my case the launching function was named something else, renamed it to main, then it worked.
Add this if its missing in your main.dart file
void main() => runApp(MyApp());
This function tells Dart where the program starts, and it must be in the file that is considered the "entry point" for you program.
I cut some text above the main function and that included a closing } which made the main inside some class above it. That caused the above error. I put back the } above main and everything became ok.

flutter webview keyboard cannot show up

I tried to integrate the webview, in the flutter app. After adding the code in the example, the page loads normally, but when I click on the input box in the page, no soft keyboard pops up,
This problem only happens on Android and it is a known issue here. https://github.com/flutter/flutter/issues/19718.
If your app does not need the webview to be on the same screen with other Flutter widgets, I recommend this webview library from the Flutter community. There is no keyboard issue here. https://pub.dartlang.org/packages/flutter_webview_plugin
I have tried multiple things but finally i have fixed it through scaffold, now my keyboard is opening.
just wrap your WebView inside Scaffold widget and apply following property inside scaffold.
resizeToAvoidBottomInset: false,
I know it's late but changing the webview version to v3.0.0 actually solved the issue for me.
This one can use for now. Hope flutter team fix it soon.
You need to open your android project in Android Studio to view all dependencies and in the webview_flutter
To fix most recent version of code, besides import
import android.app.Activity;
import io.flutter.app.FlutterApplication;
Change:
webView = new InputAwareWebView(context, containerView);
To:
Context activityContext = context;
Context appContext = context.getApplicationContext();
if (appContext instanceof FlutterApplication) {
Activity currentActivity = ((FlutterApplication) appContext).getCurrentActivity();
if (currentActivity != null) {
activityContext = currentActivity;
}
}
webView = new InputAwareWebView(activityContext, containerView);
Original answer here: #ryanhz https://github.com/flutter/flutter/issues/25767#issuecomment-588603862