EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK - WindowsException was thrown running a test: Error 0x00000000 - whilst running a widget test - flutter

This is the error message:
The following WindowsException was thrown running a test:
Error 0x00000000: The operation completed successfully.
I am trying to pumpWidget using a ChangeNotifierProvider.
await tester.pumpWidget(
ChangeNotifierProvider<PageViewModel>(
create: (_) => PageViewModel(),
child: MaterialApp(
home: Scaffold(
body: Page(),
),
),
),
);
Reason I am doing the above is because in my Page() I return a Consumer
return Consumer<PageViewModel>(
builder: (context, model, child) => Scaffold()
I don't understand what am I doing wrong.
I have split my problem into parts to understand what was I missing until I bumpped into this and I honestly cannot get out of it.
e.g
Returning just the MaterialApp and calling my page. I read the error message and I have fixed it with the guide flutter was giving.

Related

Flutter image assets not loading after redirect with go_router & login

I have a small Flutter app with 2 screens (/login & /home) and I use go_router to navigate and animated_login. The assets are placed on the home screen and they load fine if I directly access the screen, so pubspec.yaml is correctly defined.
The images fail to load only when I redirect to /home after /login. One interesting observation is that when this happens, the Flutter dev server seems to be hanging (stops responding, but doesn't crash, can't restart it with R, the browser tab complains that it lost connection to the server etc.). This problem occurs also with a combination of auto_route and flutter_login.
Thanks for any hints.
Router setup (tried also w/ the redirect parameter at router level rather than individual routes):
GoRouter routerGenerator(UserData userData) {
return GoRouter(
initialLocation: Routes.home,
refreshListenable: userData,
debugLogDiagnostics: true,
routes: [
GoRoute(
path: Routes.home,
builder: (_, __) => BasicScreen(),
redirect: (state) => userData.loggedIn ? null : Routes.login
),
GoRoute(
path: Routes.login,
builder: (_, __) => AnimLoginScreen(),
redirect: (state) => !userData.loggedIn ? null : Routes.home
),
GoRoute(path: '/', builder: (_, __) => BasicScreen())
]);
}
abstract class Routes {
static const home = '/home';
static const login = '/login';
}
Main app:
void main() {
runApp(
MultiProvider(providers: [
//other providers here
ChangeNotifierProvider(create: (_) => UserData()),
], child: MyApp()),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
final router =
routerGenerator(Provider.of<UserData>(context, listen: false));
return MaterialApp.router(
title: 'Playground',
routeInformationParser: router.routeInformationParser,
routeInformationProvider: router.routeInformationProvider,
routerDelegate: router.routerDelegate,
);
}
}
Basic screen:
class BasicScreen extends StatelessWidget {
BasicScreen({super.key});
#override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Image(image: AssetImage("assets/images/image1.png")),
Image(image: AssetImage("assets/images/image2.png")),
Image(image: AssetImage("assets/images/image3.png")),
],
),
);
}
}
Solution
Provide a simple proxy over both Flutter DevTool & backend services with SSL capabilities.
Explanation
The issue has nothing to do with routing, but rather the dev setup. Our backend services require SSL connections, but Flutter dev tool doesn't support that. Flow:
Flutter DevTool starts the project (plain HTTP) and opens Chrome window.
Assets load ok.
User logs in, backend service requires HTTPS for secure cookies.
Browser upgrades all localhost connections to HTTPS.
Flutter DevTools fails to provide SSL connection.
Assets fail to load.
The hanging DevTool is caused by the same issue: seems to me that the DevTool is pending the WebSocket connection to be opened by the JS code running in the browser, but as the browser initiates an HTTPS connection to the DevTool, it even fails to load the JS code. Therefore, the DevTool never completes the init process (as it has no incoming connection).

how to refresh current page while doing pull to refresh (LiquidPullToRefresh) in Flutter Bloc

am using bloc method for home screen. I want to do pull to refresh in home screen...
I tired too many ways not getting solution...could you please suggest some solution.
In side onrefresh() I added few changes
1 . BlocProvider(
create: (context) => OttGetAllMovie(httpClient: http.Client())
..add(FeedsFetched(widget.title, "homePage")),
//child: HomePage(),
child: OttGetHomeInnerCatPage(
wtitle: widget.title, mixpanelinner: widget.mixpanel),
)
2. _feedsBloc.add(FeedsFetched(widget.wtitle, "homePage"));
3. setState(() {
_feedsBloc.add(FeedsFetched(widget.wtitle, "homePage"));
BlocProvider(
create: (context) => OttGetAllMovie(httpClient: http.Client())
..add(FeedsFetched(widget.title, "homePage")),
//child: HomePage(),
child: OttGetHomeInnerCatPage(
wtitle: widget.title, mixpanelinner: widget.mixpanel),
)
});
While
this seems to be the method you're using to fetch data
OttGetAllMovie(httpClient: http.Client())
..add(FeedsFetched(widget.title, "homePage")),
Wrap your body in liquid pull to refresh
LiquidPullToRefresh(
key: _refreshIndicatorKey, // key if you want to add
onRefresh: ()async{
//cal your data source
OttGetAllMovie(httpClient: http.Client())
..add(FeedsFetched(widget.title, "homePage")),
}
child: ListView(), // scroll view
);

