看看我做的这个例子:
import 'package:flutter/material.dart';
import 'package:json_parsing_example/offerScreen.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Login(),
debugShowCheckedModeBanner: false,
);
}
}
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: <Widget>[
RaisedButton(
child: Text('Tap'),
onPressed: () async {
var response = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OfferPage(),
));
if (response !=
null) // This is when the user presses the back button
{
// if user inputs anything then this is where the output will come
print(response);
}
//this response is you value that you selected
// you can do processing on this page or the selection
//page
},
),
RaisedButton(
child: Text('Tap2'),
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (context) => Container(
height: MediaQuery.of(context).size.height * 0.95,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 12, top: 15),
child: GestureDetector(
onTap: () {
Navigator.of(context).pop(null);
},
child: Icon(
Icons.close,
size: 30,
),
),
),
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor,
width: 0.5)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(
width: MediaQuery.of(context)
.size
.width *
0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration: TextDecoration
.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor,
width: 1.0)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(
width: MediaQuery.of(context)
.size
.width *
0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration: TextDecoration
.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor,
width: 1.0)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(
width: MediaQuery.of(context)
.size
.width *
0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration: TextDecoration
.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(
height:
MediaQuery.of(context).size.height * 0.01),
Container(
width: MediaQuery.of(context).size.width,
height: 60,
child: Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: new FlatButton(
color: Colors.red,
child: new Text(
'BUY NOW AND SAVE',
style: TextStyle(
color: Colors.white,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
),
),
],
),
),
],
),
),
);
},
),
],
),
)));
}
}
这是优惠页面:
import 'package:flutter/material.dart';
class OfferPage extends StatefulWidget {
@override
_OfferPageState createState() => _OfferPageState();
}
class _OfferPageState extends State<OfferPage> {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
Navigator.of(context).pop(null);
},
child: Icon(
Icons.close,
size: 30,
),
),
),
],
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor, width: 0.5)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(width: size.width * 0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration:
TextDecoration.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor, width: 1.0)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(width: size.width * 0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration:
TextDecoration.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
color: Theme.of(context).hintColor, width: 1.0)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RadioListTile(
value: 1,
groupValue: 1,
title: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"12 months",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
Text(
"Rs.4,375",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13),
),
],
),
SizedBox(width: size.width * 0.005),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"50% off",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
),
),
Text(
"9,876",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 13,
decoration:
TextDecoration.lineThrough),
),
],
),
],
),
activeColor: Colors.teal,
onChanged: (val) {
setState(() {});
}),
),
),
SizedBox(height: size.height * 0.01),
Container(
width: MediaQuery.of(context).size.width,
height: 60,
child: Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: new FlatButton(
color: Colors.red,
child: new Text(
'BUY NOW AND SAVE',
style: TextStyle(
color: Colors.white,
),
),
onPressed: () {
Navigator.of(context).pop("your selected value");
},
),
),
),
),
],
),
),
],
),
),
),
);
}
}
检查一下,让我知道它是否有效。