Попробуйте использовать приведенный ниже код. Работает отлично.
ПЕРВЫЙ ЭКРАН
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'First Screen'
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SecondScreen('Babel Row'),
),
);
},
child: Card(
child: Container(
height: 100,
width: MediaQuery.of(context).size.width,
child: Center(child: Text('Babel Row')),
),
),
),
SizedBox(height: 20,),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => SecondScreen('Bench Press'),
),
);
},
child: Card(
child: Container(
height: 100,
width: MediaQuery.of(context).size.width,
child: Center(child: Text('Bench Press')),
),
),
),
],
),
),
);
}
}
ВТОРОЙ ЭКРАН
class SecondScreen extends StatelessWidget {
// define a string variable
final String name;
// create a constructor
const SecondScreen(this.name);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// set the app bar title here
title: Text(name),
),
body: Center(
child: Text(
name,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w500,
),
),
),
);
}
}
Вывод:
Надеюсь, это поможет.