Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'listData.dart';
- import 'package:http/http.dart' as http;
- import 'dart:async';
- import 'dart:convert';
- class GetDataPage extends StatefulWidget {
- static String tag = 'getdata-page';
- @override
- _GetDataPageState createState() => _GetDataPageState();
- }
- class _GetDataPageState extends State<GetDataPage> {
- TextEditingController nouji = new TextEditingController();
- String msg = '';
- Future<List> _caridata() async {
- var no = nouji.text;
- final response = await http.get(
- "http://192.168.5.33:8080/project/getdata/datauji/?no=${no}");
- if (response.statusCode != 200) {
- print(response.statusCode);
- return null;
- } else {
- var datahasiluji = json.decode(response.body);
- if (datahasiluji["result"]["code"] == 400) {
- print(response.statusCode);
- setState(() {
- msg = datahasiluji["result"]["warning"];
- });
- } else {
- if (datahasiluji["result"]["code"] == 200) {
- Route route = MaterialPageRoute(builder: (context) => ListDataPage());
- Navigator.pushReplacement(context, route);
- } else {
- setState(() {
- msg = "Tidak memiliki akses kesini!";
- });
- }
- }
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Center(
- child: ListView(
- padding: EdgeInsets.only(top: 150.0, left: 24.0, right: 24.0),
- children: <Widget>[
- Hero(
- tag: 'Hero',
- child: CircleAvatar(
- backgroundColor: Colors.transparent,
- radius: 80.0,
- child: Image.asset('assets/img/logo.png',
- width: 150.0, height: 150),
- ),
- ),
- SizedBox(height: 25.0),
- TextFormField(
- controller: nouji,
- keyboardType: TextInputType.text,
- autofocus: false,
- decoration: InputDecoration(
- hintText: 'No.',
- contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(32.0)),
- ),
- ),
- SizedBox(height: 35.0),
- RaisedButton(
- color: Colors.blue,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(20.0)),
- elevation: 5.0,
- onPressed: () {
- _caridata();
- },
- child: Container(
- padding: EdgeInsets.all(10.0),
- child: Text(
- 'Cari data',
- style: TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.bold,
- fontSize: 18.0),
- ),
- ),
- ),
- SizedBox(height: 15.0),
- Padding(
- padding: EdgeInsets.only(left: 10.0),
- child: Text(
- msg,
- style:
- TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement