जवाबों:
आप जोड़ सकते हैं TextFieldएक के रूप में childएक करने के लिए Containerहै कि एक BoxDecorationसाथ borderसंपत्ति:
new Container(
margin: const EdgeInsets.all(15.0),
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent)
),
child: Text("My Awesome Border"),
)
यहाँ एक विस्तारित उत्तर है। A DecoratedBoxको आपको बॉर्डर जोड़ने की आवश्यकता है, लेकिन मैं Containerमार्जिन और पैडिंग जोड़ने की सुविधा के लिए उपयोग कर रहा हूं ।
यहाँ सामान्य सेटअप है।
Widget myWidget() {
return Container(
margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: myBoxDecoration(), // <--- BoxDecoration here
child: Text(
"text",
style: TextStyle(fontSize: 30.0),
),
);
}
कहाँ BoxDecorationहै
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(),
);
}
इन की एक सीमा चौड़ाई 1, 3और 10क्रमशः।
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
width: 1, // <--- border width here
),
);
}
इनका बॉर्डर कलर होता है
Colors.redColors.blueColors.greenकोड
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
color: Colors.red, // <--- border color
width: 5.0,
),
);
}
इनकी सीमा सीमा है
कोड
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border(
left: BorderSide( // <--- left side
color: Colors.black,
width: 3.0,
),
top: BorderSide( // <--- top side
color: Colors.black,
width: 3.0,
),
),
);
}
इन की सीमा त्रिज्या है 5, 10और 30क्रमशः।
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(
width: 3.0
),
borderRadius: BorderRadius.all(
Radius.circular(5.0) // <--- border radius here
),
);
}
DecoratedBox/ BoxDecorationबहुत लचीले हैं। स्पंदन पढ़ें - BoxDecoration धोखा शीट कई और विचारों के लिए।
प्रलेखन में कहा गया है, स्पंदन मापदंडों पर रचना को प्राथमिकता देता है। अधिकांश समय जो आप खोज रहे हैं वह कोई संपत्ति नहीं है, बल्कि एक आवरण (और कभी-कभी कुछ मददगार / "बिल्डर")
सीमाओं के लिए आप DecoratedBoxजो चाहते हैं , वह एक decorationसंपत्ति है जो सीमाओं को परिभाषित करती है; लेकिन यह भी पृष्ठभूमि छवियों या छाया।
वैकल्पिक रूप से @ अज़ीज़ा ने कहा, आप उपयोग कर सकते हैं Container। कौन का संयोजन है DecoratedBox, SizedBoxऔर कुछ अन्य उपयोगी विगेट्स।
सबसे अच्छा तरीका है BoxDecoration () का उपयोग करना
फायदा
हानि
BoxDecorationकेवल Containerविजेट के साथ उपयोग करें ताकि आप अपने विजेट को लपेटना चाहते हैंContainer()
उदाहरण
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.orange,
border: Border.all(
color: Colors.pink[800],// set border color
width: 3.0), // set border width
borderRadius: BorderRadius.all(
Radius.circular(10.0)), // set rounded corner radius
boxShadow: [BoxShadow(blurRadius: 10,color: Colors.black,offset: Offset(1,3))]// make rounded corner of border
),
child: Text("My demo styling"),
)
बॉर्डर दिखाने के लिए BoxDecoration () का उपयोग करना सबसे अच्छा तरीका है।
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff000000),
width: 4,
)),
child: //Your child widget
),