Untitled
unknown
plain_text
4 years ago
12 kB
4
Indexable
import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:image_picker/image_picker.dart'; //image tools import 'package:file/file.dart'; class createPet extends StatefulWidget{ @override _createPet createState() => _createPet(); } class _createPet extends State<createPet> { final _formKey = GlobalKey<FormState>(); String petName = ""; String bio = ""; String birthYear = ""; String breed = ""; String sex = ""; List<String> sexType = ["female", "male", "none"]; final ImagePicker _picker = ImagePicker(); _imgFromCamera() async { final ImagePicker _picker = ImagePicker(); } _imgFromGallery() async { final XFile? image = await _picker.pickImage(source: ImageSource.gallery); } @override void initState(){ super.initState(); } void buttonPressed() { print(petName+"\n"+bio+"\n"+birthYear+"\n"+breed+"\n"+sex+"\n"); } void pageDirection() { Navigator.pushNamed(context, '/homePage'); } void textPressed() {} @override Widget build (BuildContext context){ return Scaffold( body: Padding( padding: const EdgeInsets.all(16.0), child : SingleChildScrollView( child: Form( key: _formKey, child: Column( children: [ SizedBox(height: 10,), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(8.0), child: CircleAvatar( backgroundColor: Colors.white, child: ClipOval( child: onPressed ) child: GestureDetector( onTap: _imgFromGallery, ), ), ), Padding( padding: const EdgeInsets.all(16.0), child: CircleAvatar( backgroundColor: Colors.white, child: ClipOval( child: Image.network('https://i.ebayimg.com/images/g/WIgAAOSwal5YIJHv/s-l300.jpg'), ), radius: 60, ), ), ] ), ] ), SizedBox(height: 10,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: TextFormField( decoration: InputDecoration( fillColor: Colors.grey, filled: true, hintText: "Pet's Name", border: OutlineInputBorder( borderSide: BorderSide( color: Colors.black, ), borderRadius: BorderRadius.all(Radius.circular(30)), ), ), keyboardType: TextInputType.text, validator: (value) { if(value==null){ return 'Pet name field cannot be empty!'; } else{ String trimmedValue = value.trim(); if(trimmedValue.isEmpty){ return 'Pet name field cannot be empty'; } } return null; }, onSaved: (value){ if(value != null){ petName = value; } }, ), ), ], ), SizedBox(height : 10,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: TextFormField( decoration: InputDecoration( fillColor: Colors.grey, filled: true, hintText: "Biography", border: OutlineInputBorder( borderSide: BorderSide( color: Colors.black, ), borderRadius: BorderRadius.all(Radius.circular(30)), ), ), keyboardType: TextInputType.multiline, onSaved: (value){ if(value != null){ bio = value; } }, ), ), ], ), SizedBox(height : 10,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: TextFormField( decoration: InputDecoration( fillColor: Colors.grey, filled: true, hintText: "Birth Year", border: OutlineInputBorder( borderSide: BorderSide( color: Colors.black, ), borderRadius: BorderRadius.all(Radius.circular(30)), ), ), keyboardType: TextInputType.text, onSaved: (value){ if(value != null){ birthYear = value; } }, ), ), ], ), SizedBox(height : 10,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: TextFormField( decoration: InputDecoration( fillColor: Colors.grey, filled: true, hintText: "Breed", border: OutlineInputBorder( borderSide: BorderSide( color: Colors.black, ), borderRadius: BorderRadius.all(Radius.circular(30)), ), ), keyboardType: TextInputType.text, onSaved: (value){ if(value != null){ breed = value; } }, ), ), ], ), SizedBox(height : 10,), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: DropdownButton<String>( items: sexType.map((String value) { return DropdownMenuItem<String>( value: value, child: Text(value), ); }).toList(), onChanged: (value) { if(value != null){ sex = value; } }, ), ), ], ), Container( decoration: BoxDecoration( image: DecorationImage( image: NetworkImage("https://i.ebayimg.com/images/g/WIgAAOSwal5YIJHv/s-l300.jpg", ), fit: BoxFit.fitHeight, ), ), child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox(height: 20,), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox(width: 80,), TextButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.resolveWith<Color>( (Set<MaterialState> states) { if(states.contains(MaterialState.pressed)) return Theme.of(context).colorScheme.primary.withOpacity(0.5); return Colors.blueGrey; }, ), ), onPressed: () { if (_formKey.currentState!.validate()) { print("route: homePage successful"); _formKey.currentState!.save(); //_setCurrentScreen(); pageDirection(); } }, child: Text( 'Enter', style: TextStyle( fontSize: 30, color: Colors.white, ), ), ), SizedBox(width: 80,), ], ), ] ), ), ] ), ), ) ) ); } }
Editor is loading...