Navigator.push

Navigator.push

Navigator.push<T>(context, MaterialPageRoute(builder:(context) => MyPage()) ) → Future<T> 

Navigator.push(context, MaterialPageRoute(builder:(context) => MyPage()) )

açıklama

Oluştur git.isimlendirilmemiş sayfayı ekrana basar.

parametreler

Navigator.push(context, MaterialPageRoute(builder:(context) => MyPage()) ) → Future // isimlendirilmemiş sayfayı ekrana basar

örnek uygulama

navigator-push-simple
 

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: HomePage(),
      onGenerateRoute: (RouteSettings settings) {
        switch (settings.name) {
          case '/':
            return SlideRightRoute(widget:HomePage());
            break;
          case '/second':
            return SlideRightRoute(widget:SecondHome());
            break;
        }
      },
    ),
  );
}
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
      ),
      body: new Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.pushNamed(context, '/second');
          },
          child: Text('Second Home'),
        ),
      ),
    );
  }
}
class SecondHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Second Home'),
      ),
      body: new Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.pop(context);
          },
          child: Text('Go Back'),
        ),
      ),
    );
  }
}

class SlideRightRoute extends PageRouteBuilder {
  final Widget widget;
  AppSlideRightRoute({this.widget})
      : super(
    pageBuilder: (BuildContext context, Animation animation,
        Animation secondaryAnimation) {
      return widget;
    },
    transitionsBuilder: (BuildContext context,
        Animation animation,
        Animation secondaryAnimation,
        Widget child) {
      return new SlideTransition(
        position: new Tween(
          begin: const Offset(1.0, 0.0),
          end: Offset.zero,
        ).animate(animation),
        child: child,
      );
    },
  );
}

Bir cevap yazın

KAPAT
%d blogcu bunu beğendi: