-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_InternalLinkedHashMap<dynamic, dynamic> is not a subtype of Map<String, dynamic>? in type cast #1091
Comments
@mdmomeni Thanks for reporting this! Do you mind sharing how you're initializing the client? Specifically, how are you providing the Hive box to the client. |
My void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase
await FCM.init();
// Initialize Hive (from GraphQL package)
await initHiveForFlutter();
// Initialize UserController Hive box
await UserController.init(); // await Hive.openBox<String>("user");
// GraphQL
final HttpLink httpLink = HttpLink(
"http://10.0.2.2:8000/graphql",
);
final AuthLink authLink = AuthLink(
getToken: () => UserController.token,
);
final Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: link,
cache: GraphQLCache(store: HiveStore()),
),
);
runApp(MyApp(client));
} Also class MyApp extends StatelessWidget {
const MyApp(this.client, {Key? key}) : super(key: key);
final ValueNotifier<GraphQLClient> client;
@override
Widget build(BuildContext context) {
return GraphQLProvider(
client: client,
child: GetMaterialApp(
... Client provider: GetBuilder<SearchController>(
init: SearchController(),
builder: (_) {
return GraphQLConsumer(builder: (client) {
return Expanded(
child: Column(children: [
searchField(client, _),
const SizedBox(height: 10),
Expanded(
child: Stack(
alignment: Alignment.center,
children: [mainBody(_), submitBtn()],
))
]));
});
}),
...
Widget searchField(GraphQLClient client, SearchController _) {
return Padding(
padding: const EdgeInsets.all(10),
child: TextField(
textDirection: TextDirection.ltr,
decoration: CInputDecoration(hintText: "جستجو"),
onChanged: (q) => onInputChange(q, client, _),
),
);
} |
Cheers @mdmomeni! I've created a PR with a fix. If you're able to verify that it's working for you, that'd be a huge help! |
Thank you, but how can I replace the updated code? and should I review the PR or something after testing it? |
@mdmomeni You should be able to add the branch as a dependency directly. I.e., update your graphql_flutter:
git:
url: git://github.com/zino-hofmann/graphql-flutter.git
ref: fix-hive
path: packages/graphql_flutter I'm not sure if you can add a review, but a comment on the PR (or here) will be fine. |
@budde377 This is my data structure: [
{
_id: 6141e5e09fa3f5afd79e6ecb,
type: urlLaunch,
content:
{
image: image1.png,
url: https://example1.com,
},
__typename: Recommend,
},
{
_id: 6141e8029fa3f5afd79e6ecc,
type: urlLaunch,
content:
{
image: image.png,
url: https://example.com,
},
__typename: Recommend,
},
] I use @freezed
class Recommend with _$Recommend {
factory Recommend({
required String type,
required IMap<String, String> content,
}) = _Recommend;
factory Recommend.fromJson(Map<String, dynamic> json) =>
_$RecommendFromJson(json);
}
void exampleQuery () {
final result =
await client.query$Recommend(Options$Query$Recommend(
operationName: 'exampleQuery',
fetchPolicy: FetchPolicy.cacheAndNetwork,
variables: Variables$Query$Recommend(
memberId: memberId,
),
));
if (result.hasException) {
handleException(result);
throw Exception(result.exception.toString());
}
final recommendList = IList.fromJson(
/// 🔨 If I want to not report this exception, I need to do the following
/// FIX: should work code json.decode(json.encode(result.data?["exampleQuery"]))
result.data?["exampleQuery"],
(dynamic item) => Recommend.fromJson(item),
);
return recommendList;
} |
Thanks for reporting. Please check if #1167 fixes this for you! @Adherentman |
@budde377 graphql:
git:
url: https://github.com/zino-hofmann/graphql-flutter.git
ref: main
path: packages/graphql
graphql_flutter:
git:
url: https://github.com/zino-hofmann/graphql-flutter.git
ref: main
path: packages/graphql_flutter get error: Because every version of graphql_flutter from git depends on graphql from hosted and example_app depends on graphql from git, graphql_flutter from git is forbidden.
So, because example_app depends on graphql_flutter from git, version solving failed.
pub get failed (1; So, because example_app depends on graphql_flutter from git, version solving failed.) Or when will it be published on pub.dev |
this is your error, you should put also inside the override package the graphql, this tell to pub "Hey you are using git, but there is some depenciences in common, so ignore it and use git". It is strange, but the dependieces resolution world is more strange. BTW I'm releasing the new beta release later in the day |
I have used main branch to verify that it runs very well. Thank you. |
@Adherentman the new beta is out |
This is the error when I try to run
client.query
with aGraphQLConsumer
foronChanged
event of aTextField
seems there is an issue during encoding/decoding the API result into the Hive box
(it's weird it was working as expected yesterday while I did not change the code and today it has issues)
Expected behavior
Get the result from
client.query
and update the view (using aGetx
controller sinceQuery
was not working as expected)device / execution context
Android simulator
The event function:
Stacktrace:
The text was updated successfully, but these errors were encountered: