Flutter - Animated process widget - flutter

I want to create a process animation widget like this in flutter, which shifts from 1 to 2 with pageview.
Any suggestions are welcome

This can be achieved using the flutter widget Stepper, below is the basic implementation of Stepper Widget
Full article on Medium here
Widget _tabStep() => Container(
margin: EdgeInsets.only(top: 10),
color: PURPLE,
child: Stepper(
steps: [
Step(
title: Text("First"),
content: Text("This is our first example."),
),
Step(
title: Text("Second"),
content: Text("This is our second example."),
),
Step(
title: Text("Third"),
content: Text("This is our third example."),
),
Step(
title: Text("Forth"),
content: Text("This is our forth example."),
),
],
currentStep: _index,
onStepTapped: (index) {
setState(() {
_index = index;
});
},
onStepCancel: () {
print("You are clicking the cancel button.");
},
onStepContinue: () {
print("You are clicking the continue button.");
},
),
);

Related

Reduce Flutter Stepper Bar size

I'm using flutter Stepper for my UI . I want to reduce the height of the stepper horizontal menu.
Please help me.
1
You can also change the heights of the widgets in the contents of Steps to the same value, and make it a SingleChildScrollView if needed. e.g
Step(content: Container(
height: MediaQuery.of(context).size.height - 250, //IMPORTANT
child: SingleChildScrollView(
child: Column(children: <Widget>[
...
),
2
This should work. Stepper has an argument called type where you can decide it's type. More info here: https://medium.com/flutterdevs/stepper-widget-in-flutter-37ce5b45575b
You may have to play around with the UI to make it look like your desired photo, but this should get you on track. Just set type: StepperType.horizontal.
Widget build(BuildContext context) {
return Container(
height: 300,
width: 300,
child: Stepper(
type: StepperType.horizontal,
currentStep: _index,
onStepCancel: () {
if (_index <= 0) {
return;
}
setState(() {
_index--;
});
},
onStepContinue: () {
if (_index >= 1) {
return;
}
setState(() {
_index++;
});
},
onStepTapped: (index) {
setState(() {
_index = index;
});
},
steps: [
Step(
title: Text("Step 1 title"),
content: Container(
alignment: Alignment.centerLeft,
child: Text("Content for Step 1")),
),
Step(
title: Text("Step 2 title"),
content: Text("Content for Step 2"),
),
],
),
);
}

Flutter | Load datatable after application load

I want to load data table after application load. But when application load automatically data table also load. I need that data table load with button click event.
This is the primary widget.
Widget build
Container(
child: OutlineButton(
child: Text('UPDATE',style: TextStyle(color: Colors.white)),
color: Colors.orange,
onPressed: () {abc();},
),
),
itemCount==1 ? Container(
padding: EdgeInsets.all(15.0),
child: SingleChildScrollView(
child: Column(
children: [
activityHistory()
],
),
),
):
I add that Data table to list view builder. I want to call that from button click.
Called Datatable Widget
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
if (itemCount != 0) {
print("OK");
return Container(
child:DataTable(
sortAscending: sort,
sortColumnIndex: 0,
columns: [
DataColumn(
label: Text("Code", style: TextStyle(fontSize: 16)),
numeric: false,
onSort: (columnIndex, ascending) {
setState(() {
sort = !sort;
});
onSortColum(columnIndex, ascending);
}),
DataColumn(
label: Text("QTY", style: TextStyle(fontSize: 16)),
numeric: false,
),
],
rows: avengers
.map(
(avenger) => DataRow(
selected: selectedAvengers.contains(avenger),
cells: [
DataCell(
Text(avenger.name),
onTap: () {
print('Selected ${avenger.name}');
},
),
DataCell(
Text(avenger.weapon),
),
]),
).toList(),
),
);
}else {
print("SizedBox");
return SizedBox();
}
}
);}
Now that Data table load with the application . But i want it load after application load with button click .
How can i load that table after application load and button click event ?
Initially button is NOT clicked - show SizedBox. When button is clicked we pass callback function to onPressed and show ListView.
setState(() {
clicked = true;
});
Something like this.
class _MyHomePageState extends State<MyHomePage> {
bool clicked = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Load list on click"),
),
body: activityHistory(),
floatingActionButton: FloatingActionButton(
onPressed: (){
setState(() {
clicked = true;
});
},
child: Icon(Icons.play_arrow),
),
);
}
Widget activityHistory() {
if (!clicked) return SizedBox();
return ListView(
children: [
Text("Item 1"),
Text("Item 2"),
Text("Item 3"),
Text("Item 4"),
Text("Item 5"),
],
);
}
}