Problem with update multiprovider flutter

I recently updated some dependencies of my flutter application and I had this problem with the multiprovider, could someone guide me on how is the new syntax or what is the problem here?
the previous provider dependency I was working with was ^ 3.0.0 + 1, now it is at 5.0.0
Never post images of your code, we can't copy from it or reproduce it. Here's a setup of some multiproviders in a project I have:
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<UserState>(create: (ctx) => UserState()),
ChangeNotifierProvider<Cart>(create: (ctx) => Cart()),
ChangeNotifierProvider<LocationProvider>(create: (ctx) => LocationProvider()),
],
child: MaterialApp(theme: ThemeData(
primarySwatch: Colors.blue,
),home: Consumer<UserState>(builder: (context, userState, __) {
if (userState.firstRun) {
userState.getLastUser();
}
return userState.isSignedin ? CustomDrawer(appUser: userState.user) : LoginPageScreen();
}),
),
);
}
There are changes between provider ^3 and ^5, the documentation is pretty decent and does a good job explaining things. The code I posted is using provider: ^5.0.0.

Why showcaseview throws error on first try?

Hey I am using ShowCaseView in my Flutterapp. When I first open my app, after registration there is no showcase, not even the icon which should be 'showcased' is shown. But when I am closing the app and opening it again it works just fine.
Thats the code referring to showcase:
class _HomeSearchPageState extends State<HomeSearchPage> {
final keyOne = GlobalKey();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => ShowCaseWidget.of(context).startShowCase([
keyOne,
]),
);
}
And now the scaffold:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(getTopBarSize()),
child: AppBar(
automaticallyImplyLeading: false,
title: Text(
'username',
style: TextStyle(fontSize: 14),
),
actions: <Widget>[
Showcase(
key: keyOne,
description: 'test',
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch())
.whenComplete(() => setName());
}),
),
],
),
),)
I did exactly the same as in the Github example but still it throws this error the first time:
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2 _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3 _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786
════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
These errors are kind a looped, so the debug console shows them all the time.
The only difference between the first app opening and the second one is: In the first one the user enters a registrationpage and after this he enters the page with the showcaseview. In the second the user enters directly the page with the showcaseview. How can this affect the showcase and more accurate why does this throw the errors?
Not sure if we share a similar issue but maybe my answer will help you somehow :). The issue occurs when I navigate to the page where I have Showcase widget, but it does not occur when I navigate "back" to the page from the other page.
Maybe you can check this page "This error is thrown if you haven't wrapped your widget with ShowCaseWidget. This is not the problem with the package itself."
Thus, I tried raising the level of the ShowCaseWidget in the main.dart and the issue was solved.
void main() {
// runApp(MyApp());
runApp(
ShowCaseWidget(
autoPlay: false,
autoPlayDelay: Duration(seconds: 8),
autoPlayLockEnable: false,
builder: Builder(
builder: (context) => MyApp(),
),
onStart: (index, key) {
print('onStart: $index, $key');
},
onComplete: (index, key) {
print('onComplete: $index, $key');
},
),
);
}
So far the app still works well. I will report again here in case any issues occur.

Flutter auto_route, getter 'key' was called on null

import 'package:myapp/core/routes/router.gr.dart' as app_router;
child: MaterialApp(
title: 'MyApp',
debugShowCheckedModeBanner: false,
builder: ExtendedNavigator.builder<app_router.Router>(
router: app_router.Router()
),
I have implememented autoroute however I get an error here that the getter key was called on null
As Masnun pointed out, commenting out the line 37 solves the issue. However, there is a different solution that doesn't involve touching the source of the auto_route.
I fixed this issue by removing .builder from:
builder: ExtendedNavigator.builder(
router: Router(),
...
),
and changed to
builder: ExtendedNavigator(
router: Router(),
...
),
The problem is here is this line (line 37).
key: GlobalObjectKey(nav.key),
Commenting out the line from library works fine for me. It may be a temporary problem.