我想在颤振中使用突变graphql。但我得到了这个按摩,我无法加载我的代码。
这是我的代码:
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final HttpLink httpLink = HttpLink(
'https://test.podkadeh.ir/graphql/',
);
final ValueNotifier<GraphQLClient> client= ValueNotifier<GraphQLClient>(
GraphQLClient(
link: httpLink,
cache: GraphQLCache(),
)
);
return GraphQLProvider(
child: HomePage(),
client: client,
);
}
}
class HomePage extends StatelessWidget {
TextEditingController nameController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
String createUser = '''
mutation createUser{
createUser(userInput: {Email: "$String", Password: "$String"}){
Name,
Email
}
}
''';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SingleChildScrollView(
child: Column(
children: [
Mutation(
options: MutationOptions(
document: gql(createUser),
),
builder:(
RunMutation insert,
QueryResult? result,
){
return
Column(
children: [
TextField(
decoration: InputDecoration(hintText: "Name"),
controller: nameController,
),
TextField(
decoration: InputDecoration(hintText: "Email"),
controller: emailController,
),
TextField(
decoration: InputDecoration(hintText: "Password"),
controller: passwordController,
),
RaisedButton(
child: Text("Submit"),
onPressed:(){
insert(<String, dynamic>{
"Email": emailController.text,
"Name" : nameController.text,
// "Password" : passwordController.text,
});
}),
Text("Result : \n ${result!.data?.toString()}",),
],
);
},
),
],
),
),
);
}
}
这是我得到的错误:
`未找到材料小部件。
TextField 小部件需要一个 Material 小部件祖先。在材料设计中,大多数小部件在概念上都“打印”在一张材料上。在 Flutter 的材质库中,该材质由 Material 小部件表示。例如,渲染墨水飞溅的是 Material 小部件。正因为如此,许多材质库小部件要求在它们上方的树中存在一个材质小部件。
要引入 Material 小部件,您可以直接包含一个,也可以使用包含 Material 本身的小部件,例如 Card、Dialog、Drawer 或 Scaffold。
找不到 Material 祖先的特定小部件是: TextField controller: TextEditingController#c0f68(TextEditingValue(text: ┤├, selection: TextSelection(baseOffset: -1, extentOffset: -1, affinity: TextAffinity.downstream, isDirectional: false) ,组成:TextRange(开始:-1,结束:-1)))装饰:InputDecoration(hintText:“名称”)脏依赖:[UnmanagedRestorationScope,MediaQuery]状态:_TextFieldState#49d5d这个小部件的祖先是::列方向:垂直 mainAxisAlignment:开始 crossAxisAlignment:中心 renderObject:RenderFlex#ce4db NEEDS-LAYOUT NEEDS-PAINT:StreamBuilder<QueryResult?> 状态:_StreamBuilderBaseState<QueryResult?, AsyncSnapshot<QueryResult?>>#26355:突变依赖关系:[_InheritedGraphQLProvider] 状态:MutationState #0e229:列方向:垂直 mainAxisAlignment:开始 crossAxisAlignment:中心 renderObject:RenderFlex#1a73f 需要-布局需要-油漆需要-合成-位-更新:SingleChildScrollView 依赖项:[PrimaryScrollController]:MaterialApp 状态:_MaterialAppState#7f306:主页:_InheritedGraphQLProvider:GraphQLProvider 状态:_GraphQLProviderState#bab20 :MyApp ...相关的导致错误的小部件是:TextField TextField:file:///G:/%D8%B3%D9%88%D8%B1%D8%B3%20%D9%87%D8%A7 %DB%8C%20%D9%81%D9%84%D8%A7%D8%AA%D8%B1/mutation_gql/lib/main.dart:62:25`_GraphQLProviderState#bab20 : MyApp ... 相关的导致错误的小部件是:TextField TextField:file:///G:/%D8%B3%D9%88%D8%B1%D8%B3%20%D9%87% D8%A7%DB%8C%20%D9%81%D9%84%D8%A7%D8%AA%D8%B1/mutation_gql/lib/main.dart:62:25`_GraphQLProviderState#bab20 : MyApp ... 相关的导致错误的小部件是:TextField TextField:file:///G:/%D8%B3%D9%88%D8%B1%D8%B3%20%D9%87% D8%A7%DB%8C%20%D9%81%D9%84%D8%A7%D8%AA%D8%B1/mutation_gql/lib/main.dart:62:25`
谁能帮帮我?