flutter package easyloading with ResponsiveWrapper - flutter

I have a problem. I'm using the easyloading package with responsivewrapper. but i can't put them together please help me
builder: EasyLoading.init(context, child) =>
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return MaterialApp(
initialRoute: '/',
builder: EasyLoading.init(context, child) => ResponsiveWrapper.builder(child,
defaultScale: true,
breakpoints: [
ResponsiveBreakpoint.resize(480, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.resize(1000, name: DESKTOP),
],
background: Container(color: Color(0xFFF5F5F5))),
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => MainPage(),
'/CusSearchAtcp': (BuildContext context) => const CusSearchAtcp(),
},
);
});
}

The builder parameter must return one widget. If you like to do initialization or return two widgets, you've to nest them yourself inside the builder:
builder: (context, child) {
// do your initialization here
child = EasyLoading.init(); // assuming this is returning a widget
child = ResponsiveWrapper.builder(/*your required code here*/);
return child;
}
Or you should try to use 2nd way by ResponsiveWrapper.builder or EasyLoading such as:
builder: EasyLoading.init(builder: ResponsiveWrapper.builder(/*your required code here*/)),

Related

Go_Router Pass Object to new route

I want to pass object from the listview to the sub route. It seems no way to pass the object.
Is there any how to do it?
GoRouter routes(AuthBloc bloc) {
return GoRouter(
navigatorKey: _rootNavigatorKey,
routes: <RouteBase>[
GoRoute(
routes: <RouteBase>[
GoRoute(
path: loginURLPagePath,
builder: (BuildContext context, GoRouterState state) {
return const LoginPage();
},
),
GoRoute(
path: homeURLPagePath,
builder: (BuildContext context, GoRouterState state) =>
const HomePage(),
routes: <RouteBase>[
GoRoute(
path: feeURLPagePath,
name: 'a',
builder: (context, state) => FeePage(),
routes: [
/// Fee Details page
GoRoute(
name: 'b',
path: feeDetailsURLPagePath,
builder: (BuildContext context, GoRouterState state) =>
const FeeDetails(),
),
]),
],
),
],
path: welcomeURLPagePath,
builder: (BuildContext context, GoRouterState state) =>
const SplashPage(),
),
],
refreshListenable: GoRouterRefreshStream(bloc.stream),
debugLogDiagnostics: true,
initialLocation: welcomeURLPagePath,
},
);
}
The error says no initial match found for feeDetails!
Use extra parameter in context.goNamed()
Example:
Object:
class Sample {
String attributeA;
String attributeB;
bool boolValue;
Sample(
{required this.attributeA,
required this.attributeB,
required this.boolValue});}
Define GoRoute as
GoRoute(
path: '/sample',
name: 'sample',
builder: (context, state) {
Sample sample = state.extra as Sample; // -> casting is important
return GoToScreen(object: sample);
},
),
Call it as:
Sample sample = Sample(attributeA: "True",attributeB: "False",boolValue: false)
context.goNamed("sample",extra:sample );
Receive it as:
class GoToScreen extends StatelessWidget {
Sample? object;
GoToScreen({super.key, this.object});
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
object.toString(),
style: const TextStyle(fontSize: 24),
)),
);
}
}

Flutter Error: The method 'setContext' isn't defined for the type 'ScreenUtil'

