0

容器(填充:EdgeInsets.all(15),

  child: Column(
    children: [
      TextFormField(
        onTap: () =>
            Navigator.of(context).pushNamed(AirportSearchScreen.id).then(
                  (value) 
              {
            setState(() {
              _initValues['departureCity'] = value;
              print(_initValues['departureCity']);
            });
          },
                ),
        decoration: InputDecoration(
          labelText: 'Departure City',
        ),
        initialValue: _initValues['departureCity'],
      ),
    ],
  ),
);

当我打印该值时,它会给出正确的结果。但我无法在 TextFormField 上得到结果。

4

1 回答 1

1

试试下面的代码:

child: Column(
        children: [
          TextFormField(
            onTap: () =>
            Navigator.of(context).pushNamed(AirportSearchScreen.id).then(
                  (value) 
              {
               setState(() {
                    _initValues['departureCity'] = value;
                    print(_initValues['departureCity']);
                  });
                },
                ),
            decoration: InputDecoration(
              labelText: 'Departure City',
            ),
            controller: TextEditingController(text: _initValues['departureCity']),
          ),
        ],
      ),
于 2020-09-10T18:55:27.387 回答