WORKING WITH FUNCTIONS IN FLUTTER

 Code as seen in video:

 

main.dart

import 'package:flutter/material.dart';
import 'package:lessons/widget_creator.dart';

class SecondPage extends StatelessWidget {
  const SecondPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Second Page"),
        leading: const Icon(
          Icons.star,
        ),
      ),
      body: Center(
        child: Column(
          children: [
            createHeaders("Second Page", "This is the second page"),
            const Text(
              "This is the body of the second page",
            ),
            ElevatedButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: const Text("Back to Main Page"),
            ),
          ],
        ),
      ),
    );
  }
}



widget_creator.dart

import 'package:flutter/material.dart';

Widget createHeaders(String title, String subTitle) {
  return Column(
    children: [
      Text(
        title,
        style: TextStyle(fontSize: 30.0),
      ),
      vSpacer(10.0),
      Text(
        subTitle,
        style: TextStyle(fontSize: 20.0),
      ),
    ],
  );
}

Widget createTextField(TextEditingController controller, String labelText,
    String hintText, IconData suffixIcon) {
  return TextField(
    controller: controller,
    style: const TextStyle(fontSize: 15.0),
    textAlign: TextAlign.center,
    decoration: InputDecoration(
      labelText: labelText,
      hintText: hintText,
      suffixIcon: Icon(suffixIcon),
      border: OutlineInputBorder(
        borderSide: const BorderSide(
          width: 1,
          color: Colors.blue,
        ),
        borderRadius: BorderRadius.circular(
          5.0,
        ),
      ),
    ),
  );
}

Widget vSpacer(double height) {
  return SizedBox(
    height: height,
  );
}



second_page.dart


import 'package:flutter/material.dart';
import 'package:lessons/widget_creator.dart';

class SecondPage extends StatelessWidget {
  const SecondPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Second Page"),
        leading: const Icon(
          Icons.star,
        ),
      ),
      body: Center(
        child: Column(
          children: [
            createHeaders("Second Page", "This is the second page"),
            const Text(
              "This is the body of the second page",
            ),
            ElevatedButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: const Text("Back to Main Page"),
            ),
          ],
        ),
      ),
    );
  }
}




No comments:

Post a Comment

UNITY2D: SPAWN ENEMIES RANDOMLY/DYNAMICALLY AT RUN TIME

 Code: player.cs using System . Collections ; using System . Collections . Generic ; using UnityEngine ; using UnityEngine . SceneManage...