flutter push code example

Example 1: flutter push route

// Within the `FirstRoute` widget
onPressed: () {
  Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => SecondRoute()),
  );
}

Example 2: flutter not navigating to a new screen

Wrap the new screen with a Scaffold widget

//navigation page
return GestureDetector(
  onTap: () {
    Navigator.push(
    context,
    MaterialPageRoute(
    	builder: (context) => DestinationScreen()),
  );
}

// new screen page
class _DestinationScreenState extends State<DestinationScreen> {
  
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

Example 3: pusher connect flutter

pusher_websocket_flutter: ^0.1.1
 
 try {
      await Pusher.init(
          "Appid",
          PusherOptions(
            auth: PusherAuth(url, headers: {
              'Content-Type': 'application/json',
              'Authorization': 'Bearer ' + token
            }),
            cluster: "ap2",
            encrypted: true,
          ),
          enableLogging: true);
    } on PlatformException catch (e) {
      print(e.message);
    }

    Pusher.connect(onConnectionStateChange: (x) async {
      print(x.currentState);
    }, onError: (x) {
      debugPrint("Error: ${x.exception}");
    });
    channel = await Pusher.subscribe(
        'private-message-1'}');
    channel.bind('newmessage', (onEvent) {
	print(onEvent.data)

    });

Tags:

Dart Example