1

I have a code that displays a list of devices. When a user clicks on a device, they are redirected to a page with a detailed description of the device.

phone_list.dart

 .....
child: TextButton(
        onPressed: (){{
         Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) =>const 
             DeviceDescription(),
            settings: RouteSettings(
               arguments: phones[index],
                                    ),
     .....

device_description.dart

class DeviceDescription extends StatelessWidget {
  const DeviceDescription({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final device = ModalRoute.of(context)!.settings.arguments as Phone;

    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Text(device.name),
        ........
      ),
    );
  }
}

But my problem is that when updating the page with a description of the device, the user is again returned to the page with a list of all devices.

Is there any way to fix this problem? Perhaps I need to write a new route in main.dart?. Then tell me how to change the code so that information about a specific device is displayed on this page.

enter image description here

Paul
  • 53
  • 3
  • 21
  • Trying to understand the problem, because what you're doing is pretty straightforward. You say that "when updating the page with a description of the device, the user is again returned to the page with a list of all devices". Are you saying that this page takes you back to the list page like in a loop? Please explain with a bit more detail the part when you update the **DeviceDescription** page. – Roman Jaquez Mar 06 '22 at 18:38
  • @Roman Jaquez I added gif in my question – Paul Mar 06 '22 at 19:15
  • Well, you are refreshing the whole page, which almost equates reinitializing the whole app. The issue here is that you will have to maintain some sort of state so when you reload you can land back where you were. Other people have had the same issue as you as in this post https://stackoverflow.com/questions/61232367/flutter-web-provider-loss-of-state-when-browser-refresh. You may have to rethink your navigation strategy, maybe look at Navigation 2.0 where routing is more adapted to web. – Roman Jaquez Mar 06 '22 at 20:03

0 Answers0