Laporan Praktikum Aplikasi Mobile

Ahda Rindang Al-Amin

Laporan Praktikum 2

Setup Flutter Development, Stateless & Statefull Widget, Basic Widgets


Tujuan

Tujuan praktikum ini yaitu mahasiswa membuat menginstall lingkungan flutter development, stateless dan statefull widget dan basic widgets flutter :

  1. Mahasiswa mampu menyiapkan lingkungan development flutter seperti install sdk flutter, git, android SDK, IDE, dll
  2. Mahasiswa mampu membuat stateless dan statefull widget flutter
  3. Mahasiswa mampu membuat contoh widgets flutter

Langkah-Langkah
Setup Lingkungan Flutter Development

Software-software yang dibutuhkan untuk menjalankan flutter diantaranya:

Setelah software yang dibutuhkan lengkap, cek apakah lingkungan flutter development siap untuk digunakan dengan mengetikkan flutter doctor pada terminal.

Buat Project Flutter "hai"

Membuat project flutter bisa melalui terminal dengan mengetik flutter create nama_project pada direktori yang diinginkan. Disini nama project yang akan dibuat bernama "hai". Untuk menjalankannya, ketik cd hai, lalu flutter run

Agar lebih mudah, lanjutkan project di Visual Studio Code. tambahkan folder hai ke workspace.

Struktur Project Flutter
Stateless Widget

Stateless Widget merupakan widget yang data atau tampilannya tidak mengalami perubahan ketika sebuah state dijalankan, Widget ini bersifat statis atau tetap misalnya teks statis, logo aplikasi dll

import 'package:flutter/material.dart';
void main() {
  runApp(const MyStateless());
}

class MyStateless extends StatelessWidget {
  const MyStateless({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Stateless Widget"),
        ),
        body: const Center(
          child: Text("ini body"),
        ),
      ),
    );
  }
}
  • Output program
  • Statefull Widget

    Statefull Widget merupakan widget dinamis yang ketika sebuah state berubah maka tampilan UI juga berubah. contohnya ketika tombol diklik atau ditekan maka tombol berubah warna atau form input nilainya berubah.

    Contoh penggunaan statefull widget:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyStatefull());
    }
    
    class MyStatefull extends StatefulWidget {
      const MyStatefull({super.key});
    
      @override
      State<MyStatefull> createState() => _MyStatefullState();
    }
    
    class _MyStatefullState extends State<MyStatefull> {
      int _kelipatan = 0;
      void _kelipatanDua() {
        setState(() {
          _kelipatan += 2;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text("Statefull Widget"),
            ),
            body: Center(
              child: Container(
                width: 100,
                height: 100,
                color: Colors.amber,
                child: Column(
                  children: [
                    const Text("Kelipatan 2 : "),
                    Text(
                      '$_kelipatan',
                      style: Theme.of(context).textTheme.headlineMedium,
                    )
                  ],
                ),
              ),
            ),
            floatingActionButton: FloatingActionButton(
              onPressed: _kelipatanDua,
              tooltip: "Kelipatan 2",
              child: const Icon(Icons.add),
            ),
          ),
        );
      }
    }
  • Output program
  • Basic Widgets

    Tugas

    1. Buatlah tampilan widget secara vertical dan horizontal dengan menggunakan minimal 3 buah basic widget dalam 1 tampilan

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Latihan 1: Widget Layout'),
            ),
            body: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    width: double.infinity,
                    height: 100,
                    color: Colors.blueAccent,
                    child: const Center(
                      child: Text(
                        'Container',
                        style: TextStyle(color: Colors.white, fontSize: 18),
                      ),
                    ),
                  ),
                  const SizedBox(height: 20),
                  const Text(
                    'Susunan Horizontal:',
                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(height: 10),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Icon(
                        Icons.star,
                        color: Colors.amber,
                        size: 50.0,
                      ),
                      Text('Text Bintang'),
                      Icon(
                        Icons.favorite,
                        color: Colors.red,
                        size: 50.0,
                      ),
                      Text('Text Hati'),
                    ],
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
  • Output:
  • 2. Buatlah tampilan yang berisi informasi profile kalian (foto, nama, nim, Alamat, nomor handphone, jurusan) dengan mengimplementasikan seluruh basic widget yang ada pada modul praktikum ini.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Profil Mahasiswa'),
            ),
            body: SingleChildScrollView(
              child: Center(
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      const CircleAvatar(
                        radius: 80,
                        backgroundImage: AssetImage(
                          'assets/images/foto.jpg',
                        ),
                      ),
                      const SizedBox(height: 20),
    
                      
                      const Text(
                        'Ahda Rindang Al-Amin',
                        style: TextStyle(
                          fontSize: 24.0,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 5),
                      const Text(
                        '2311531003',
                        style: TextStyle(
                          fontSize: 16.0,
                          color: Colors.grey,
                        ),
                      ),
                      const SizedBox(height: 30),
    
                      Container(
                        padding: const EdgeInsets.all(16.0),
                        decoration: BoxDecoration(
                          color: Colors.grey[200],
                          borderRadius: BorderRadius.circular(10),
                        ),
                        child: const Column(
                          children: [
                            InfoRow(
                              icon: Icons.school,
                              text: 'Informatika',
                            ),
                            SizedBox(height: 15),
                            InfoRow(
                              icon: Icons.home,
                              text: 'Pauh, Padang',
                            ),
                            SizedBox(height: 15),
                            InfoRow(
                              icon: Icons.phone,
                              text: '0812-7347-1093',
                            ),
                          ],
                        ),
                      ),
                      const SizedBox(height: 30),
    
    
                      ElevatedButton(
                        onPressed: () {
                          print("Tombol 'Hubungi' ditekan!");
                        },
                        style: ElevatedButton.styleFrom(
                          backgroundColor: Colors.blueAccent,
                          foregroundColor: Colors.white,
                          padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 15),
                        ),
                        child: const Text('Hubungi'),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      }
    }
    
    class InfoRow extends StatelessWidget {
      final IconData icon;
      final String text;
    
      const InfoRow({
        super.key,
        required this.icon,
        required this.text,
      });
    
      @override
      Widget build(BuildContext context) {
        return Row(
          children: [
            Icon(icon, color: Colors.blueAccent),
            const SizedBox(width: 15),
            Text(text, style: const TextStyle(fontSize: 16)),
          ],
        );
      }
    }
  • Output:

  • Tinggalkan Komentar


    Komentar

    Belum ada komentar.


    Contact

    Send Me A Message