Created
March 16, 2020 06:42
-
-
Save ShaiqAhmedkhan/31bc8d37978966e38480f1cd8c3e109a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:translator/translator.dart'; | |
void main() | |
{ | |
runApp( | |
MaterialApp( | |
theme: ThemeData( | |
primaryColor: Colors.red[500], | |
), | |
home: App(), | |
) | |
); | |
} | |
class App extends StatefulWidget { | |
@override | |
_AppState createState() => _AppState(); | |
} | |
class _AppState extends State<App> { | |
GoogleTranslator translator = new GoogleTranslator(); | |
String out; | |
final lang=TextEditingController(); | |
void trans() | |
{ | |
translator.translate(lang.text, to: 'fr') | |
.then((output) | |
{ | |
setState(() { | |
out=output; | |
}); | |
print(out); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Google Transalate"), | |
), | |
body: Container( | |
child: Center( | |
child: Column( | |
children: <Widget>[ | |
Card( | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: <Widget>[ | |
Text("English",style: TextStyle(fontSize: 17,color: Colors.red),), | |
Icon(Icons.swap_horiz), | |
Text("French",style: TextStyle(fontSize: 17,color: Colors.red),), | |
], | |
), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.only(left:10.0,right: 10), | |
child: TextField( | |
controller: lang, | |
), | |
), | |
MaterialButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(12), | |
), | |
color: Colors.orange, | |
child: Text("Press "), | |
onPressed: () | |
{ | |
trans(); | |
}, | |
), | |
SizedBox(height: 10,), | |
Text(out.toString(),style: TextStyle(fontSize: 18),) | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment