SHARE
TWEET

Untitled

geoBadita Jan 21st, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:first_laboratory/service/TShirtService.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4.  
  5. import 'domain/TShirt.dart';
  6.  
  7. class AddEdit extends StatefulWidget {
  8.  
  9.  
  10.   final TShirt t;
  11.   final bool mode;
  12.  
  13.   const AddEdit(this.t, this.mode);
  14.  
  15.   @override
  16.   State createState() {
  17.     return AddEditState(t, mode);
  18.   }
  19. }
  20.  
  21. class AddEditState extends State<AddEdit>{
  22.   TShirt t;
  23.   bool edit;
  24.   TextField descriptionText;
  25.   TextField countText;
  26.   TextEditingController descriptionController = TextEditingController();
  27.   TextEditingController countController = TextEditingController();
  28.   RaisedButton addEditButton;
  29.   TShirtService service = TShirtService();
  30.   BuildContext context;
  31.   State parent;
  32.  
  33.   AddEditState(TShirt t, bool mode) {
  34.     this.t = t;
  35.     this.edit = mode;
  36.     descriptionText = TextField(
  37.       controller: descriptionController,
  38.     );
  39.     countText = TextField(
  40.       controller: countController,
  41.     );
  42.     descriptionController.text = t.mealDescription;
  43.     countController.text = t.mealCount.toString();
  44.     if (edit) {
  45.       addEditButton = RaisedButton(
  46.         onPressed: editAnnouncement,
  47.         child: Text("Edit"),
  48.       );
  49.     } else {
  50.       addEditButton = RaisedButton(
  51.         onPressed: addAnnouncement,
  52.         child: Text("Add"),
  53.       );
  54.     }
  55.   }
  56.  
  57.   Widget _buildTiles(TShirt root) {
  58.     return Scaffold(
  59.         body: Container(
  60.             alignment: Alignment.center,
  61.             child: Column(
  62.               crossAxisAlignment: CrossAxisAlignment.center,
  63.               mainAxisAlignment: MainAxisAlignment.center,
  64.               children: <Widget>[descriptionText, countText, addEditButton],
  65.             )));
  66.   }
  67.  
  68.   @override
  69.   Widget build(BuildContext context) {
  70.     this.context = context;
  71.     return _buildTiles(t);
  72.   }
  73.  
  74.   addAnnouncement() {
  75.  
  76.     TShirt t = TShirt.withoutID(
  77.         descriptionController.text,
  78.         int.parse(countController.text)
  79.         );
  80.     Navigator.pop(context, t);
  81.   }
  82.  
  83.   editAnnouncement() {
  84.  
  85.     TShirt t = TShirt(
  86.         this.t.id,
  87.         descriptionController.text,
  88.         int.parse(countController.text),);
  89.  
  90.     print(t);
  91.     Navigator.pop(context,t);
  92.   }
  93.  
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top