Professional Documents
Culture Documents
SENSOR QR CODE
OLEH:
I Made Deon Virgananta
1915051035
PTI 4A
TEKNIK INFORMATIKA
FAKULTAS TEKNIK DAN KEJURUAN
UNIVERSITAS PENDIDIKAN GANESHA
SINGARAJA
2020/2021
Link GitHub: https://github.com/deon6-glitch/QrScannerAndWebView1.git
Tampilan :
Source Code :
Home_Screen.dart
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'profile.dart';
import 'webview_screen.dart';
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
String kode = "";
var getKode;
Future scanBarcode() async {
getKode = await BarcodeScanner.scan();
setState(() {
kode = getKode.rawContent;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black45,
appBar: AppBar(
leading: Icon(Icons.dashboard),
title: Text("QR SCANNER"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.person_outline),
color: Colors.white,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyApp()),
);
},
)
],
centerTitle: true,
backgroundColor: Colors.blueAccent,
elevation: 0.0,
),
body: Column(
children: [
Container(
height: 10,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(16.0),
bottomRight: Radius.circular(16.0),
),
),
),
SizedBox(
height: 10.0,
),
Image.asset("images/qrscan.jpg",
height: 400,
width: 300,),
SizedBox(
height: 10.0,
),
// ignore: deprecated_member_use
FlatButton(
onPressed: () {
scanBarcode();
},
child: Container(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text(
"Scan!",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w300,
fontSize: 16,
),
),
),
),
decoration: BoxDecoration(
color: Colors.blueAccent[400],
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
),
),
// ignore: deprecated_member_use
FlatButton(
onPressed: kode == ""
? () {}
: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WebScreen(kode),
),
);
},
child: Container(
width: double.infinity,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: kode == ""
? Text(
"Result",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w300,
fontSize: 16,
),
)
: Text(
kode,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w300,
fontSize: 16,
),
),
),
),
decoration: BoxDecoration(
color: Colors.greenAccent[400],
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
),
),
],
),
);
}
}
Main.dart
import 'package:flutter/material.dart';
import 'home_screen.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
Profile.dart :
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:qr_scanner/home_screen.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black38,
appBar: AppBar(
backgroundColor: Colors.green,
title: Text('Profil'),
centerTitle: true,
leading: Icon(Icons.menu),
),
body: Center(
child: Column(
children: <Widget>[
Picture(),
Name(),
NIM(),
Container(
padding: EdgeInsets.only(top: 20),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Col
or>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed))
return Colors.blueAccent;
return Colors
.tealAccent; // Use the component's default.
},
),
),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder:
(context) => HomeScreen()));
},
child: Text(
'BACK',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w500,
color: Colors.black),
),
),
)
],
),
),
),
);
}
}
class Picture extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 290,
height: 250,
margin: const EdgeInsets.only(top: 45.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
image: DecorationImage(
image: AssetImage('images/deon.jpg'),
fit: BoxFit.cover,
),
),
);
}
}
class Name extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text(
"I Made Deon Virgananta",
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
margin: const EdgeInsets.only(top: 40.0),
);
}
}
class NIM extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text(
"1915051035",
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
margin: const EdgeInsets.only(top: 10.0),
);
}
}
Webview_screen:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebScreen extends StatelessWidget {
final String url;
WebScreen(this.url);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[50],
appBar: AppBar(
title: Text(url),
centerTitle: true,
backgroundColor: Colors.lightBlueAccent,
),
body: WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
),
);
}
}