kartal
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.
Future Extension
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());
}
Context Extension
You can easy to use context power so context help for many needs.
General Context Extension
I mostly use this extension. It's most needed for 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),
),
);
}
Widget Extension
Sometimes you need visible widget so you can this extension.
Text("Hello").toVisible(isAvaible);
MediaQuery Extension
This extension gives device size use so you can need dynamic(grid) value for device aspect, use the dynamic height or width.
SizedBox(
height: context.dynamicHeight(0.1),
width: context.dynamicWidth(0.1),
child: Text('${context.lowValue}'),
);
}
Navigation Extension
This extension can directly access the 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'),
),
],
)
Duration Extension
These extensions mainly for animation use.
AnimatedOpacity(
opacity: context.isKeyBoardOpen ? 1 : 0,
duration: context.durationLow,
child: Text('${context.durationLow.inHours}'),
);
Padding Extension
These extensions declares the projects main padding values.
Padding(
padding: context.paddingLow,
child: Padding(
padding: context.horizontalPaddingMedium,
child: Text('${context.durationLow.inHours}'),
),
)
Empty Widget Extension
Sometimes you 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')],
)
],
)
Radius Extension
This extension only uses to draw the border.
Container(
decoration: BoxDecoration(borderRadius: context.lowBorderRadius),
);
Device Screen Size Extension
This extension can be used to create responsive widgets.
Scaffold(
drawer: context.isSmallScreen ? Drawer() : null,
body: Container(),
);
Device Operatig System Extension
This extension can be used to create native widgets.
SizedBox(
child: context.isIOSDevice ? CupertinoButton() : MaterialButton(),
);
Image Extension ðŸŒ
You can use very easy rotation from image.
@override
Widget build(BuildContext context) {
return Image.network('https://picsum.photos/200/300').bottomRotation;
}
Integer Extension
Now, we have a little code.
10.randomValue
Key Extension
Find a render object with using key
final GlobalKey key = GlobalKey();
final GlobalObjectKey key2 = GlobalObjectKey('vb');
@override
Widget build(BuildContext context) {
return Container(
key:key,
child:Text('hello',key:key2)
);
}
void findElementAndDetail(){
final box = key.renderBox;
final boxHeight = key.height
}
void scrollToObjectKey(){
key2.scrollToWidget()
}
List Extension
You can find a specific index or null value for the list
final List<User>? values;
void searchIndex(){
values.indexOrNull
}
List Validation Extension
We can check this for empty and null.
final List<T>? values = null;
@override
Widget build(BuildContext context) {
return Container(
child: values.isNotNullOrEmpty ? Text('ok') : Text('false'),
);
}
String Extension
String needs validation, color, launch, share etc.
Package Information Extension
You can access directly application platform information.
Text(''.appName)
Text(''.version)
Text(''.packageName)
Text(''.buildNumber)
Validation Extension
Validate your string value to some features.
TextFormField(validator: (value) => value.isNotNullOrNoEmpty ? null : 'fail'),
Input Formatter
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}');
},
)
],
);
Launch Any Content In App Dialog Extension
You need to open the value in device system. You can just say string value to launch prefix.
void openEmail(String value){
value.launchWebsite;
}
Share Any Content External Apps Extension
This extension can share your value to other apps or optional apps.
void shareWhatssApp(String value) {
value.shareWhatsApp();
}
void openWeb(String value) {
value.launchWebsite;
}
Authorization Extension
Sometimes you need this extension from send service request so easy create bearer token string.
void bearerTokenHeader() {
print('TOKEN-X-X-X'.beraer);
}
File Extension
There are extensions that will facilitate your file operations.
File Type Extension
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();
);
Tasks
License
2020 created for @VB10