Greetings, I wrote some logic to retrieve a json object and pass it through a series of widgets for presenting on my iOS/Android application. My issue is that the data doesn’t reach the next widget that is set to receive it. I’ve been trying all day to get this functionality up and running – can’t seem to spot why its not getting the values. My code will be below
class ClientPortal extends StatefulWidget {
const ClientPortal({
super.key,
});
@override
State<ClientPortal> createState() => _ClientPortalState();
}
class _ClientPortalState extends State<ClientPortal> {
// State Variables
dynamic userData;
dynamic dataCount;
fetchClientPortalData() async {
final storage = FlutterSecureStorage();
final storageObj = await storage.readAll();
var uid = storageObj['uid'];
var accessToken = storageObj['access_token'];
var client = storageObj['client'];
try {
Response response = await post(
Uri.parse('http://localhost:3000/api/v1/clients/client_portal'),
body: {'uid': uid, 'access-token': accessToken, 'client': client});
print(response.statusCode);
if (response.statusCode == 200) {
var clientPortalData = jsonDecode(response.body.toString());
var responseHeaders = response.headers;
setState(() {
dataCount = clientPortalData['dataCount'];
userData = clientPortalData['userData'];
});
}
} catch (e) {
print(e);
}
}
late Future<dynamic> _clientPortalData;
@override
void initState() {
_clientPortalData = fetchClientPortalData();
super.initState();
}
Widget build(BuildContext context) {
return FutureBuilder<dynamic>(
future: _clientPortalData,
initialData: {},
builder: (context, snapshot) {
List<Widget> children;
if (snapshot.connectionState == ConnectionState.done) {
print('INSIDE OF CLIENT PORTAL');
// works start
print(userData);
// works end
// fails to store data attributes here in widget below
return PortalNavigator(
dataCount: dataCount,
userData: userData);
} else {
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: children,
));
},
);
}
}
// THIS WIDGET DOES NOT RECEIVE DATA
class PortalNavigator extends StatefulWidget {
PortalNavigator(
{super.key,
dataCount: dataCount,
userData: userData});
@override
State<PortalNavigator> createState() => _PortalNavigatorState();
}
class _PortalNavigatorState extends State<PortalNavigator> {
dynamic userData;
dynamic dataCount;
@override
Widget build(BuildContext context) {
print('NO DATA EXIST FOR VARS ABOVE');
print(userData);
print(dataCount);
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: PortalNavigatorView(
dataCount: dataCount,
userData: userData),
debugShowCheckedModeBanner: false,
);
}
}