无法将ChangeNotifierProvider.value放在扑波中以反映数据中的变化
我无法在 UI 中放置changeNotifierProvider.value 来显示更改(已检查并且数据没有问题),如果您可以,请指导我在下面的小部件中放置changeNotifierProvider.value 的位置和方式。谢谢。
如果您需要任何进一步的信息,请告诉我。
更改.dart
@override
Widget build(BuildContext context) {
final check = Provider.of<UserProfileReadProvider>(context);
final n = check.items;
return Scaffold(
body: Container(
margin:
const EdgeInsets.only(top: 50, left: 40, right: 10, bottom: 90.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
radius: 50.0,
backgroundColor: Colors.blue.shade800,
child: const Text('AM'),
),
const SizedBox(height: 70),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Name : ${n.name}',
style: const TextStyle(
fontStyle: FontStyle.normal,
color: Colors.black,
fontSize: (18.0)),
),
const SizedBox(height: 15),
Text(
'Address: ${n.address}',
style: const TextStyle(
fontStyle: FontStyle.normal,
color: Colors.black,
fontSize: 18.0),
),
main.dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (ctx) => UserProfileReadProvider(),
),
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (ctx) =>Page(),
},
));
}
}
提供程序.dart
UserProfileInformation nitems = UserProfileInformation();
Future<void> addUserinformation(
UserProfile st, var imagecheck) async {
Map<String, String> headers = {
"Content-Type": "charset=utf-8",
"Content-type": "application/json"
};
var uri = Uri.parse('http://localhost:3001/userprofile/check/upload');
try {
var request = http.MultipartRequest('POST', uri);
request.headers.addAll(headers);
request.fields['userId'] = st.userId;
request.fields['name'] = st.name;
request.fields['address'] = st.address;
var response = await request.send();
print(response.statusCode);
if (response.statusCode == 201) {
st = nitems;
notifyListeners();
} else {
print('invalid data ');
}
} catch (error) {
print(error);
}
}
I am unable to place changeNotifierProvider.value for the UI to show the changes( checked and no issue with the data), If you can please guide me as to where and how to place the changeNotifierProvider.value in the below widget.Thank you.
Please let me know if u require any further information.
change.dart
@override
Widget build(BuildContext context) {
final check = Provider.of<UserProfileReadProvider>(context);
final n = check.items;
return Scaffold(
body: Container(
margin:
const EdgeInsets.only(top: 50, left: 40, right: 10, bottom: 90.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
radius: 50.0,
backgroundColor: Colors.blue.shade800,
child: const Text('AM'),
),
const SizedBox(height: 70),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Name : ${n.name}',
style: const TextStyle(
fontStyle: FontStyle.normal,
color: Colors.black,
fontSize: (18.0)),
),
const SizedBox(height: 15),
Text(
'Address: ${n.address}',
style: const TextStyle(
fontStyle: FontStyle.normal,
color: Colors.black,
fontSize: 18.0),
),
main.dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (ctx) => UserProfileReadProvider(),
),
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (ctx) =>Page(),
},
));
}
}
provider.dart
UserProfileInformation nitems = UserProfileInformation();
Future<void> addUserinformation(
UserProfile st, var imagecheck) async {
Map<String, String> headers = {
"Content-Type": "charset=utf-8",
"Content-type": "application/json"
};
var uri = Uri.parse('http://localhost:3001/userprofile/check/upload');
try {
var request = http.MultipartRequest('POST', uri);
request.headers.addAll(headers);
request.fields['userId'] = st.userId;
request.fields['name'] = st.name;
request.fields['address'] = st.address;
var response = await request.send();
print(response.statusCode);
if (response.statusCode == 201) {
st = nitems;
notifyListeners();
} else {
print('invalid data ');
}
} catch (error) {
print(error);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论