Understanding ListView.builder

Okay, so I think I am stuck with flutter builder a little bit.
I've created simple app, just to make my question easier:
I have a data class:
class DataLists {
List<ListTile> lists = [
ListTile(
leading: Text('Tile Leading 1'),
title: Text('Tile Title 1'),
subtitle: Text('Tile Subtitle 1'),
trailing: Text('Tile Trailing 1'),
),
ListTile(
leading: Text('Tile Leading 2'),
title: Text('Tile Title 2'),
subtitle: Text('Tile Subtitle 2'),
trailing: Text('Tile Trailing 2'),
),
ListTile(
leading: Text('Tile Leading 3'),
title: Text('Tile Title 3'),
subtitle: Text('Tile Subtitle 3'),
trailing: Text('Tile Trailing 3'),
),
ListTile(
leading: Text('Tile Leading 4'),
title: Text('Tile Title 4'),
subtitle: Text('Tile Subtitle 4'),
trailing: Text('Tile Trailing 4'),
),
ListTile(
leading: Text('Tile Leading 5'),
title: Text('Tile Title 5'),
subtitle: Text('Tile Subtitle 5'),
trailing: Text('Tile Trailing 5'),
),
];
}
And main dart file:
import 'package:flutter/material.dart';
import 'package:learning/data.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: TestTile(),
);
}
}
class TestTile extends StatefulWidget {
#override
_TestTileState createState() => _TestTileState();
}
class _TestTileState extends State<TestTile> {
DataLists dataLists = DataLists();
TextEditingController leadingController = TextEditingController();
TextEditingController titleController = TextEditingController();
TextEditingController subtitleController = TextEditingController();
TextEditingController trailingController = TextEditingController();
Future<String> createDialog(BuildContext context) {
return showDialog(context: context, builder: (context) {
return SimpleDialog(
title: Text('Input data: '),
children: [
TextField(
controller: leadingController,
),
TextField(
controller: titleController,
),
TextField(
controller: subtitleController,
),
TextField(
controller: trailingController,
),
MaterialButton(
child: Text('Submit'),
onPressed: () {
Navigator.of(context).pop(leadingController.text);
setState(() {
List<ListTile> tempList = dataLists.lists;
if (titleController.text.isNotEmpty && leadingController.text.isNotEmpty && subtitleController.text.isNotEmpty && trailingController.text.isNotEmpty) {
tempList.add(
ListTile(
leading: Text(leadingController.text),
title: Text(titleController.text),
subtitle: Text(subtitleController.text),
trailing: Text(trailingController.text),
),
);
dataLists.lists = tempList;
} else {
print('Null values');
}
leadingController.clear();
titleController.clear();
subtitleController.clear();
trailingController.clear();
});
},
),
],
);
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test Tile'),
),
body: Container(
child: SafeArea(
child: ListView(
children: <ListTile>[
for (ListTile e in dataLists.lists)
e
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
createDialog(context);
setState(() {
});
},
child: Icon(Icons.add),
backgroundColor: Colors.blue,
),
);
}
}
The problem is: I cannot make it work in other way. Can someone change my implementation to a ListView.builder? I am stuck a little bit :(
Key goal:
Idea:
Click on a button -> form appear -> after you press a submit button list is updated instantly
I'll add a delete function later, just learning docs, nothing more.
Can someone review my code and, if no one mind, try to rewrite the same idea, but using ListView.builder?
I've tried several times, but cannot get properties correctly from the form, and update listtile using builder, need help
Cheers!
ListView.builder requires a static height, so keep a track on that one. Now, coming to the question, that you want to use ListView.builder. You can do via this
Container(
height: give_your_height,
child: ListView.builder(
shrinkWrap: true,
itemCount: dataLists.lists.length,
itemBuilder: (context, index) {
return dataLists.lists[index];
}
)
)
Try this, it may solve your issue.
ListView(
children: [
for (ListTile e in dataLists.lists)
Card(child: e)
],
),
or with ListView.builder()
ListView.builder(
itemCount: dataLists.lists.length,
itemBuilder: (context, index) {
return dataLists.lists[index];
},
);
Further Reference: https://api.flutter.dev/flutter/material/ListTile-class.html

Open collapsed ListTile after choose row

How could I do so that on the onTap of the line I open another ListTile below?
return ListTile(
title: Html(data: "<br/> <b>${team[index]['code']}</b>"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
setState(() {
// call open colapsed or child listtile here
});
},
);
If I understand your question correctly, you want to show more ListTile items when the user taps on one of the ListTile items?
If that's the case, you can use ExpansionTile instead.
Here is an example code:
ExpansionTile(
onExpansionChanged: (res) {
print(res ? 'Open' : 'Close');
},
title: Text('Dropdown'),
children: [
ListTile(
title: Text('Test #1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print('Test #1');
},
),
ListTile(
title: Text('Test #1'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print('Test #1');
},
),
],
)
P.S. You can also nest ExpansionTile inside another ExpansionTile.

Customize Stepper in Flutter

I want to customize the Steppers in flutter.
How can I place the Step title to the left of each step bar?
How can I change the line bar to the dotted bar of the stepper?
And how can I customize the state of the step other than the 5 StepState provided like a round bubble?
Here is my code.
Container(
child: Stepper(
currentStep: 0,
controlsBuilder: (BuildContext context, {
VoidCallback onStepContinue,
VoidCallback onStepCancel
}) => Container(),
steps: [
Step(
content: Container(
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('9:00Am - 10:00AM'),
Text(
'Everest Tour',
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
),
),
title: Text('9:00 AM'),
),
Step(
content: Text('2nd Data'),
title: Text('10:00 AM'),
state: StepState.editing,
isActive: true,
subtitle: Text('subtitle')
)
],
),
)
You can customize the Stepper widget by modifying the original Stepper widget class. Here's a customized Stepper widget I've created that can be configured with optional stepIndicatorAlignment and dottedLine arguments. The text on 'Continue' and 'Cancel' buttons can also be modified.
Here's a sample on how it can be implemented.
CustomStepper(
// stepIndicatorAlignment is set to StepIndicatorAlignment.left by default if not configured
stepIndicatorAlignment: StepIndicatorAlignment.right,
// dottedLine is set to false by default if not configured
dottedLine: true,
currentStep: _index,
onStepCancel: () {
if (_index > 0) {
setState(() {
_index -= 1;
});
}
},
onStepContinue: () {
if (_index <= 0) {
setState(() {
_index += 1;
});
}
},
onStepTapped: (int index) {
setState(() {
_index = index;
});
},
steps: <CustomStep>[
CustomStep(
title: const Text('Step 1 title'),
content: Container(
alignment: Alignment.centerLeft,
child: const Text('Content for Step 1'),
),
continueButtonLabel: 'YES',
cancelButtonLabel: 'NO',
),
CustomStep(
title: Text('Step 2 title'),
content: Container(
alignment: Alignment.centerLeft,
child: Text('Content for Step 2'),
),
),
],
),
In this similar Stack Overflow post, I've explained how I'm able to modify the stock Flutter Stepper widget.