Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:page_transition/page_transition.dart';
- import 'package:mosque/api/api_mosque.dart';
- import 'package:mosque/main.dart';
- class UpdateScreen extends StatefulWidget {
- final String idUpdate;
- final String nrpUpdate;
- final String namaUpdate;
- final String emailUpdate;
- final String jurusanUpdate;
- final String imageUpdate;
- UpdateScreen({
- this.idUpdate,
- this.nrpUpdate,
- this.namaUpdate,
- this.emailUpdate,
- this.jurusanUpdate,
- this.imageUpdate,
- });
- @override
- _UpdateScreenState createState() => _UpdateScreenState();
- }
- class _UpdateScreenState extends State<UpdateScreen> {
- final _scaffoldKey = GlobalKey<ScaffoldState>();
- bool _isLoadingButton = false;
- ApiHelper api = ApiHelper();
- File _image;
- TextEditingController _txtId;
- TextEditingController _txtNRP;
- TextEditingController _txtNama;
- TextEditingController _txtEmail;
- TextEditingController _txtJurusan;
- @override
- void initState() {
- _txtId = TextEditingController(text: "${widget.idUpdate}");
- _txtNRP = TextEditingController(text: "${widget.nrpUpdate}");
- _txtNama = TextEditingController(text: "${widget.namaUpdate}");
- _txtEmail = TextEditingController(text: "${widget.emailUpdate}");
- _txtJurusan = TextEditingController(text: "${widget.jurusanUpdate}");
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- key: _scaffoldKey,
- appBar: AppBar(
- actions: <Widget>[
- _isLoadingButton
- ? _loadingIndicator()
- : IconButton(
- icon: Icon(
- Icons.check_box,
- color: Colors.white,
- size: 32,
- ),
- onPressed: () {
- _validateTextField();
- },
- )
- ],
- leading: IconButton(
- icon: Icon(Icons.arrow_left),
- onPressed: () => Navigator.pop(context, false),
- ),
- centerTitle: true,
- title: Text('Update ${widget.namaUpdate}'),
- ),
- body: Container(
- child: SingleChildScrollView(
- scrollDirection: Axis.vertical,
- padding: EdgeInsets.all(20),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: <Widget>[
- Column(
- children: <Widget>[
- Text('Its Using Image Network'),
- CircleAvatar(
- radius: 70,
- backgroundImage: NetworkImage(
- '${Urls.BASE_API_IMAGE}/${widget.imageUpdate}'),
- ),
- ],
- ),
- Column(
- children: <Widget>[
- Text('im want this using image.file()'),
- CircleAvatar(
- radius: 70,
- backgroundImage: NetworkImage(
- '${Urls.BASE_API_IMAGE}/${widget.imageUpdate}'),
- ),
- ],
- ),
- ],
- ),
- TextFormField(
- readOnly: true,
- controller: _txtId,
- decoration: new InputDecoration(
- labelText: "Enter ID",
- fillColor: Colors.white,
- ),
- keyboardType: TextInputType.phone,
- ),
- TextFormField(
- autofocus: true,
- maxLength: 9,
- controller: _txtNRP,
- decoration: new InputDecoration(
- labelText: "Enter NRP",
- fillColor: Colors.white,
- ),
- keyboardType: TextInputType.phone,
- ),
- TextFormField(
- controller: _txtNama,
- decoration: new InputDecoration(
- labelText: "Enter Name",
- fillColor: Colors.white,
- ),
- keyboardType: TextInputType.text,
- ),
- TextFormField(
- controller: _txtEmail,
- decoration: new InputDecoration(
- labelText: "Enter Email",
- fillColor: Colors.white,
- ),
- keyboardType: TextInputType.emailAddress,
- ),
- TextFormField(
- controller: _txtJurusan,
- decoration: new InputDecoration(
- labelText: "Enter Jurusan",
- fillColor: Colors.white,
- ),
- keyboardType: TextInputType.text,
- ),
- ],
- ),
- ),
- ),
- );
- }
- Widget _loadingIndicator() {
- return Align(
- alignment: Alignment.center,
- child: CircularProgressIndicator(),
- );
- }
- void _validateTextField() async {
- if (_txtNRP.text == widget.nrpUpdate &&
- _txtNama.text == widget.namaUpdate &&
- _txtEmail.text == widget.emailUpdate &&
- _txtJurusan.text == widget.jurusanUpdate) {
- _showSnackBar(context, 'Data Tidak Boleh Sama', Colors.red);
- } else {
- _updateRevisi();
- }
- }
- void _updateRevisi() async {
- final body = {
- "nrp": _txtNRP.text,
- "nama": _txtNama.text,
- "email": _txtEmail.text,
- "jurusan": _txtJurusan.text,
- "id": _txtId.text,
- };
- int update = await api.updateMahasiswaRevisi(CrudComponent.headers, body);
- if (update == 204) {
- Navigator.push(
- context,
- PageTransition(
- child: Welcome(), type: PageTransitionType.leftToRight));
- } else {
- _showSnackBar(context, "Failed Update ", Colors.red[800]);
- }
- }
- void _showSnackBar(BuildContext context, String message, Color color) {
- final snackBar = SnackBar(
- duration: Duration(seconds: 1),
- backgroundColor: color,
- content: Text(message),
- );
- _scaffoldKey.currentState.showSnackBar(snackBar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment