Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'listData.dart';
  3. import 'package:http/http.dart' as http;
  4. import 'dart:async';
  5. import 'dart:convert';
  6.  
  7. class GetDataPage extends StatefulWidget {
  8. static String tag = 'getdata-page';
  9. @override
  10. _GetDataPageState createState() => _GetDataPageState();
  11. }
  12.  
  13. class _GetDataPageState extends State<GetDataPage> {
  14. TextEditingController nouji = new TextEditingController();
  15. String msg = '';
  16.  
  17. Future<List> _caridata() async {
  18. var no = nouji.text;
  19. final response = await http.get(
  20. "http://192.168.5.33:8080/project/getdata/datauji/?no=${no}");
  21.  
  22. if (response.statusCode != 200) {
  23. print(response.statusCode);
  24. return null;
  25. } else {
  26. var datahasiluji = json.decode(response.body);
  27. if (datahasiluji["result"]["code"] == 400) {
  28. print(response.statusCode);
  29. setState(() {
  30. msg = datahasiluji["result"]["warning"];
  31. });
  32. } else {
  33. if (datahasiluji["result"]["code"] == 200) {
  34. Route route = MaterialPageRoute(builder: (context) => ListDataPage());
  35. Navigator.pushReplacement(context, route);
  36. } else {
  37. setState(() {
  38. msg = "Tidak memiliki akses kesini!";
  39. });
  40. }
  41. }
  42. }
  43. }
  44.  
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. body: Center(
  49. child: ListView(
  50. padding: EdgeInsets.only(top: 150.0, left: 24.0, right: 24.0),
  51. children: <Widget>[
  52. Hero(
  53. tag: 'Hero',
  54. child: CircleAvatar(
  55. backgroundColor: Colors.transparent,
  56. radius: 80.0,
  57. child: Image.asset('assets/img/logo.png',
  58. width: 150.0, height: 150),
  59. ),
  60. ),
  61. SizedBox(height: 25.0),
  62. TextFormField(
  63. controller: nouji,
  64. keyboardType: TextInputType.text,
  65. autofocus: false,
  66. decoration: InputDecoration(
  67. hintText: 'No.',
  68. contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
  69. border: OutlineInputBorder(
  70. borderRadius: BorderRadius.circular(32.0)),
  71. ),
  72. ),
  73. SizedBox(height: 35.0),
  74. RaisedButton(
  75. color: Colors.blue,
  76. shape: RoundedRectangleBorder(
  77. borderRadius: BorderRadius.circular(20.0)),
  78. elevation: 5.0,
  79. onPressed: () {
  80. _caridata();
  81. },
  82. child: Container(
  83. padding: EdgeInsets.all(10.0),
  84. child: Text(
  85. 'Cari data',
  86. style: TextStyle(
  87. color: Colors.white,
  88. fontWeight: FontWeight.bold,
  89. fontSize: 18.0),
  90. ),
  91. ),
  92. ),
  93. SizedBox(height: 15.0),
  94. Padding(
  95. padding: EdgeInsets.only(left: 10.0),
  96. child: Text(
  97. msg,
  98. style:
  99. TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
  100. ),
  101. ),
  102. ],
  103. ),
  104. ),
  105. );
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement