Home > Mobile >  I want to create elevated button and text formfield with same size
I want to create elevated button and text formfield with same size

Time:04-05

Also I dont want to give sizes one by one for every widget. I imagine that I give a size for widget and other widgets gets size from the first one. But even I tryed almost everything that I seen, still I couldnt solve this problem. Can you help me guys?

Thanks for answering.

CodePudding user response:

Create a constants.dart file

add

const widgetWidth = 100.0;

create a widget_box.dart

import 'constants.dart'
class WidgetBox extends StatelessWidget {

const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
width: widgetWidth
)
}
}

then whenever you want to use that widget just plug in

WidgetBox()

and when you change the value in the constant file it will change it in the widgetbox.dart value which will update it anywhere you use the class. obviously you can build out whatever you want but this is how you can make one change to the same reproduced widget everywhere.

CodePudding user response:

I dont know if its helpfull. Im new at overflow. Sorry about that.

     import 'package:flutter/material.dart';
     import 'package:flutter/scheduler.dart';
    

      class SignInView extends StatefulWidget {
      const SignInView({Key? key}) : super(key: key);
    
      @override
      State<SignInView> createState() => _SignInViewState();
    }
    
    
    
    class _SignInViewState extends State<SignInView> {
    
      var _identifier;
      var _sifremiUnuttum;
    
    
      double _height = 56; // dummy height
      GlobalKey globalKey = GlobalKey();
    
    
      @override
      void initState() {
        super.initState();
        SchedulerBinding.instance?.addPostFrameCallback((_) {
          setState(() {
            // height of the TextFormField is calculated here, and we call setState to assign this value to Button
            _height = globalKey.currentContext!.size!.height;
          });
        });
      }
        
            TextFormField(
                          key: globalKey,
                          decoration: InputDecoration(
                            labelText: 'Email Addres',
                            hintText: 'Email Addres',
                            filled: true,
                            fillColor: Color.fromARGB(255, 249, 249, 249),
                            errorBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(25.0),
                              borderSide: BorderSide(
                                  color: Colors.green
                              ),
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(25.0),
                              borderSide: BorderSide(
                                // style: BorderStyle.none,
                                color: Colors.blue,
                              ),
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(25.0),
                              borderSide: BorderSide(
                                  style: BorderStyle.none,
                                  color: Colors.green
                              ),
                            ),
                            disabledBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(25.0),
                              borderSide: BorderSide(
                                // style: BorderStyle.none,
                                  color: Colors.green
                              ),
                            ),
                            // border: OutlineInputBorder(
                            //     borderRadius: BorderRadius.circular(20.0)
                            // ),
        
                          ),
                        )


ElevatedButton(
                    onPressed: (){},
                    style: ButtonStyle(
                      fixedSize: MaterialStateProperty.all(globalKey.currentContext?.size)
                    ),
                    child: Text('Giriş Yap')
                )
  • Related