Commit 5d04e799 authored by madushanmac's avatar madushanmac

created option page

parent 81a12eb3
import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'dart:convert';
import 'package:http/http.dart'as http;
class Options extends StatefulWidget {
const Options({ Key? key }) : super(key: key);
State<Options> createState() => _OptionsState();
}
class _OptionsState extends State<Options> {
late List users;
bool loading = false;
Future<String> getUsers() async {
setState(() => loading = true);
var url = Uri.parse('https://jsonplaceholder.typicode.com/users');
var response =
await http.get(url);
setState(() => users = json.decode(response.body.toString()));
setState(() => loading = false);
return 'success';
}
@override
void dispose() {
super.dispose();
}
@override
void initState() {
super.initState();
getUsers();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 55,
),
//app navigation bar
Padding(
padding: const EdgeInsets.only(left: 25.0),
child: GestureDetector(
child: Container(
height: 50,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(12),
color: Color.fromARGB(255, 97, 96, 96)),
child: Image.asset(
'lib/icons/back.png',
),
),
onTap: (){
Navigator.pop(context);
print('go back pressed');
},
),
),
const SizedBox(height: 20,),
Container(
color: Colors.grey,
height: 40,
child: Center(child: Text('Reports ',style: TextStyle(fontSize: 30.0,fontWeight: FontWeight.bold),))
),
const SizedBox(height: 50,),
Column(
children: <Widget>[
loading
? const Center(
child: CircularProgressIndicator(),
heightFactor: 12.0,
)
: Expanded(
child: ListView.builder(
itemCount: users == null ? 0 : users.length,
itemBuilder: (BuildContext context, int index) {
var name = users[index]['name'];
var email = users[index]['email'];
return Column(
children: <Widget>[
ListTile(
leading: const CircleAvatar(
child: Icon(Icons.account_box),
),
title: Text(name),
subtitle: Text(email),
),
const Divider(),
],
);
}),
),
],
)
],
)
);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment