Search
 
SCRIPT & CODE EXAMPLE
 

DART

how to use wrap widget in flutter

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedButton = null;
  void setSelectedButton(int index) {
    setState(() {
      _selectedButton = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Wrap(children: [
          for (int i = 0; i < 10; i++)
            CustomElevatedButton(
                i,
                _selectedButton == null
                    ? Colors.red
                    : _selectedButton == i
                        ? Colors.red
                        : Colors.grey, () {
              setSelectedButton(i);
            }),
        ]),
      ),
    );
  }
}

class CustomElevatedButton extends StatelessWidget {
  final int number;
  final Color buttonColor;
  final void Function() onPressed;
  CustomElevatedButton(this.number, this.buttonColor, this.onPressed);
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(5.0),
      child: Column(
        children: <Widget>[
          ElevatedButton(
            onPressed: onPressed,
            child: Text(
              '${number + 1}',
              textAlign: TextAlign.center,
            ),
            style: ElevatedButton.styleFrom(
              shadowColor: Colors.grey,
              primary: buttonColor,
              minimumSize: Size(70, 70),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(15.0),
              ),
              textStyle: TextStyle(
                fontSize: 40,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Comment

PREVIOUS NEXT
Code Example
Dart :: flutter build async 
Dart :: flutter login pop to index 1 
Dart :: android studio not detecting new package in flutter 
Dart :: dart anonymous function in forEach 
Dart :: flutter decreate saturation 
Dart :: flutter row vertical direction 
Dart :: dart formatter stuck 
Dart :: flutter navigator get result 
Dart :: text widget not recognize the currency symbol flutter 
Dart :: how to set device into autorotate in flutter 
Dart :: flutter sidebox 
Dart :: random element from list dart 
Dart :: flutter container padding 
Dart :: flutter instance of 
Dart :: Flutter default device font PlatformChannel 
Dart :: functions in dart 
Swift :: firebase crashlytics dsym missing 
Swift :: swift append element to array 
Swift :: swift set view z order front 
Swift :: swift scrollview hide scrollbar 
Swift :: swift 5 func to increase number every time call 
Swift :: white or light ASAuthorizationAppleIDButton “Sign in with Apple” button - Swift 
Swift :: swiftui vstack alignment 
Swift :: swift clear badge number 
Swift :: Make a VStack fill the width of the screen in SwiftUI 
Swift :: listview swiftui 
Swift :: swiftui 100 days 
Swift :: swift loop through 2 arrays at once 
Swift :: remove all add TapGestureRecognizer swift 
Swift :: how can i find range of a string in another string swift 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =