How to access a variable from another dart file . Flutter
Create a constructor onDateSelected so you can get a datetime when you select a date from date-picker.
class DateOfBirth extends StatefulWidget {
final Function onDateSelected;
DateOfBirth({this.onDateSelected});
@override
_DateOfBirthState createState() => _DateOfBirthState();
}
class _DateOfBirthState extends State<DateOfBirth> {
DateTime? dateTime;
String _text = '';
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border.all(), borderRadius: BorderRadius.circular(5)),
width: double.infinity,
child: Padding(
padding: const EdgeInsets.only(left: 8, right: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Date Of Birth'),
Text(_text),
ElevatedButton(
onPressed: () async {
dateTime = await showDatePicker(
context: context,
initialDate: dateTime ?? DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
);
widget.onDateSelected(dateTime);
setState(() {
_text =
'${dateTime?.day}/${dateTime?.month}/${dateTime?.year}';
});
},
child: const Text('Date Of Birth'),
),
],
),
),
);
}
}
// You can get date like this.
DateOfBirth(
onDateSelected: (date) {
//
},
)
Python: Dynamically access variable from another file
You can use getattr()
for this:
main_file.py
import config as cf
new_var = 'var' + str(1)
print(getattr(cf, new_var))
The attribute is here the variable of the imported module.
Related Topics
Onchange Event Updates State With 1 Character Delay
How to Open a Web Page Automatically in Full Screen Mode
Export Method/Function in React Native
Looping Through Dynamically Generated Checkboxes to Get Values
Disable F5 and Browser Refresh Using JavaScript
How to Convert Date Format from Dd.Mm.Yyyy to Dd/Mm/Yyyy in JavaScript
Mongodb, Update Collection Field If New Value Is Not Null
Angular 4 Submit Form by Pressing Enter With Login Button
How to Get the Value of Li on Dropdown Menu Click in Laravel Using Jquery
Javascript Index of for Multiple Values
Check If My HTML Table Is Empty Using JavaScript
React - How to Open Pdf File as a Href Target Blank
Node Server Running But Localhost Refusing to Connect
Get a List of Dates Between Two Dates Using JavaScript
Filereader Onload With Result and Parameter