Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #6 [Null safety] #8

Merged
merged 4 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ We have also added complex animations.
We have added support and contact helplines.
We have added medicines database and notification.
We have added new illustrations.
We have added null-safety.

## Challenges we ran into
Complex yet engaging UI was needed, to lift the mood of the user so that they feel good after using the app. So it was a challenge to actually create this UI with excellent user experience.
Expand Down
220 changes: 110 additions & 110 deletions lib/dialog_flow.dart
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
import 'package:flutter/material.dart';
// import 'package:flutter/material.dart';

import 'package:flutter_dialogflow/dialogflow_v2.dart';
import 'package:google_fonts/google_fonts.dart';
// import 'package:flutter_dialogflow/dialogflow_v2.dart';
// import 'package:google_fonts/google_fonts.dart';

import 'facts_message.dart';
// import 'facts_message.dart';

class CuristAssistant extends StatefulWidget {
CuristAssistant({Key key}) : super(key: key);
// class CuristAssistant extends StatefulWidget {
// CuristAssistant({Key key}) : super(key: key);

@override
_CuristAssistantState createState() => new _CuristAssistantState();
}
// @override
// _CuristAssistantState createState() => new _CuristAssistantState();
// }

class _CuristAssistantState extends State<CuristAssistant> {
final List<Facts> messageList = <Facts>[];
final TextEditingController _textController = new TextEditingController();
// class _CuristAssistantState extends State<CuristAssistant> {
// final List<Facts> messageList = <Facts>[];
// final TextEditingController _textController = new TextEditingController();

Widget _queryInputWidget(BuildContext context) {
return Card(
color: Color(0xffffffff),
elevation: 0,
margin: EdgeInsets.all(10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30))),
child: Padding(
padding: const EdgeInsets.only(left: 12, right: 0),
child: Row(
children: <Widget>[
Flexible(
child: TextField(
controller: _textController,
onSubmitted: _submitQuery,
style: GoogleFonts.montserrat(),
decoration: InputDecoration.collapsed(
hintText: "Talk to Curist Assistant",
hintStyle: GoogleFonts.montserrat(),
),
),
),
Container(
child: IconButton(
icon: Icon(
Icons.send,
color: Color(0xFF76EAD7),
),
onPressed: () => _submitQuery(_textController.text)),
),
],
),
),
);
}
// Widget _queryInputWidget(BuildContext context) {
// return Card(
// color: Color(0xffffffff),
// elevation: 0,
// margin: EdgeInsets.all(10),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.circular(30))),
// child: Padding(
// padding: const EdgeInsets.only(left: 12, right: 0),
// child: Row(
// children: <Widget>[
// Flexible(
// child: TextField(
// controller: _textController,
// onSubmitted: _submitQuery,
// style: GoogleFonts.montserrat(),
// decoration: InputDecoration.collapsed(
// hintText: "Talk to Curist Assistant",
// hintStyle: GoogleFonts.montserrat(),
// ),
// ),
// ),
// Container(
// child: IconButton(
// icon: Icon(
// Icons.send,
// color: Color(0xFF76EAD7),
// ),
// onPressed: () => _submitQuery(_textController.text)),
// ),
// ],
// ),
// ),
// );
// }

void agentResponse(query) async {
_textController.clear();
AuthGoogle authGoogle = await AuthGoogle(
fileJson: "assets/health-assistant-a5445-8d571f0f6b24.json")
.build();
Dialogflow dialogFlow =
Dialogflow(authGoogle: authGoogle, language: Language.english);
AIResponse response = await dialogFlow.detectIntent(query);
Facts message = Facts(
text: response.getMessage() ??
CardDialogflow(response.getListMessage()[0]).title,
name: "Flutter",
type: false,
);
setState(() {
messageList.insert(0, message);
});
}
// void agentResponse(query) async {
// _textController.clear();
// AuthGoogle authGoogle = await AuthGoogle(
// fileJson: "assets/health-assistant-a5445-8d571f0f6b24.json")
// .build();
// Dialogflow dialogFlow =
// Dialogflow(authGoogle: authGoogle, language: Language.english);
// AIResponse response = await dialogFlow.detectIntent(query);
// Facts message = Facts(
// text: response.getMessage() ??
// CardDialogflow(response.getListMessage()[0]).title,
// name: "Flutter",
// type: false,
// );
// setState(() {
// messageList.insert(0, message);
// });
// }

