Page MenuHomec4science

may.dart.bak
No OneTemporary

File Metadata

Created
Sat, Nov 9, 05:35

may.dart.bak

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:provider/src/provider.dart';
import 'package:http/http.dart' as http;
class Intrests extends StatefulWidget {
@override
IntrestsState createState() => new IntrestsState();
}
class IntrestsState extends State<Intrests> {
Map<String, bool?> values = {
'Music': false,
'Pets & Animals': false,
'Sports': false,
'Travel & Events': false,
'People & Blogs': false,
'News & Politics': false,
};
@override
Widget build(BuildContext context) {
final firebaseUser = context.watch<User?>();
String? email_id = firebaseUser!.email;
return new Scaffold(
appBar: new AppBar(title: new Text('CheckboxListTile demo')),
body:
Column(
children: [
const SizedBox(height: 10,),
Text(' please add your preferences here'),
const SizedBox(height: 10,),
Expanded(child:
new ListView(
children: values.keys.map((String key) {
return new CheckboxListTile(
title: new Text(key),
value: values[key],
onChanged: (bool? value) {
setState(() {
values[key] = value;
});
},
);
}).toList(),
),
),
const SizedBox(height: 20,),
Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width -50,
height: 50,
child: buildSubmitButton(context,email_id!),
),
const SizedBox(height: 20,)
]
)
);
}
Widget buildSubmitButton(BuildContext context,email) {
return Align(
alignment: Alignment.bottomCenter,
child: MaterialButton(onPressed: () {
onSubmitTapped( context,email);
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(17)),
elevation:3,
height: 50,
minWidth: MediaQuery.of(context).size.width - 32 ,
padding: const EdgeInsets.all(16),
color: Colors.red,
child: Text('Submit', style: TextStyle(color: Colors.black),),
)
);
}
void onSubmitTapped(BuildContext context,email) async {
//Do whatever you want here
String str1,str2,str3,str4,str5,str6,str7,str8;
if(values["Music"] == true)
str1 ="music";
else str1="0";
if(values["Pets & Animals"] == true)
str2 ="pets and animals";
else str2="0";
if(values["Sports"] == true)
str3 ="sports";
else str3="0";
if(values["Travel & Events"] == true)
str4 ="travel and events";
else str4="0";
if(values["People & Blogs"] == true)
str5 ="people and blogs";
else str5="0";
if(values["news & politics"] == true)
str6 ="travel and events";
str8="0";
str7 = "0";
str6="0";
String pref_str = str1+","+str2+","+str3+","+str4+","+str5+","+str6+","+str7+","+str8;
String user_email = email;
String server_str = user_email+"+"+pref_str;
// var url = "http://10.0.2.2:5000/prefs/"+server_str;
var url = "https://raniarecommender.a2hosted.com/pythonapp/prefs/"+server_str;
var response = await http
.get(Uri.parse(url), headers: {
"Access-Control-Allow-Origin": "*"
});
var x = response.body;
print(x);
Navigator.pushNamed(context, '/homeScreen');
}
}
void main() {
runApp(new MaterialApp(home: new Intrests(), debugShowCheckedModeBanner: false));
}

Event Timeline