Kartal is the place for my borning country so I created an extension for giving born to more power with simple use. If you want to example with these extensions, you should be look example folder.
You can easy use for network or any future request.
Future<String> fetchDummyData(BuildContext context) async {
await Future.delayed(context.durationLow);
return Future.value('Okey');
}
@override
Widget build(BuildContext context) {
return fetchDummyData(context).toBuild<String>(
onSuccess: (data) {
return Text(data);
},
loaindgWidget: CircularProgressIndicator(),
notFoundWidget: Text('Oh no'),
onError: FlutterLogo());
}
You can easy to use context power so context help for many needs.
I use the most this extesnion. It's most needed for the your products.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(brightness: context.appBrightness),
body: Container(
height: context.mediaQuery.size.height,
color: context.colorScheme.onBackground,
child: Text(context.isKeyBoardOpen ? 'Open' : 'Close', style: context.textTheme.subtitle1),
),
);
}
Sometimes need visible widget so you can this extension.
Text("Hello").toVisible(isAvaible);
These extension gives device size use so you can need dynamic(grid) value for device aspect, use the dyanmic height or width.
SizedBox(
height: context.dynamicHeight(0.1),
width: context.dynamicWidth(0.1),
child: Text('${context.lowValue}'),
);
}
These directly access navigation features.
Column(
children: [
FloatingActionButton(
child: Text('Navigation Prop'),
onPressed: () {
context.navigation.canPop();
},
),
FloatingActionButton(
onPressed: () {
context.pop();
},
child: Text('Navigation Pop'),
),
FloatingActionButton(
onPressed: () {
context.navigateName('/hello');
},
child: Text('Navigation Named'),
),
FloatingActionButton(
onPressed: () {
context.navigateToPage(HomeViewDetail(), type: SlideType.TOP);
},
child: Text('Navigation Named'),
),
FloatingActionButton(
onPressed: () {
context.navigateToReset('/hello');
},
child: Text('Navigation Named and Remove'),
),
],
)
These extensions mainly for animation use.
AnimatedOpacity(
opacity: context.isKeyBoardOpen ? 1 : 0,
duration: context.durationLow,
child: Text('${context.durationLow.inHours}'),
);
These extensions declare project main padding values.
Padding(
padding: context.paddingLow,
child: Padding(
padding: context.horizontalPaddingMedium,
child: Text('${context.durationLow.inHours}'),
),
)
Sometimes need empty widget screen for space area, you can use that time.
Column(
children: [
Text('${context.durationLow.inHours}'),
context.emptySizedHeightBoxHigh,
Row(
children: [Text('Row'), context.emptySizedWidthBoxLow, Text('Row')],
)
],
)
This extension only uses to draw the border.
Container(
decoration: BoxDecoration(borderRadius: context.lowBorderRadius),
);
This extension is used to create responsive widgets.
Scaffold(
drawer: context.isSmallScreen ? Drawer() : null,
body: Container(),
);
This extension is used to create native widgets.
SizedBox(
child: context.isIOSDevice ? CupertinoButton() : MaterialButton(),
);
You can use very easy rotiaton from image.
@override
Widget build(BuildContext context) {
return Image.network('https://picsum.photos/200/300').bottomRotation;
}
Now, we has a a little code.
extension IntagerExtension on int {
int get randomValue => Random().nextInt(17);
}
We need list operation sometmes null check etc.
We can check this for empty and null.
final List values = null;
@override
Widget build(BuildContext context) {
return Container(
child: values.isNotNullOrEmpty ? Text('ok') : Text('false'),
);
}
String need validation, color, launch, share etc.
You can access directly applicaton platform information.
Text(''.appName)
Text(''.version)
Text(''.packageName)
Text(''.buildNumber)
Validate your string value to some features.
TextFormField(validator: (value) => value.isNotNullOrNoEmpty ? null : 'fail'),
You need the value mask and validation use formatter extension.
Column(
children: [
TextFormField(validator: (value) => value.isNotNullOrNoEmpty ? null : 'fail'),
TextFormField(validator: (value) => value.isValidEmail ? null : 'fail'),
TextFormField(validator: (value) => value.isValidPassword ? null : 'fail'),
TextField(
inputFormatters: [InputFormatter.instance.phoneFormatter],
onChanged: (value) {
print('${value.phoneFormatValue}');
},
)
],
);
You need open the value in device system. You can just say string value to launch prefix.
void openEmail(String value){
value.launchWebsite;
}
These extension share your value to other apps or optional apps.
void shareWhatssApp(String value) {
value.shareWhatsApp();
}
void openWeb(String value) {
value.launchWebsite;
}
Sometimes need this extension from send service request so easy create bearer token string.
void bearerTokenHeader() {
print('TOKEN-X-X-X'.beraer);
}
There are extensions that will facilitate your file operations.
This extension shows what type a file is.
final file = File('assets/image.png');
Container(
child: file.fileType == FileType.IMAGE ? Image.asset('${file.path}') : SizedBox();
);
There is also the use of .is type.
final file = File('assets/image.jpeg');
Container(
child: file.isImageFile ? Image.asset('${file.path}') : SizedBox();
);
- Advance String Extension
- More Integer Extension
- Unit Test
- File Extension
- SQLite etc. extension
- Application Extensions
2020 created for @VB10