Flutter PHP

Create Flutter Logout Screen Using PHP MySQL

In this tutorial we shall discuss how to create the logout screen of out flutter app.

  1. Create The Logout Screen
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LogoutScreen extends StatefulWidget {
  const LogoutScreen({super.key});

  State<LogoutScreen> createState() => _LogoutScreenState();

class _LogoutScreenState extends State<LogoutScreen> {


  Widget build(BuildContext context) {
    return const Placeholder();

2. Now Create The Asynchronous Function

import 'package:shared_preferences/shared_preferences.dart'; 

import '../Home/Home.dart';

Future<void> _logoutUser() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove('email');
    await prefs.remove('password');
    // Redirect to Home screen
      MaterialPageRoute(builder: (context) => Home()),

3. Now Call The Logout Function On Page Load

  void initState() {


Leave a Reply

Your email address will not be published. Required fields are marked *