Customize Stepper in Flutter - 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.

Related

Flutter - How to remove the ability to click on a step title? Specifically the ripple effect even when stepTapped is undefined

I noticed that the steps can be clicked on to navigate back. But is there a way to disable this? In the image below clicking on the name triggers a material button click.
child: Stepper(
type: StepperType.vertical,
physics: const ScrollPhysics(),
currentStep: _currentStep,
onStepTapped: null,
controlsBuilder: ((context, details) {
return Row(
children: [
ElevatedButton(
onPressed: (() => continued()),
child: const BrandText(
text: 'Continue',
),
),
if (_currentStep != 0)
TextButton(
onPressed: (() => cancel()),
child: const BrandText(
text: 'Back',
),
),
],
);
}),
steps: [
Step(
title: const BrandText(text: 'Name'),
content: Column(
children: <Widget>[
BrandTextInput(
controller: _groupNameController,
hintText: 'Name',
iconName: Icons.label)
],
),
isActive: _currentStep >= 0,
state: _currentStep >= 0
? StepState.complete
: StepState.disabled,
),
Make onStepTapped blank
onStepTapped: (step){},
title click effect Disabled
You need to edit the stepper.dart file.
Widget _buildVertical() {
return ListView(
shrinkWrap: true,
physics: widget.physics,
children: <Widget>[
for (int i = 0; i < widget.steps.length; i += 1)
Column(
key: _keys[i],
children: <Widget>[
// InkWell(
// onTap: widget.steps[i].state != StepState.disabled ? () {
// // In the vertical case we need to scroll to the newly tapped
// // step.
// Scrollable.ensureVisible(
// _keys[i].currentContext!,
// curve: Curves.fastOutSlowIn,
// duration: kThemeAnimationDuration,
// );
//
// widget.onStepTapped?.call(i);
// } : null,
// canRequestFocus: widget.steps[i].state != StepState.disabled,
// child: _buildVerticalHeader(i),
// ),
Container(
child: _buildVerticalHeader(i),
),
_buildVerticalBody(i),
],
),
],
);
}

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"),
],
);
}
}

Flutter - Animated process widget

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.");
},
),
);

Flutter how to get a popup menu on a ListTile?

I'm trying to get a popupmenu under a ListTile. The title displays a description, the subtitle displays the selected value with some message and the onTap opens the popupmenu in which a user can select a value.
I tried putting a DropdownButtonHideUnderline in the subtitle, but this displays an arrow and does not respond to the ListTile onTab obviously.
How can I get a popupmenu on a ListTile?
Maybe you can try PopuMenuButton,
PopupMenuButton<String>(
onSelected: (String value) {
setState(() {
_selection = value;
});
},
child: ListTile(
leading: IconButton(
icon: Icon(Icons.add_alarm),
onPressed: () {
print('Hello world');
},
),
title: Text('Title'),
subtitle: Column(
children: <Widget>[
Text('Sub title'),
Text(_selection == null ? 'Nothing selected yet' : _selection.toString()),
],
),
trailing: Icon(Icons.account_circle),
),
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'Value1',
child: Text('Choose value 1'),
),
const PopupMenuItem<String>(
value: 'Value2',
child: Text('Choose value 2'),
),
const PopupMenuItem<String>(
value: 'Value3',
child: Text('Choose value 3'),
),
],
)
Take a look at How to open a PopupMenuButton?