void _submitQuery(String text) {
_textController.clear();
Facts message = new Facts(
text: text,
name: "Akshay",
type: true,
);
setState(() {
messageList.insert(0, message);
});
agentResponse(text);
}
// void _submitQuery(String text) {
// _textController.clear();
// Facts message = new Facts(
// text: text,
// name: "Akshay",
// type: true,
// );
// setState(() {
// messageList.insert(0, message);
// });
// agentResponse(text);
// }

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xff76EAD7),
appBar: AppBar(
centerTitle: true,
title: Text(
"Curist Assistant",
style: GoogleFonts.montserrat(
color: Colors.white, fontWeight: FontWeight.w600),
),
backgroundColor: Color(0xff76EAD7),
elevation: 0,
leading: IconButton(
icon: Icon(Icons.chevron_left),
onPressed: () {
Navigator.pop(context);
},
),
),
body: Column(children: <Widget>[
Flexible(
child: ListView.builder(
padding: EdgeInsets.all(8.0),
reverse: true, //To keep the latest messages at the bottom
itemBuilder: (_, int index) => messageList[index],
itemCount: messageList.length,
)),
_queryInputWidget(context),
]),
);
}
}
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// backgroundColor: Color(0xff76EAD7),
// appBar: AppBar(
// centerTitle: true,
// title: Text(
// "Curist Assistant",
// style: GoogleFonts.montserrat(
// color: Colors.white, fontWeight: FontWeight.w600),
// ),
// backgroundColor: Color(0xff76EAD7),
// elevation: 0,
// leading: IconButton(
// icon: Icon(Icons.chevron_left),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
// ),
// body: Column(children: <Widget>[
// Flexible(
// child: ListView.builder(
// padding: EdgeInsets.all(8.0),
// reverse: true, //To keep the latest messages at the bottom
// itemBuilder: (_, int index) => messageList[index],
// itemCount: messageList.length,
// )),
// _queryInputWidget(context),
// ]),
// );
// }
// }
12 changes: 6 additions & 6 deletions lib/facts_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:healthapp/main.dart' as main;
class Facts extends StatelessWidget {
Facts({this.text, this.name, this.type});

final String text;
final String name;
final bool type;
final String? text;
final String? name;
final bool? type;

List<Widget> botMessage(context) {
return <Widget>[
Expand All @@ -34,7 +34,7 @@ class Facts extends StatelessWidget {
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8.0),
child: Text(
text,
text!,
style: GoogleFonts.montserrat(
color: Color(0xFF393E46),
),
Expand Down Expand Up @@ -62,7 +62,7 @@ class Facts extends StatelessWidget {
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8.0),
child: Text(
text,
text!,
style: GoogleFonts.montserrat(color: Color(0xFF393E46)),
),
)),
Expand Down Expand Up @@ -91,7 +91,7 @@ class Facts extends StatelessWidget {
margin: const EdgeInsets.symmetric(vertical: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: this.type ? userMessage(context) : botMessage(context),
children: this.type! ? userMessage(context) : botMessage(context),
),
);
}
Expand Down
23 changes: 10 additions & 13 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:healthapp/activity.dart';
import 'package:healthapp/dialog_flow.dart';
import 'package:healthapp/exercise.dart';
import 'package:healthapp/main.dart' as main;
import 'package:healthapp/medicines.dart';
Expand Down Expand Up @@ -138,10 +137,10 @@ class _HomeState extends State<Home> {
],
),
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => CuristAssistant()));
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (context) => CuristAssistant()));
},
),
GestureDetector(
Expand Down Expand Up @@ -283,16 +282,15 @@ class _HomeState extends State<Home> {

class ActivityRings extends StatefulWidget {
const ActivityRings({
Key key,
Key? key,
}) : super(key: key);

@override
_ActivityRingsState createState() => _ActivityRingsState();
}

class _ActivityRingsState extends State<ActivityRings> {
Pedometer _pedometer;
StreamSubscription<int> _subscription;
late StreamSubscription<StepCount> _subscription;
int stepsToday = int.parse(main.prefs.get("stepsToday"));
@override
void initState() {
Expand All @@ -315,20 +313,19 @@ class _ActivityRingsState extends State<ActivityRings> {
}

void startListening() {
_pedometer = new Pedometer();
_subscription = _pedometer.pedometerStream.listen(_onData,
_subscription = Pedometer.stepCountStream.listen(_onData,
onError: _onError, onDone: _onDone, cancelOnError: true);
}

void stopListening() {
_subscription.cancel();
}

void _onData(int stepCountValue) async {
void _onData(StepCount stepCountValue) async {
setState(() {
stepsToday = stepCountValue;
stepsToday = stepCountValue.steps;
main.prefs.put("stepsToday", "$stepCountValue");
main.prefs.put("calToday", "${stepCountValue / 3}");
main.prefs.put("calToday", "${stepsToday / 3}");
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:healthapp/navmenu/menu_dashboard_layout.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';

Box prefs;
Directory dir;
late Box prefs;
Directory? dir;
void main() {
WidgetsFlutterBinding.ensureInitialized();
getApplicationDocumentsDirectory().then(
Expand Down
Loading