flutter_agnes 1.0.11 flutter_agnes: ^1.0.11 copied to clipboard
Widgets.
import 'package:flutter/material.dart';
import 'package:flutter_agnes/flutter_agnes.dart';
import 'package:flutter_agnes/src/widgets/dialogs/simple_dialog.dart';
import 'package:flutter_agnes/src/widgets/share/outline_button_widget.dart';
import 'package:asuka/asuka.dart' as asuka;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Agnes Flutter',
theme: ThemeData(primarySwatch: Colors.blue, accentColor: Colors.white),
builder: asuka.builder,
home: MyHomePage(title: 'Agnes Flutter'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
TextEditingController textEditingController = TextEditingController();
final _formKey = GlobalKey<FormState>();
TabController _tabController;
String city;
@override
void initState() {
super.initState();
city = cities[0];
_tabController = TabController(length: 3, vsync: this);
}
List cities = [
'Rio de Janeiro',
'Pará',
'São Paulo',
'Tocantins'
];
void _onPressed() async {
bool result = await asuka.showDialog<bool>(
barrierDismissible: false,
builder: (context) => SimpleDialogFuture(
width: 300,
showMessagePositive: true,
loadingMessage: 'Aguarde...',
future: _getCep(),
),
);
print('SimpleDialogFuture: ${result.toString()}');
}
void _onPressedButtonWidget() async {
bool result = await asuka.showDialog<bool>(
barrierDismissible: false,
builder: (context) => SimpleDialogWidget(
width: 300,
title: 'Message',
messageModel: MessageModel(code: -1, success: false, message: 'Falha!'),
onPressed: () => Navigator.pop(context),
));
print('SimpleDialogFuture: ${result.toString()}');
}
Widget _listPaginatedWidget() => ListPaginatedWidget.builder(
listType: ListType.LIST_VIEW,
loadFuture: pagedListLoad,
itemCount: (Page response) => response.payloads.length,
totalPages: (Page response) => response.totalPage,
pageItems: (Page response) => response.payloads,
itemsBuilder: (value, int index) {
Payload payload = value;
return ListTile(
title: Text(payload.item),
);
},
loadingWidgetBuilder: () =>
WaitingResult(label: 'Aguarde...', colorCircular: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor),
noneResult: NoneResult(
label: 'Nenhum resultado enconrtado!', background: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
bottom: TabBar(
controller: _tabController,
tabs: const <Widget>[
Tab(
icon: Icon(Icons.category),
text: 'Widgets and Dialogs',
),
Tab(
icon: Icon(Icons.pages),
text: 'Paged list',
),
Tab(
icon: Icon(Icons.list),
text: 'Future list',
),
],
),
),
body: TabBarView(
controller: _tabController,
children: <Widget>[
SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(top: 20, left: 20, right: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
OutlineButtonWidget(
title: 'Simple Dialog Future',
icon: Icons.check,
width: double.maxFinite,
onPressed: _onPressed,
),
ButtonWidget(
label: 'Simple Dialog Widget',
height: 50,
elevation: 15,
alignment: Alignment.center,
borderRadius: 2,
width: double.maxFinite,
icon: Icons.check,
color: Theme.of(context).accentColor,
background: Theme.of(context).primaryColor,
onPressed: _onPressedButtonWidget),
ButtonWidget(
margin: EdgeInsets.only(top: 10),
texts: [
TextSpan(
text: 'Teste?',
style: new TextStyle(
color: Colors.black,
),
),
TextSpan(
text: ' Clique aqui.',
style: new TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
),
],
height: 50,
background: Colors.transparent,
elevation: 0,
alignment: Alignment.center,
borderRadius: 2,
width: double.maxFinite,
icon: Icons.check,
color: Theme.of(context).primaryColor,
onPressed: () {
asuka.showSnackBar(SnackBar(
behavior: SnackBarBehavior.floating,
content: Text('Teste realizado com sucesso!'),
action: SnackBarAction(label: 'Ok', textColor: Colors.white, onPressed: () => print('ok'))));
}),
Row(
children: [
Expanded(
child: TextFormFieldWidget(
icon: Icons.message,
controller: textEditingController,
labelText: 'Text clip oval',
)),
Expanded(
flex: 0,
child: ClipOvalWidget(
icon: Icons.check,
color: Colors.white,
background: Theme.of(context).primaryColor,
onTap: () {
setState(() {
textEditingController.text = 'Test clip oval';
FocusScope.of(context).requestFocus(new FocusNode());
});
}))
],
),
DropdownMenuItemCustomWidget<String>(
title: 'Cities',
value: city,
items: cities.map((value) => DropdownMenuItem<String>(
child: Text(value),
value: value,
)).toList(),
prefixIcon: Icons.swap_horiz,
onChanged: (String value) {
setState(() {
city = cities.lastWhere((element) => element == value);
print(city);
});
},
),
Row(
children: [
Expanded(
child: Form(
key: _formKey,
child: TextFormFieldNoneBorder(
title: 'Label',
hintText: 'hint text',
icon: Icons.report,
colorIcon: Colors.grey,
cursorColor: Colors.grey,
suffixIcon: IconButton(
icon: Icon(Icons.check_circle),
onPressed: () {},
),
onFieldSubmitted: (value) {
if (_formKey.currentState.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Dados ok!')),
);
}
},
validator: (value) {
if (value == null || value.isEmpty) return '*O campo é obrigatório';
return null;
},
))),
],
),
],
),
),
),
Container(
padding: EdgeInsets.only(top: 5, left: 20, right: 20, bottom: 20),
child: Card(
elevation: 20,
margin: EdgeInsets.only(top: 20),
child: Container(
padding: EdgeInsets.all(10),
width: double.maxFinite,
height: 300,
child: Column(
children: [
Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: Text(
'Example of paged list',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
Expanded(
child: _listPaginatedWidget(),
)
],
)),
),
),
Container(
padding: EdgeInsets.only(top: 5, left: 20, right: 20, bottom: 20),
child: Card(
elevation: 20,
margin: EdgeInsets.only(top: 20),
child: Container(
padding: EdgeInsets.all(10),
height: 400,
child: Column(
children: [
Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: Text(
'Example future list',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
Expanded(
child: FutureBuilderWidget(
loadFuture: _getUsers(),
builderWidget: (item, index) {
User user = item;
return ListTile(
title: Text(user.username),
subtitle: Text('${user.toString()}'),
isThreeLine: true,
);
},
),
)
],
)),
)),
],
),
);
}
}
Future<Page> pagedListLoad(int currentPage) async {
List<Payload> list = [
Payload(page: 1, item: 'Item 1 '),
Payload(page: 1, item: 'Item 2'),
Payload(page: 1, item: 'Item 3'),
Payload(page: 1, item: 'Item 4'),
Payload(page: 1, item: 'Item 5'),
Payload(page: 1, item: 'Item 6'),
Payload(page: 1, item: 'Item 7'),
Payload(page: 1, item: 'Item 8'),
Payload(page: 2, item: 'Item 9'),
Payload(page: 2, item: 'Item 10'),
Payload(page: 2, item: 'Item 11'),
Payload(page: 2, item: 'Item 12'),
Payload(page: 2, item: 'Item 13'),
Payload(page: 2, item: 'Item 14'),
Payload(page: 2, item: 'Item 15'),
Payload(page: 3, item: 'Item 16'),
Payload(page: 3, item: 'Item 17'),
Payload(page: 3, item: 'Item 18'),
Payload(page: 3, item: 'Item 19'),
Payload(page: 3, item: 'Item 20'),
Payload(page: 3, item: 'Item 21'),
Payload(page: 3, item: 'Item 22'),
];
List modelTests = list.where((element) => element.page == currentPage).toList();
Page page = Page(currentPage: currentPage, totalPage: 3, payloads: modelTests);
await Future.delayed(const Duration(milliseconds: 2000));
return page;
}
Future<MessageModel> _getCep() async {
try {
var requestHelpers = new RequestHelpers<Cep>(objectCreator: () => Cep());
Cep cep = await requestHelpers.getRequest('https://viacep.com.br/ws/01001000/json/');
return MessageModel(code: 1, success: true, message: cep.toString());
} catch (e) {
print(e);
return MessageModel(code: -1, success: false, message: e.toString());
}
}
Future<List<User>> _getUsers() async {
try {
var requestHelpers = new RequestHelpers<Users>(objectCreator: () => Users());
Users users = await requestHelpers.getRequest('https://jsonplaceholder.typicode.com/users');
return users.users;
} catch (e) {
print(e);
throw (e);
}
}
class Payload {
final int page;
final String item;
const Payload({this.page, this.item});
}
class Page {
final int totalPage;
final int currentPage;
final List<Payload> payloads;
const Page({this.totalPage, this.currentPage, this.payloads});
}
class Cep extends IModel {
String cep;
String logradouro;
String complemento;
String bairro;
String localidade;
String uf;
String ibge;
String gia;
String ddd;
String siafi;
Cep({
this.cep,
this.logradouro,
this.complemento,
this.bairro,
this.localidade,
this.uf,
this.ibge,
this.gia,
this.ddd,
this.siafi,
});
Map<String, dynamic> toJson() => {
"cep": cep,
"logradouro": logradouro,
"complemento": complemento,
"bairro": bairro,
"localidade": localidade,
"uf": uf,
"ibge": ibge,
"gia": gia,
"ddd": ddd,
"siafi": siafi,
};
@override
//fromJson(Map<String, dynamic> json) {
fromJson(dynamic json) {
cep = json["cep"];
logradouro = json["logradouro"];
complemento = json["complemento"];
bairro = json["bairro"];
localidade = json["localidade"];
uf = json["uf"];
ibge = json["ibge"];
gia = json["gia"];
ddd = json["ddd"];
siafi = json["siafi"];
}
@override
String toString() {
return 'Cep: $cep\nLogradouro: $logradouro\nComplemento: $complemento\n'
'Bairro: $bairro\nLocalidade: $localidade\nUF: $uf\nIBGE: $ibge\nGIA: $gia\nDDD: $ddd\nSIAFI: $siafi';
}
}
class Users extends IModel {
List<User> users;
Users({this.users});
@override
fromJson(dynamic json) {
users = List<User>.from(json.map((x) => User.fromJson(x)));
}
@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
}
}
class User extends IModel {
int id;
String name;
String username;
String email;
String phone;
String website;
User({
this.id,
this.name,
this.username,
this.email,
this.phone,
this.website,
});
factory User.fromJson(Map<String, dynamic> json) => User(
id: json["id"],
name: json["name"],
username: json["username"],
email: json["email"],
phone: json["phone"],
website: json["website"],
);
@override
fromJson(dynamic json) {
id = json["id"];
name = json["name"];
username = json["username"];
email = json["email"];
phone = json["phone"];
website = json["website"];
}
@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
}
@override
String toString() {
return '$name\n$email\n$phone\n$website';
}
}