flutter getx package not working, showing error - flutter

I recently upgraded flutter. After upgrading, when I going to use Get it's showing down error.
without adding get my project work fine.
Codes
import 'package:flutter/material.dart';
import 'package:flutterfire_auth/src/homepage.dart';
import 'package:get/get.dart';
void main() {
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter App',
debugShowCheckedModeBanner: false,
home: Homepage(),
);
}
}
errors
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-3.15.0/lib/get_navigation/src/extension_navigation.dart:235:37: Error: No named parameter with the name 'shadowThemeOnly'.
final theme = Theme.of(context, shadowThemeOnly: true);
^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/theme.dart:119:20: Context: Found this candidate, but the arguments don't match.
static ThemeData of(BuildContext context) {
^^

add pub dependency extension in vscode "Pubspec Dependency Search" ,it will help in automitacally add "get" dependency

Related

graphql_flutter Error: The non-abstract class 'GraphQLWebSocketChannel' is missing implementations

I am trying to use graphql_flutter (https://pub.dev/packages/graphql_flutter) for my MVVM architecture. (https://stacked.filledstacks.com/docs/getting-started/overview) I got this error below from the package graphql_flutter when I try to run my code
`../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/graphql-5.1.2/lib/src/links/websocket_link/websocket_client.dart:577:7: Error: The non-abstract class 'GraphQLWebSocketChannel' is missing implementations for these members:
WebSocketChannel.ready
Try to either
provide an implementation,
inherit an implementation from a superclass or mixin,
mark the class as abstract, or
provide a 'noSuchMethod' implementation.
class GraphQLWebSocketChannel extends StreamChannelMixin<dynamic>
^^^^^^^^^^^^^^^^^^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-2.3.0/lib/src/channel.dart:56:22: Context: 'WebSocketChannel.ready' is defined here.
final Future<void> ready = Future.value();`
This is my code in the main.dart file. I am getting the error as long as I have imported the package.
import 'package:flutter/material.dart';
import 'package:testing/app/app.locator.dart';
import 'package:testing/ui/common/app_colors.dart';
import 'package:testing/ui/setup/setup_bottom_sheet_ui.dart';
import 'package:testing/ui/setup/setup_dialog_ui.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'app/app.router.dart';
void main() {
setupLocator();
setupDialogUi();
setupBottomSheetUi();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
HttpLink httpLink = HttpLink("https://api.github.com/graphql");
AuthLink authLink = AuthLink(
getToken: () async => 'Bearer PERSONAL_ACCESS_TOKEN',
);
Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> qlClient = ValueNotifier(
GraphQLClient(
link: link,
// The default store is the InMemoryStore, which does NOT persist to disk
cache: GraphQLCache(store: HiveStore()),
),
);
return GraphQLProvider(
client: qlClient,
child: MaterialApp(
title: 'Flutter Demo',
theme: Theme.of(context).copyWith(
primaryColor: kcBackgroundColor,
focusColor: kcPrimaryColor,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Colors.black,
),
),
initialRoute: Routes.startupView,
onGenerateRoute: StackedRouter().onGenerateRoute,
navigatorKey: StackedService.navigatorKey,
navigatorObservers: [
StackedService.routeObserver,
],
));
}
}
I got this error yesterday. I added it to the pubspec.yaml wrote the following lines and it worked for me
dependency_overrides:
web_socket_channel: 2.2.0
link - https://github.com/flutter/cocoon/pull/2405 (go to the section "Files changed")

"Cannot set URL strategy more than once." error using go_router with Flutter Web

I am using go_router flutter package for Flutter Web.
I am getting this error while reloading the website. The back button is working great but the reload causes this.
Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/window.dart:25:10
!_isUrlStrategySet
"Cannot set URL strategy more than once."
Below is the code for my main.dart:
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:navigator_2/some_app.dart';
import 'details_page.dart';
void main() {
runApp( MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final GoRouter _router = GoRouter(
urlPathStrategy: UrlPathStrategy.path,
routes: [
GoRoute(path: '/',builder: (context,state)=> const SomeAppPage()),
GoRoute(path: '/details',builder: (context,state){
final query = state.queryParams['index'];
return DetailsPage(index: int.parse(query!));
}),
]);
return MaterialApp.router(
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate ,
title: 'Go Router Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
);
}
}
Divyam Makar's answer didn't work for me because I need to use ChangeNotifier subclass on my GoRouter definition, so when I moved the GoRouter initialisation to initState, I got the exception:
dependOnInheritedWidgetOfExactType<_InheritedProviderScope<MyCustomState?>>()
or dependOnInheritedElement() was called before
_MainWidgetState.initState() completed.
So, following the documentation, I set the Url Path Strategy in an upper level of the hierarchy, in the main method:
void main() {
GoRouter.setUrlPathStrategy(UrlPathStrategy.path);
runApp(App());
}
The url path strategy to remove the # character from url's should be set in main().
As of go_router 5.1.0, urlPathStrategy has been completely removed, so GoRouter.setUrlPathStrategy(UrlPathStrategy.path); would cause a build error.
In the 5.0 migration guide, instead of GoRouter.setUrlPathStrategy(UrlPathStrategy.path); replace with:
import 'package:flutter_web_plugins/url_strategy.dart';
void main() {
usePathUrlStrategy();
runApp(ExampleApp());
}
I got the answer. It was just that because GoRouter was defined in build function then during reload its called again and thus causing this error. Removing it and putting it in initState solves it.

