Showing posts with label 【LARAVEL PHP and FLUTTER ANDROID STUDIO and IOS】dynamic multiple text field. Show all posts
Showing posts with label 【LARAVEL PHP and FLUTTER ANDROID STUDIO and IOS】dynamic multiple text field. Show all posts

Wednesday, 14 April 2021

【LARAVEL PHP and FLUTTER ANDROID STUDIO and IOS】dynamic multiple text field

main.dart

 import 'dart:convert';


import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Multiple Insert a',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Todo());
}
}

class Todo extends StatefulWidget {
@override
_TodoState createState() => _TodoState();
}

class _TodoState extends State<Todo> {
List _formdata = [];
var todo = List<Widget>();
int _index = 1;

void _add() {
int keyValue = _index;
_formdata.add({'id': _index, 'text': '', 'done': 0});
var _formdataIndex = _formdata.indexWhere((data) => data['id'] == keyValue);

todo = List.from(todo)
..add(Column(
key: Key("${keyValue}"),
children: <Widget>[
ListTile(
leading: Text('Name: '),
title: TextField(
onChanged: (val) {
_formdata[_formdataIndex]['text'] = val;
},
),
),
],
));
setState(() => ++_index);
}

@override
void initState() {
super.initState();
_add();
}

@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () =>
http.post('http://10.0.2.2:8080/api/todos',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(_formdata))
.then((value) {

}),
child: Icon(Icons.save),
),
appBar: AppBar(
title: Text('Add'),
actions: <Widget>[
FlatButton(
child: Icon(Icons.add, color: Colors.white,),
onPressed: _add,
),
],
),
body: ListView(
children: todo,
),
);
}
}

BREAKING: North Carolina automotive group acquires 7 Upstate dealerships

Breaking news from GSA Business Report Click here to view this message in a browser window. ...