0% found this document useful (0 votes)
86 views12 pages

Laporan Uts Flutter Dan Android Studio - 1815051088

This document is a report on a Flutter and Android Studio exam submitted to fulfill the requirements of a Mobile Programming course. It discusses the splash screen, shopping cart, item input, and item display screens created in the exam. It also includes the source code for the main file, splash screen, dashboard, cart model, product list, and add new item screens. The Github link provided contains the full source code for the shopping bag application created for the exam.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views12 pages

Laporan Uts Flutter Dan Android Studio - 1815051088

This document is a report on a Flutter and Android Studio exam submitted to fulfill the requirements of a Mobile Programming course. It discusses the splash screen, shopping cart, item input, and item display screens created in the exam. It also includes the source code for the main file, splash screen, dashboard, cart model, product list, and add new item screens. The Github link provided contains the full source code for the shopping bag application created for the exam.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

LAPORAN UTS FLUTTER DAN ANDROID STUDIO

Tugas Laporan

Diajukan Untuk Memenuhi Tugas Mata Kuliah Pemrograman Mobile Dosen

Pengampu : I Ketut Resika Arthana, S.T.,M.Kom.

Disusun Oleh :

Mario Martin Da Silva


1815051088

JURUSAN PENDIDIKAN TEKNIK INFORMATIKA FAKULTAS

TEKNIK DAN KEJURUAN

UNIVERSITAS PENDIDIKAN GANESHA

SINGARAJA

2020
Tampilan Splash Screen
2. Tampilan Daftar Belanjaan (Cart)
3. Tampilan Input data Belanjaan
4. Tampilan Hasil Input Data Belanjaan
SOURCE CODE :

1. Main.dart
import 'package:shoppingbag/splashscreen.dart';
import 'package:flutter/material.dart';

import './components/dashboard.dart';
import './components/product_lists.dart';
import './components/add_new_item.dart';
import './models/cart.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Shopping Bag",
theme: ThemeData(
primarySwatch: Colors.blue,
accentColor: Colors.blue,
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(fontSize: 15, fontWeight: FontWeight.bold))),
home: SplashScreen(),
);
}
}

class Home extends StatefulWidget {


@override
_HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {


final List<Cart> _carts = [
Cart(id: 'MR1', title: 'Baju Batik', harga: 15000, qty: 1),
Cart(id: 'MR2', title: 'Sabun Mandi', harga: 17000, qty: 2),
];

void _openModal(BuildContext context) {


showModalBottomSheet(
context: context,
builder: (_) {
return AddNewItem(_addNewItem);
});
}

void _addNewItem(String title, double harga, int qty) {


final newItem = Cart(id: DateTime.now().toString(), title: title, harga: harga,
qty: qty);
setState(() {
_carts.add(newItem);
});
}

void _resetCarts() {
setState(() {
_carts.clear();
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Daftar Belanjaan"),
actions: <Widget>[
FlatButton(child: Icon(Icons.clear, color: Colors.white,), onPressed: () =>
_resetCarts(),)
],
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Dashboard(_carts),
ProductList(_carts),
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _openModal(context),
),
);
}
}

2. Splashscreen.dart
import 'package:flutter/material.dart';
import 'dart:async';

import 'main.dart';

class SplashScreen extends StatefulWidget{

_SplashScreen createState() => _SplashScreen();

class _SplashScreen extends State<SplashScreen>{

void initState(){
super.initState();
splashscreenStart();
}

splashscreenStart() async{
var duration = const Duration(seconds: 3);
return Timer(duration, (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Home()),

);
});
}

@override
Widget build(BuildContext context){

return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[

Icon(
Icons.school,
size: 100.0,
color: Colors.white,
),

SizedBox(height: 24.0,),

Text("UNDIKSHA",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 30.0,
),
),

],
),
),
);
}

}
3. dashboard.dart
import 'package:flutter/material.dart';
import '../models/cart.dart';

class Dashboard extends StatelessWidget {


final List<Cart> _listCart;
Dashboard(this._listCart);

int get totalItem {


return _listCart.fold(0, (sum, item) {
return sum += item.qty;
});
}

double get totalPrice {


return _listCart.fold(0, (sum, item) {
return sum += item.harga;
});
}

@override
Widget build(BuildContext context) {
return Card(
elevation: 6,
margin: EdgeInsets.all(10),
child: Padding(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Column(children: <Widget>[
Text("Total Item", style: Theme.of(context).textTheme.title,),
SizedBox(height: 4,),
Text(totalItem.toString() + " pcs", style: TextStyle(fontSize: 25,
fontWeight: FontWeight.bold),),
],),
Column(children: <Widget>[
Text("Total Belanja", style: Theme.of(context).textTheme.title,),
SizedBox(height: 4,),
Text(totalPrice.toStringAsFixed(0), style: TextStyle(fontSize: 25,
fontWeight: FontWeight.bold),)
],)
],
),
),
);
}
}
4. cart.dart
import 'package:flutter/foundation.dart';

class Cart {
final String id;
final String title;
final double harga;
final int qty;

Cart({
@required this.id,
@required this.title,
@required this.harga,
@required this.qty
});
}

5. product_lists.dart
import 'package:flutter/material.dart';
import '../models/cart.dart';

class ProductList extends StatelessWidget {


final List<Cart> carts;

ProductList(this.carts);

@override
Widget build(BuildContext context) {
return Container(
height: 400,
child: carts.isEmpty ? Column(children: <Widget>[
Text(
"No Transaction Data",
style: Theme.of(context).textTheme.title,
),
],): ListView.builder(
itemBuilder: (context, index) {
return Card(
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).primaryColor, width: 2)),
child: Text(
carts[index].qty.toString(),
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
fontSize: 20
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(carts[index].title, style:
Theme.of(context).textTheme.title,),
Text('Harga: Rp' + carts[index].harga.toStringAsFixed(0), style:
TextStyle(fontSize: 12, color: Colors.grey),),
],
)
],
),
);
},
itemCount: carts.length,
),
);
}
}

6. add_new_item.dart
import 'package:flutter/material.dart';

class AddNewItem extends StatefulWidget {


final Function addNew;
AddNewItem(this.addNew);

@override
_AddNewItemState createState() => _AddNewItemState();
}

class _AddNewItemState extends State<AddNewItem> {


final titleController = TextEditingController();
final hargaController = TextEditingController();
final qtyController = TextEditingController();

void saveNewItem() {
final title = titleController.text;
final harga = hargaController.text;
final qty = int.parse(qtyController.text);

if (title.isEmpty || harga.isEmpty || qty <= 0) {


return;
}
widget.addNew(title, double.parse(harga), qty);
Navigator.of(context).pop();
}

@override
Widget build(BuildContext context) {
return Card(
child: Container(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Nama Barang'),
controller: titleController,
),
TextField(
decoration: InputDecoration(labelText: 'Harga'),
controller: hargaController,
keyboardType: TextInputType.number,
),
TextField(
decoration: InputDecoration(labelText: 'Qty'),
controller: qtyController,
keyboardType: TextInputType.number,
),
FlatButton(
child: Text('Tambah'),
onPressed: saveNewItem,
textColor: Colors.blueAccent,
)
],
),
),
);
}
}

Link Github :
https://github.com/mariomartin134/UTS-Flutter-Shopping-Bag.git

Link YouTube :
https://www.youtube.com/watch?v=DrAQhuF5UPA

You might also like