The argument type 'Future<SharedPreferences>' can't be assigned to the parameter type 'SharedPreferences'

I want to access the shared preferences at the application startup and want to use this same object across the entire app by passing it to the classes. I am getting the following error:
The argument type 'Future' can't be assigned to the
parameter type 'SharedPreferences'.
main.dart
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:application/layouts/ScreenOne.dart';
import 'package:application/layouts/ScreenTwo.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
sharedPreferences() async {
return await SharedPreferences.getInstance();
}
final preferences = SharedPreferences.getInstance();
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: (preferences.getInt("login") == 1 ? ScreenOne(preferences) : ScreenTwo(preferences)),
);
}
}
I am unable to resolve this error. Is there anything I am doing wrong or missing? Thanks!!!
First of all, you defined function sharedPreferences() but did not use it later in the code - simply remove it.
Furthermore, based on the documentation SharedPreferences.getInstance() returns Future<SharedPreferences> and not SharedPreferences, hence you get the following error. You can resolve the issue by getting the SharedPreferences instance in the main method and then using constructor injection to provide the preferences object to the MyApp:
Future<void> main() async { // <-- Notice the updated return type and async
final preferences = await SharedPreferences.getInstance(); // <-- Get SharedPreferences instance
runApp(
MyApp(preferences: preferences), // <-- Inject (pass) SharedPreferences object to MyApp
);
}
class MyApp extends StatelessWidget {
final SharedPreferences preferences;
const MyApp({
required this.preferences,
})
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: (preferences.getInt("login") == 1 ? ScreenOne(preferences) : ScreenTwo(preferences)),
);
}
}

Status Bar Color - Flutter

I need red status bar with white foreground for my entire app.
I'm using flutter_statusbarcolor package for this.
I did the following so far:
Added the package in pubsec.yaml
Imported the package in my main.dart file
Added the following lines of codes inside the build() of MyApp class
FlutterStatusbarcolor.setStatusBarColor(Colors.red[900]);
FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
Result:
The status bar's color is red(working as it should).
The foreground color is white. But on restart changes to black. On hot reload, changes back to white. But on restart, it'll change back to black.
Here is my complete code:
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
FlutterStatusbarcolor.setStatusBarColor(Colors.red[900]);
FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App Title',
home: HomeScreen(),
);
}
}
I've also tried the following:
SystemChrome.setSystemUIOverlayStyle()
appBarTheme: Theme.of(context).appBarTheme.copyWith(brightness: Brightness.light)
Nothing's working. Can anyone please help me sustain the white foreground throughout the app?
You can try this from this Doc ==> setSystemUIOverlayStyle method
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.red,
);
return Placeholder(); // using As your Need
}
add this:
import 'package:flutter/services.dart'
use the code below after theme data
home: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
Hope it work...

Auto_route unable to use the generated file : no name parameter with the name 'reportsRouteUpdateToEngine'

i'm trying auto_route but i don't understand what i'm doing wrong.
Here is my router.dart :
#MaterialAutoRouter(
routes: <AutoRoute>[
// initial route is named "/"
MaterialRoute(page: HomeView, initial: true),
MaterialRoute(page: StartupView),
],
)
class $Router {}
And here is my main.dart
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
builder: ExtendedNavigator.builder(
router: Router(),
builder: (context, extendedNav) => Theme(
data: ThemeData(brightness: Brightness.dark),
child: extendedNav,
),
),
);
}
}
i've run
flutter packages pub run build_runner build
Then when i run myApp and then i get this error :
Error: No named parameter with the name 'reportsRouteUpdateToEngine'.
reportsRouteUpdateToEngine: true,
^^^^^^^^^^^^^^^^^^^^^^^^^^
I also tried without their extendedNav, just like this :
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
onGenerateRoute: Router(),
);
}
}
Still doesn't work.
Any help ?
The 0.6.9 version seems to work only with the latest flutter version (1.22).
My flutter version was outdated, i upgraded it and it works with 0.6.9.
For a version of Flutter less than 1.22 you need to specify this version in the pubspec.yaml file without the ^:
auto_route: 0.6.7