如何从SharedPreferences获取ID并将其显示在Widget中

时间:2020-04-14 13:04:49

标签: flutter dart

我需要从opJson获取id,并在Widget中显示

对象是:

flutter: "{id: 2, ......}
@override
void function() async {
    final prefs = await SharedPreferences.getInstance();
    var usu = prefs.getString('user') ?? 0;
    String opJson = json.jsonEncode(usu);
    print('+++++++');
    print(opJson);
}
Widget _buildDrawer(BuildContext context) {
    function();
    return Drawer(
      child: ListView(
        dragStartBehavior: DragStartBehavior.down,
        children: <Widget>[
          Image.asset('assets/l.png'),
          const DrawerHeader(child: 
                  Center(child: 
                     Text('A', 
                         style: TextStyle(
                               color: Colors.black, 
                               fontWeight: FontWeight.w700, 
                               fontSize: 28.0)))),
          ListTile(
            leading: Icon(Icons.account_balance),
            title: Text('User:'),
            onTap: () {
              Navigator.popAndPushNamed(context, '/dashboard');
            },
            enabled: true,
          ),

0 个答案:

没有答案