Jaagdish47

4A. Designing the mobile app to implement routing?

Nov 24th, 2024 (edited)
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.43 KB | Source Code | 0 0
  1. //4A. Designing the mobile app to implement routing?
  2. import 'package:flutter/material.dart';
  3.  
  4. void main() {
  5.   runApp(const MaterialApp(
  6.     home: MyApp(),
  7.   ));
  8. }
  9.  
  10. class MyApp extends StatelessWidget {
  11.   const MyApp({Key? key}) : super(key: key);
  12.  
  13.   @override
  14.   Widget build(BuildContext context) {
  15.     TextEditingController name = TextEditingController();
  16.     TextEditingController id = TextEditingController();
  17.     TextEditingController semester = TextEditingController();
  18.     TextEditingController dept = TextEditingController();
  19.     TextEditingController city = TextEditingController();
  20.  
  21.     return Scaffold(
  22.       appBar: AppBar(
  23.         title: const Text("User Info"),
  24.         centerTitle: true,
  25.       ), // AppBar
  26.       body: Padding(
  27.         padding: const EdgeInsets.all(10.0),
  28.         child: Column(
  29.           children: [
  30.             const SizedBox(height: 10),
  31.             TextField(
  32.               controller: name,
  33.               decoration: InputDecoration(
  34.                 labelText: "Enter your name",
  35.                 border: OutlineInputBorder(
  36.                   borderRadius: BorderRadius.circular(15),
  37.                 ), // OutlineInputBorder
  38.               ), // InputDecoration
  39.             ), // TextField
  40.             const SizedBox(height: 10),
  41.             TextField(
  42.               controller: id,
  43.               decoration: InputDecoration(
  44.                 labelText: "Enter your ID",
  45.                 border: OutlineInputBorder(
  46.                   borderRadius: BorderRadius.circular(15),
  47.                 ), // OutlineInputBorder
  48.               ), // InputDecoration
  49.             ), // TextField
  50.             const SizedBox(height: 10),
  51.             TextField(
  52.               controller: semester,
  53.               decoration: InputDecoration(
  54.                 labelText: "Enter your Semester",
  55.                 border: OutlineInputBorder(
  56.                   borderRadius: BorderRadius.circular(15),
  57.                 ), // OutlineInputBorder
  58.               ), // InputDecoration
  59.             ), // TextField
  60.             const SizedBox(height: 10),
  61.             TextField(
  62.               controller: dept,
  63.               decoration: InputDecoration(
  64.                 labelText: "Enter your Department",
  65.                 border: OutlineInputBorder(
  66.                   borderRadius: BorderRadius.circular(15),
  67.                 ), // OutlineInputBorder
  68.               ), // InputDecoration
  69.             ), // TextField
  70.             const SizedBox(height: 10),
  71.             TextField(
  72.               controller: city,
  73.               decoration: InputDecoration(
  74.                 labelText: "Enter your City",
  75.                 border: OutlineInputBorder(
  76.                   borderRadius: BorderRadius.circular(15),
  77.                 ), // OutlineInputBorder
  78.               ), // InputDecoration
  79.             ), // TextField
  80.             const SizedBox(height: 20),
  81.             ElevatedButton(
  82.               onPressed: () {
  83.                 Navigator.push(
  84.                   context,
  85.                   MaterialPageRoute(
  86.                     builder: (context) => NextScreen(
  87.                       name: name.text,
  88.                       id: id.text,
  89.                       semester: semester.text,
  90.                       dept: dept.text,
  91.                       city: city.text,
  92.                     ),
  93.                   ),
  94.                 );
  95.               },
  96.               child: const Text("Continue"),
  97.             ), // ElevatedButton
  98.           ],
  99.         ), // Column
  100.       ), // Padding
  101.     ); // Scaffold
  102.   }
  103. }
  104.  
  105. class NextScreen extends StatelessWidget {
  106.   final String name;
  107.   final String id;
  108.   final String semester;
  109.   final String dept;
  110.   final String city;
  111.  
  112.   const NextScreen({
  113.     Key? key,
  114.     required this.name,
  115.     required this.id,
  116.     required this.semester,
  117.     required this.dept,
  118.     required this.city,
  119.   }) : super(key: key);
  120.  
  121.   @override
  122.   Widget build(BuildContext context) {
  123.     return Scaffold(
  124.       appBar: AppBar(
  125.         title: const Text("Details"),
  126.       ), // AppBar
  127.       body: Padding(
  128.         padding: const EdgeInsets.all(10.0),
  129.         child: Column(
  130.           crossAxisAlignment: CrossAxisAlignment.start,
  131.           children: [
  132.             Text("Name: $name"),
  133.             Text("ID: $id"),
  134.             Text("Semester: $semester"),
  135.             Text("Department: $dept"),
  136.             Text("City: $city"),
  137.           ],
  138.         ), // Column
  139.       ), // Padding
  140.     ); // Scaffold
  141.   }
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment