Is there a way to navigate from one dart "page" to a specific point in another? This will get me to a given page:
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => WK3()),
);
But I want to navigate to a specific child or row within that page (which is fairly long, and would otherwise require a lot of scrolling). I am used to working with html, where you just have to indicate a position within a page using a hash tag: #here That should be possible to do in Flutter/Dart, right? [addendum] On the target page I have broken up the rows into widgets:
class WKl extends CardExamplesApp {
const WKl({super.key});
@override
Widget build(BuildContext context) {
return Stack(
children: [
Image.asset('images/2wk2l.png',
fit: BoxFit.fitWidth,
key: Key('wk_2l')),
SizedBox(
width: 210,
height: 173,
child: FloatingActionButton(
heroTag: "btn2l",
elevation: 0,
backgroundColor: Colors.blue.withOpacity(0),
shape: BeveledRectangleBorder(borderRadius: BorderRadius.zero),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => KT()),
);
},
),
),
],
);
}
}
class WKm extends CEA{
const WKm({super.key});
@override
Widget build(BuildContext context) {
return SafeArea(
child:
Image.asset('images/2wk2m.png',
fit: BoxFit.fitWidth),
);
}
}
The rows alternate between being "static" and having buttons leading to the second page. This seemed to be the only way to position the buttons on what was once a very long png image, since the buttons could only take relative positions (located on the screen, not within the long column). By pressing one of these buttons, I can navigate to the second page, and then return to an identified row, but only that row is displayed after returning. Way back:
Navigator.pushNamed(
context,
'/wk_2l',
arguments: {'scrollTo': elementId},
);
I have tried variations with .pop, am exploring ways to identify state, stateful, etc., but... the first page should not change state; the second should only appear when called, then allow a return to the first. The column is preceded by a list:
class CEA extends StatelessWidget {
const CEA({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
WKa(),
WKl(),
etc.
I had thought I might need to fix the row wickets in the column, so the whole column opens and can be scrolled when we return from the second page, but I couldn't even imagine how that might be done. Eventually, though, I realised I just had to "pop" the second page, and the first would open at the point of departure;
onPressed: () {
Navigator.pop(context);
},
My mistake was not understanding that, when Flutter says a page is "over" another, it really is "over" it, and navigation isn't like in html, php, old-fashioned subroutines, etc.