美文网首页
9.Flutter中的push与pop

9.Flutter中的push与pop

作者: 李响2022 | 来源:发表于2020-03-08 01:30 被阅读0次
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
      home: Scaffold(body: HomePage())
    ));
}

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      child: Center(
        child:RaisedButton(
          child:Text('push'),
          onPressed:(){
            Navigator.of(context).push(
              MaterialPageRoute(builder: (context) => Page2())
            );
        })
      )
    );
  }
}

class Page2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.green,
        child: Center(
          child:RaisedButton(
            child:Text('pop'),
            onPressed:(){
              Navigator.pop(context);
          })
        )
      )
    );
  }
}

相关文章

网友评论

      本文标题:9.Flutter中的push与pop

      本文链接:https://www.haomeiwen.com/subject/htpldhtx.html