aqua to help with ui development
utility classes/functions to help with ui development using the flutter framework.
it is recommended to use the as keyword with the import statement when importing the package to prevent name conflicts, for example…
import 'package:aqua/aqua.dart' as aqua
to log output to file
await aqua.log('data to log', logfile: 'path/to/file', clear: true, time: true);
to save data to device
future<void> save() async {
var id = 'id';
var _value = 1920;
await aqua.pref.set(id, value);
var value = await aqua.pref.get(id);
}
to put a block of code in a try catch
// the argument for trycatch could either be a callback to a function or a future
// as a function
widget _buildwidget(){
// may fail to build for some reason
}
var child = await aqua.trycatch(_buildwidget());
// as a future
future<widget> _buildwidget() async {
// may fail to build for some reason
}
var future = _buildwidget();
var child = await aqua.trycatch(future);
if(child != null){
// proceed
}
when fetching data from server in json, or posting a query to server in json
// posting to an endpoint
var fromserver = await aqua.client(
'192.168.1.100', //ip
8080, // port
'/test', // endpoint
query: {
'id': 1,
}, // post parameters
// verbose: true
).getresponse();
// a real end point would look like this
// the end point is free to use
// you can find the rest of the endpoints here: https://www.coingecko.com/en/api
var fromserver = await aqua.client(
'api.coingecko.com',
443,
'/api/v3/coins/markets',
issecured: true,
query: {
'vs_currency': 'usd',
'order': 'market_cap_desc',
'per_page': '20',
'page': '1',
'sparkline': 'true'
}
).getresponse(method: 'get');
desktop only
to allow for mouse pointers to change to click icons on hovering on a clickable widget
@override
widget build(buildcontext context){
// some code
// then
return aqua.mouseinteractivity(
child: child
);
}
to get a random index between a range of indexes
var index = aqua.getrandomnumber(min: 10, max: 10000);
to output info on screen with different colors
aqua.pretifyoutput('to print on screen'); // will print in green
aqua.pretifyoutput('to print on screen', color: 'red');
to add a shadowy effect on an image
@override
widget build(buildcontext context){
return stack(
children: [
_buildimage(),
aqua.shadow(
width: width,
height: height,
)
]
);
}
a quick drop down widget
@override
widget build(buildcontext context){
return aqua.dropdown(
initvalue: 'one',
items: ['one', 'two', 'three', 'four', 'five', 'six']
);
}
a quick tabbar. tabs without scaffold…
@override
widget build(buildcontext context){
return material(
child: defaulttabcontroller(
length: 3,
child: column(
children: [
aqua.tabheader(
tablisting: ['car', 'transit', 'bike'],
),
expanded(
child: tabbarview(
children: [
icon(icons.directions_car),
icon(icons.directions_transit),
icon(icons.directions_bike),
],
),
)
],
),
)
);
}
to get screen dimensions in scale
@override
widget build(buildcontext context){
aqua.dimensions().init(context);
return container(
width: aqua.dimensions.width, // full width of screen
height: aqua.dimensions.height, // full height of screen
color: colors.red
);
}
to captilaize a word
var capitalized = aqua.capitalize('alphabet');
print('capitalized: $capitalized);
to create a file quickly (will also create the recursive directories on the path)
await aqua.createfile('/path/to/file');
// to clear a file/truncate a file
await aqua.createfile('/path/to/file', clear: true);
to generate a random id
var id = aqua.generateuuid(length: 30);
to navigate
// some code
// then
aqua.dimensions().init(context);
widget viewone = container(
width: aqua.dimensions.width,
height: aqua.dimensions.height
color: colors.blue
);
widget viewtwo = container(
width: aqua.dimensions.width,
height: aqua.dimensions.height
color: colors.red
);
// to navigate to the next view without erasing the previous view from state
aqua.customnavigator(
context: context,
buildscreen: () = > viewone
).navigatetopage();
// to navigate to the next view and erase the previous view from state
aqua.customnavigator(
context: context,
replacesingle: true,
buildscreen: () = > viewone
).navigatetopage();
// to navigate to the next view and erase all the previous views from state
aqua.customnavigator(
context: context,
replaceall: true,
buildscreen: () = > viewone
).navigatetopage();
// to navigate to the next view using a named route
aqua.customnavigator(
context: context,
namedroute: '/home',
buildscreen: () = > viewone
).navigatetopage();
to display loading icon
// render this widget as you see fit
widget loadingicon = aqua.loadingicon();
// to specify a loading type: check the different loading icons at this location
// https://github.com/jogboms/flutter_spinkit
import 'package:flutter_spinkit/flutter_spinkit.dart' as spinkitt;
widget loadingicon = aqua.loadingicon(
spinkitwidget: spinkitt.spinkitwave(
color: colors.blue,
size: 40.0,
),
);
to request focus from another widget
@override
widget build(buildcontext context){
// some code
// then
widget withfocus = aqua.requestfocus(child, context: context);
// make sure to return a widget
}
to add commas to numbers
string number = aqua.pretifynumber('1000000');
print('number: $number');
to clip images into a circular widget
@override
widget build(buildcontext context){
// some code
// then
widget clippedimage = aqua.clippedcircle(
child: child // some widget, could be an image, wrapped in a container,
color: colors.blue // border of the circle
);
// make sure to return a widget
}
custom text form widget
class play extends statefulwidget {
@override
playstate createstate() => playstate();
}
class playstate extends state<play>{
focusnode focusnode;
texteditingcontroller texteditingcontroller;
@override
void initstate(){
super.initstate();
focusnode = focusnode();
texteditingcontroller = texteditingcontroller();
}
@override
void dispose(){
focusnode?.dispose();
texteditingcontroller?.dispose();
super.dispose();
}
@override
widget build(buildcontext context){
aqua.dimensions().init(context);
// more on this later ...
// check source code :)
return sizedbox(
width: aqua.dimensions.width,
height: 100.0,
child: aqua.textformfieldcustom(
isoutlineborder: true, // or false
focusnode: focusnode
controller: texteditingcontroller,
)
);
}
}
flutter devices
window navigator, a bit of boilerplate code is needed for this to work …
to setup your environment for mobile, click here
to setup your environment for desktop, click here
copy paste the code below to render a screen like this:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:aqua/aqua.dart' as aqua;
class shell extends statefulwidget {
@override
shellstate createstate() => shellstate();
}
class shellstate extends state<shell>{
widget selectedwidget;
aqua.navigationstreamer mainnavstreamer;
streamsubscription mainnavstreamsubscription;
@override
void initstate(){
super.initstate();
mainnavstreamer = aqua.navigationstreamer();
mainnavstreamsubscription = mainnavstreamer.listen((data){
aqua.pretifyoutput('[shell] data from nav stream: $data');
selectedwidget = data['window'];
setstate((){});
});
}
@override
void dispose(){
mainnavstreamsubscription.cancel();
mainnavstreamer.close();
super.dispose();
}
widget _buildshell(buildcontext context){
aqua.dimensions().init(context);
double navwidth = aqua.dimensions.width * 0.15;
double contentwindowwidth = aqua.dimensions.width - navwidth;
map<string, map<string, dynamic>> generatedroutes = _buildgeneratedroutes(
contentwindowwidth,
aqua.dimensions.height
);
var textstyle = textstyle(
fontsize: 30.0,
color: colors.white,
fontweight: fontweight.bold
);
widget firstwidget = container(
width: contentwindowwidth,
height: aqua.dimensions.height,
color: colors.purple,
child: center(
child: text(
'home',
style: textstyle
)
),
);
return scaffold(
appbar: null,
body: singlechildscrollview(
child: container(
child: row(
children: [
aqua.navigation(
width: navwidth,
height: aqua.dimensions.height,
header: container(
width: navwidth,
height: 100.0,
color: colors.red,
child: center(
child: text(
'header',
style: textstyle(
color: colors.white,
fontweight: fontweight.bold
),
),
),
),
routes: generatedroutes,
bgcolors: <color>[
colors.blue,
colors.blueaccent
],
hovercolor: colors.brown.withopacity(0.5),
selectedcolor: colors.white.withopacity(0.5),
navstreamer: mainnavstreamer,
),
container(
child: column(
mainaxisalignment: mainaxisalignment.start,
children: [
selectedwidget == null ? aqua.requestfocus(
firstwidget,
context: context
) : aqua.requestfocus(
selectedwidget,
context: context
)
],
),
)
]
)
),
),
);
}
@override
widget build(buildcontext context) => _buildshell(context);
map<string, map<string, dynamic>> _buildgeneratedroutes(double windowwidth, double windowheight){
var textstyle = textstyle(
fontsize: 30.0,
color: colors.white,
fontweight: fontweight.bold
);
function _buildiconhelper = (icondata icondata){
return icon(icondata, color: colors.black, size: 15.0,);
};
return {
'home': {
'window': container(
width: windowwidth,
height: windowheight,
color: colors.purple,
child: center(
child: text(
'home',
style: textstyle
)
),
),
'icon': _buildiconhelper(icons.home)
},
'search': {
'window': container(
width: windowwidth,
height: windowheight,
child: stack(
children: [
aqua.shadow(
height: windowwidth,
width: windowheight,
colors: [
colors.green,
colors.teal
],
),
center(
child: text(
'search',
style: textstyle
)
),
],
)
),
'icon': _buildiconhelper(icons.search)
},
'settings': {
'window': container(
width: windowwidth,
height: windowheight,
color: colors.indigo,
child: center(
child: text(
'settings',
style: textstyle
)
),
),
'icon': _buildiconhelper(icons.settings)
}
};
}
}
Comments are closed.