I have an API that include 17.000 words. I show this words on a flipcard on the screen. When the back of card, I want translated versions of these words. How can I do that? Do I use Yandex translate API? I tried to use Google translate API but it couldn't work.
Future<dynamic> fetchAPIdata() async {
//API cagrisi
try {
final url = Uri.parse('https://random-word-api.herokuapp.com/all');
final response = await http.get(url);
if (response.statusCode == 200) {
final responseData = json.decode(response.body);
if (responseData is List<dynamic>?) {
data.addAll(
responseData?.map((e) => e?.toString() ?? "").toList() ?? []);
word_box.addAll(data);
isBusy.value = false;
}
} else {
return null;
}
} catch (_) {
isBusy.value = false;
}
}
child: CardSwiper(
backCardOffset: const Offset(0, 27.0),
padding: EdgeInsets.zero,
numberOfCardsDisplayed: 3,
isLoop: true,
onEnd: () {
controller.listNext();
},
onSwipe:
(previousIndex, currentIndex, direction) {
index = currentIndex ?? previousIndex;
return Future.value(true);
},
controller: controller.cardSwiperController,
cardsCount: controller.list.length,
cardBuilder: (context, index) {
return FlipCard(
controller: controller.flipCardController,
side: CardSide.FRONT,
direction: FlipDirection.HORIZONTAL,
back: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(20.0)),
color: UIColors.primary400,
child: Container(
alignment: Alignment.center,
child: Text( '${controller.list[index]}'.trParams({
'words': controller.list[index],
}),
style: UIStyle.h1,
),
),
),
front: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(20.0)),
color: UIColors.primary400,
child: Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
controller.list[index],
style: UIStyle.h1,
),
Text('TEXT',
style: UIStyle.sh2_medium
.copyWith(
color:
UIColors.grey100)),
],
),
),
),
);
},
),
body: Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
SizedBox(height: 50),
Text(
'textArea'.tr(),
textAlign: TextAlign.center,
style: TextStyle(fontSize: 35),
),
OutlineButton(
onPressed: () {
translator.setNewLanguage(
context,
newLanguage: translator.currentLanguage == 'ar' ? 'en' : 'ar',
remember: true,
restart: true,
);
},
child: Text('buttonTitle'.tr()),
),
],
),
),
I tried this but it couldn't work so I deleted code. I have button and when I click the button card is flipping then must show translated version of word.