I am using flutter screenutil and The following code used to work, but it gives me this error now.
The method 'setContext' isn't defined for the type 'ScreenUtil'. Try correcting the name to the name of an existing method, or defining a method named 'setContext'.
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) {
return themeChanger;
},
),
ChangeNotifierProvider(
create: (_) {
return settingChanger;
},
),
ChangeNotifierProvider(create: (_) {
return locationChanger;
})
],
child: Consumer2<DarkThemeProvider, AdvancedSettingsProvider>(
builder: (context, value1, value2, child) {
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (_) => MaterialApp(
builder: (context, widget) {
ScreenUtil.setContext(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: widget!);
},
theme: Styles.themeData(
themeChanger.darkTheme, context, themeChanger.color),
debugShowCheckedModeBanner: false,
home: (widget.payload.isEmpty)
? Skeleton()
: AccessedByNotifPage(
payload: widget.payload,
),
),
);
}),
);
}
}```
[![This image shows the error](https://imgur.com/a/l9B5fDJ)
Use init() function instead of setContext()
it's in the new update.
example:
builder: (context, widget) {
ScreenUtil.init(context);
}
You need to upgrade screenUtil version in pubsic.yaml to
flutter_screenutil: ^5.4.0
then flutter clean, flutter pub get and put this code in material app
builder: (ctx, child) {
ScreenUtil.setContext(ctx);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!,
);
}

The argument type 'MaterialApp Function()' can't be assigned to the parameter type 'Widget Function(BuildContext)'

I am using flutter_screenutil and
The following code used to work, but it gives me this error when I try to run it:
Error: The argument type 'MaterialApp Function()' can't be assigned to the parameter type 'Widget Function(BuildContext)'.
class _MyAppState extends State<MyApp> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) {
return themeChanger;
},
),
ChangeNotifierProvider(
create: (_) {
return settingChanger;
},
),
ChangeNotifierProvider(create: (_) {
return locationChanger;
})
],
child: Consumer2<DarkThemeProvider, AdvancedSettingsProvider>(
builder: (context, value1, value2, child) {
return
ScreenUtilInit(
designSize: Size(1080, 2160),
builder: () =>
MaterialApp(
builder: (context, widget) {
ScreenUtil.setContext(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: widget!);
},
theme: Styles.themeData(
themeChanger.darkTheme, context, themeChanger.color),
debugShowCheckedModeBanner: false,
home: (widget.payload.isEmpty)
? Skeleton()
[enter image description here][1] : AccessedByNotifPage(
payload: widget.payload,
),
),
);
}),
);
}
}
This image shows the error:
If you use ScreenUtilInit, you must have to provide Buildcontext or pass a value in the builder function callback.
Use:
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (BuildContext context,child) => MaterialApp(
or:
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (_,child) => MaterialApp(
ScreenUtilInit: builder provides BuildContext on callback,
On line 162 do builder: (_) => MaterialApp or
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (BuildContext c) => MaterialApp(
In your code simply change
builder: (context, value1, value2, child){
with
create: (context, value1, value2, child) {
ScreenUtilInit(
designSize: const Size(360, 740),
builder: (BuildContext context, child) => MaterialApp(
))

How can I clear the current state of my providers manually in Flutter app?

How can I clear the current state of my providers manually in my Flutter app? while I'm using MultiProvider
The use case I have is when a user signs out of my app then signs up as a new/different user the previous users' state is still stored in the providers.
it is cleared automatically when the app is restarted, however.
MultiProvider(
providers: ServiceProvider().providers,
child: Consumer<AppLocale>(builder: (BuildContext context, AppLocale locale, Widget? child) {
return MaterialApp(
title: 'Application',
localizationsDelegates: AppLocalizations.localizationsDelegates,
debugShowCheckedModeBanner: false,
navigatorKey: RouteService.navigatorKey,
scaffoldMessengerKey: RouteService.rootScaffoldMessengerKey,
supportedLocales: AppLocalizations.supportedLocales,
onGenerateRoute: Routes.generateRoute,
initialRoute: RoutePaths.SplashScreen,
onUnknownRoute: Routes.generateRoute,
navigatorObservers: <NavigatorObserver>[AppRouteObserver()],
locale: locale.appLocal,
theme: appTheme(),
// debugShowMaterialGrid: true,
// showPerformanceOverlay: true,
// checkerboardRasterCacheImages: true,
// checkerboardOffscreenLayers: true,
// showSemanticsDebugger: true,
);
}),
)
Below is my ServiceProvider class
class ServiceProvider {
final List<SingleChildWidget> _independentServices = <SingleChildWidget>[
// ignore: always_specify_types
Provider.value(value: null)
];
final List<SingleChildWidget> _dependentServices = <SingleChildWidget>[];
final List<SingleChildWidget> _uiConsumableProviders = <SingleChildWidget>[
// ignore: always_specify_types
ChangeNotifierProvider(
create: (BuildContext context) => AppLocale(),
),
// ignore: always_specify_types
ChangeNotifierProvider(
create: (BuildContext context) => UserDetailsProvider(),
),
// ignore: always_specify_types
ChangeNotifierProvider(
create: (BuildContext context) => AccountAddressProvider(),
),
// ignore: always_specify_types
ChangeNotifierProvider(
create: (BuildContext context) => ServiceProvidersProductsProvider(),
),
// ignore: always_specify_types
ChangeNotifierProvider(
create: (BuildContext context) => LookupValuesProvider(),
),
];
List<SingleChildWidget> get providers {
return <SingleChildWidget>[..._independentServices, ..._dependentServices, ..._uiConsumableProviders];
}
}

Multiple ScopedModels in flutter

I followed a tutorial from a flutter app with login system using a scope_model. Then, I added a new scope_model called Group to use in a new "route" called opportunities.
But in my new route I can't call the scope_model Group and I allways see the same error:
Error: Could not find the correct ScopedModel.
I think that my mistake is in main.dart. I don't know how to "invoque" my new scope_model.
Here is my code.
file opportuinity.dart
import 'package:scoped_model/scoped_model.dart';
import 'package:business_maker/data/models/group_api.dart';
(...)
#override
Widget build(BuildContext context) {
final _group = ScopedModel.of<GroupModel>(context, rebuildOnChange: true);
file main.dart
#override
Widget build(BuildContext context) {
return ScopedModel<ThemeModel>(
model: _model,
child: new ScopedModelDescendant<ThemeModel>(
builder: (context, child, theme) => ScopedModel<AuthModel>(
model: _auth,
child: MaterialApp(
theme: theme.theme,
home: new ScopedModelDescendant<AuthModel>(
builder: (context, child, model) {
if (model?.user != null) return Home();
return LoginPage();
}),
routes: <String, WidgetBuilder>{
"/login": (BuildContext context) => LoginPage(),
"/menu": (BuildContext context) => Home(),
"/home": (BuildContext context) => Home(),
"/settings": (BuildContext context) => SettingsPage(),
"/opportunities": (BuildContext context) => OpportunityPage()
},
),
),
));
}
thank you
If you want to use models in different routes then you need to place the model above the Navigator which is usually created in a WidgetsApp/MaterialApp/CupertinoApp
In your code I do not see a ScopedModel<Group> that's placed above the navigator. Or anywhere, actually. You need to add the group model above the navigator (something the materialapp creates for you).
Widget build(BuildContext context) {
return ScopedModel<ThemeModel>(
model: _model,
child: ScopedModel<Group>(
model: _yourGroupModel,
child: new ScopedModelDescendant<ThemeModel>(
builder: (context, child, theme) => ScopedModel<AuthModel>(
model: _auth,
child: MaterialApp(
theme: theme.theme,
home: new ScopedModelDescendant<AuthModel>(
builder: (context, child, model) {
if (model?.user != null) return Home();
return LoginPage();
}),
routes: <String, WidgetBuilder>{
"/login": (BuildContext context) => LoginPage(),
"/menu": (BuildContext context) => Home(),
"/home": (BuildContext context) => Home(),
"/settings": (BuildContext context) => SettingsPage(),
"/opportunities": (BuildContext context) => OpportunityPage()
},
),
),
)
)
);
}