Mobile Programming - Hello World Part II
Mobile Programming
Hi guys.
Kembali lagi bersama saya Fahriza Ramadhan.
Kali ini saya akan menjelaskan sourcecode tentang Mobile Programming.
Yuk langsung kita lihat !!!
Langkah Kerja
1. Pertama-tama buka aplikasi Visual Studio Code-nya.
2. Kemudian klik View - Command Pallate - Flutter : New Application Project, kemudian tentukan folder dimana kita ingin menyimpannya, lalu beri nama file nya tadi.
3. Tunggu proses build up nya selesai.
4. Jika sudah, komentari seluruh script di file test > widget_test.dart, lalu berpindah ke lib > main.dart. Jika sudah, hapus sourcecode nya dan ketikkan sourcecode dibawah ini.
import 'package:flutter/material.dart';
class Tampilan extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Sample Code'),
),
body: Center(child: Text('Hallo')),
backgroundColor: Colors.blueGrey.shade200,
));
}
}
void main() {
runApp(Tampilan());
}
5. Kemudian jalankan dengan klik Run - Start Debugginh. Lalu tunggu prosesnya.
6. Berikut adalah tampilan hasil di smartphone yang saya hubungkan dengan aplikasi Vysor.
7. Selanjutnya kita ubah sourcecode nya menjadi seperti ini.
import 'package:flutter/material.dart';
class MyAppBar extends StatelessWidget {
const MyAppBar({required this.title, Key? key}) : super(key: key);
// Fields in a Widget subclass are always marked "final".
final Widget title;
@override
Widget build(BuildContext context) {
return Container(
height: 56.0, // in logical pixels
padding: const EdgeInsets.symmetric(horizontal: 8.0),
decoration: BoxDecoration(color: Colors.blue[500]),
// Row is a horizontal, linear layout.
child: Row(
// <Widget> is the type of items in the list.
children: [
const IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null, // null disables the button
),
// Expanded expands its child
// to fill the available space.
Expanded(
child: title,
),
const IconButton(
icon: Icon(Icons.search),
// tooltip: 'Search',
onPressed: null,
),
],
),
);
}
}
class MyScaffold extends StatelessWidget {
const MyScaffold({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// Material is a conceptual piece
// of paper on which the UI appears.
return Material(
// Column is a vertical, linear layout.
child: Column(
children: [
MyAppBar(
title: Text(
'Selamat Datang !!!',
style: Theme.of(context) //
.primaryTextTheme
.headline6,
),
),
const Expanded(
child: Center(
child: Text('Hi Namaku Riza!'),
),
),
],
),
);
}
}
void main() {
runApp(
const MaterialApp(
title: 'Tugas_Modul3', // used by the OS task switcher
home: SafeArea(
child: MyScaffold(),
),
),
);
}
8. Setelah itu run kan dan tunggu proses nya.
9. Berikut hasil nya akan nampak di smartphone kita. Disini saya tampilkan ke layar menggunakan aplikasi Vysor.
Saya rasa cukup segini dulu penjelasan dari saya.
Saya akhiri
Assalamualaikum Wr. Wb.

















Komentar
Posting Komentar