Untitled
unknown
plain_text
a year ago
1.4 kB
7
Indexable
Never
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: ButtonColumn(), ); } } class ButtonColumn extends StatefulWidget { @override _ButtonColumnState createState() => _ButtonColumnState(); } class _ButtonColumnState extends State<ButtonColumn> { int _selectedIndex = 0; // Index of the currently selected button List<String> buttonLabels = ['Button 1', 'Button 2', 'Button 3', 'Button 4']; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Button Column Example')), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: List.generate(buttonLabels.length, (index) { return ElevatedButton( onPressed: () { setState(() { _selectedIndex = index; // Update selected index }); }, style: ElevatedButton.styleFrom( primary: _selectedIndex == index ? Colors.red : null, ), child: Text(buttonLabels[index]), ); }), ), ), ); } }