'on swipe how can i set text in text field after that edit text and insert again on that position where we swipe
on swipe how can I set text in the text field after that edit text and insert it again in that position. swipe in Dismissible and after swipe, I want my text on the input text field and change the text and add the text in the same position can you please help me strong text enter image description here
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../models/model.dart';
import 'list_provider.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late GlobalKey<FormState> _formKey;
late TextEditingController _controller;
var taskItems;
int counter = 0;
late DynamicList listClass;
bool isUpdate =false;
@override
void initState() {[enter image description here][1]
// TODO: implement initState
super.initState();
_formKey = GlobalKey();
_controller = TextEditingController();
taskItems = Provider.of<ListProvider>(context, listen: false);
listClass = DynamicList(taskItems.list);
}
@override
void dispose() {
// TODO: implement dispose
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
key: _formKey,
child: TextFormField(
controller: _controller,
onSaved: (val) {
taskItems.addItem(val);
},
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState?.save();
_controller.clear();
}
},
child: Text('Add'),
),
),
const Padding(padding: EdgeInsets.all(8.0),
),
Consumer<ListProvider>(builder: (context, provider, listTile) {
return Expanded(
child: ListView.builder(
itemCount: listClass.list.length,
itemBuilder: buildList,
),
);
}),
],
),
**
-
> Heading
**
));
}
Widget buildList(BuildContext context, int index) {
counter++;
return Dismissible(
key: Key(counter.toString()),
direction: DismissDirection.startToEnd,
onDismissed: (direction) {
taskItems.deleteItem(index);
},
child: Container(
margin: EdgeInsets.all(4),
decoration: BoxDecoration(
border: Border.all(
color: Colors.blue,
width: 2,
),
borderRadius: BorderRadius.circular(10)),
child: ListTile(
title: Text(listClass.list[index].toString()),
trailing: IconButton(iconSize: 30, icon: Icon(Icons.delete),
onPressed: () {
setState(() {
taskItems.deleteItem(index);
},
);
},
),
),
),
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|