@@ -19,11 +19,7 @@ import 'package:bertqa/ml/qa_client.dart';
1919import 'package:flutter/material.dart' ;
2020
2121class QaDetail extends StatefulWidget {
22- const QaDetail (
23- {super .key,
24- required this .title,
25- required this .content,
26- required this .questions});
22+ const QaDetail ({super .key, required this .title, required this .content, required this .questions});
2723
2824 final String title;
2925 final String content;
@@ -66,8 +62,7 @@ class _QaDetailState extends State<QaDetail> {
6662 if (! trimQuestion.endsWith ("?" )) {
6763 trimQuestion += "?" ;
6864 }
69- List <QaAnswer > answers =
70- await _qaClient.runInference (trimQuestion, widget.content);
65+ List <QaAnswer > answers = await _qaClient.runInference (trimQuestion, widget.content);
7166 // Highlight the answer here
7267 _highlightAnswer (answers.first);
7368 }
@@ -115,36 +110,15 @@ class _QaDetailState extends State<QaDetail> {
115110 style: Theme .of (context).textTheme.bodyMedium,
116111 )
117112 : RichText (
118- text: TextSpan (
119- style: Theme .of (context).textTheme.bodyMedium,
120- children: [
121- if (_answerIndex > 0 )
122- TextSpan (
123- text: widget.content
124- .substring (0 , _answerIndex)),
125- TextSpan (
126- style: TextStyle (
127- background: Paint ()
128- ..color = Colors .yellow),
129- text: widget.content.substring (_answerIndex,
130- _answerIndex + _qaAnswer! .text.length)),
131- if ((_answerIndex + _qaAnswer! .text.length) <
132- widget.content.length)
133- TextSpan (
134- text: widget.content.substring (
135- _answerIndex + _qaAnswer! .text.length,
136- widget.content.length))
137- ]),
113+ text: TextSpan (style: Theme .of (context).textTheme.bodyMedium, children: [
114+ if (_answerIndex > 0 ) TextSpan (text: widget.content.substring (0 , _answerIndex)),
115+ TextSpan (style: TextStyle (background: Paint ()..color = Colors .yellow), text: widget.content.substring (_answerIndex, _answerIndex + _qaAnswer! .text.length)),
116+ if ((_answerIndex + _qaAnswer! .text.length) < widget.content.length) TextSpan (text: widget.content.substring (_answerIndex + _qaAnswer! .text.length, widget.content.length))
117+ ]),
138118 ))),
139119 Container (
140120 padding: const EdgeInsets .all (16 ),
141- decoration: BoxDecoration (color: Colors .white, boxShadow: [
142- BoxShadow (
143- color: Colors .grey.withOpacity (0.5 ),
144- spreadRadius: 2 ,
145- blurRadius: 5 ,
146- offset: const Offset (0 , 3 ))
147- ]),
121+ decoration: BoxDecoration (color: Colors .white, boxShadow: [BoxShadow (color: Colors .grey.withValues (alpha: 0.5 ), spreadRadius: 2 , blurRadius: 5 , offset: const Offset (0 , 3 ))]),
148122 // color: Colors.white,
149123 child: Column (
150124 children: [
@@ -157,8 +131,7 @@ class _QaDetailState extends State<QaDetail> {
157131 child: ListView .separated (
158132 shrinkWrap: true ,
159133 scrollDirection: Axis .horizontal,
160- separatorBuilder: (BuildContext context, int index) =>
161- const Divider (
134+ separatorBuilder: (BuildContext context, int index) => const Divider (
162135 indent: 16 ,
163136 ),
164137 itemCount: widget.questions.length,
@@ -175,9 +148,7 @@ class _QaDetailState extends State<QaDetail> {
175148 Expanded (
176149 child: TextField (
177150 controller: _controller,
178- decoration: const InputDecoration (
179- border: UnderlineInputBorder (),
180- labelText: "Text query" ),
151+ decoration: const InputDecoration (border: UnderlineInputBorder (), labelText: "Text query" ),
181152 onChanged: (text) {
182153 setState (() {
183154 _currentQuestion = text;
@@ -194,9 +165,7 @@ class _QaDetailState extends State<QaDetail> {
194165 _answerQuestion ();
195166 }
196167 : null ,
197- style: ElevatedButton .styleFrom (
198- disabledBackgroundColor: Colors .grey,
199- backgroundColor: const Color (0xFFFFA800 )),
168+ style: ElevatedButton .styleFrom (disabledBackgroundColor: Colors .grey, backgroundColor: const Color (0xFFFFA800 )),
200169 child: const Icon (
201170 Icons .east,
202171 color: Colors .white,
0 commit comments