Skip to content

Instantly share code, notes, and snippets.

View florent37's full-sized avatar

Florent CHAMPIGNY florent37

View GitHub Profile
SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 48),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_currentMovie.title.replaceAll(" ", "\n").toUpperCase(),
style: TextStyle(
shadows: [
Shadow(
//On Android
class MainActivity() : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, "samples.flutter.io/battery").setMethodCallHandler { call, result ->
if (call.method == "getBatteryLevel") {
val batteryLevel = getBatteryLevel()
//From Flutter
Future<String> _getBatteryLevel() async {
String batteryLevel;
try {
//invoke the platform specific code
//wait for the result
final int result = await platform.invokeMethod('getBatteryLevel');
batteryLevel = 'Battery level at $result % .';
} on PlatformException catch (e) {
batteryLevel = "Failed to get battery level: '${e.message}'.";
class SearchViewModel(application: Application) : AndroidViewModel(application), CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main
private val mutableViewState = MutableLiveData<SearchViewState>()
val viewState : LiveData<SearchViewState> = mutableViewState
private val repository by lazy {
mainApplication.omdbRepository
interface OMDBApi {
@GET("/")
fun searchMovies(@Query("s") name: String, @Query("apiKey") apikey: String) : Deferred<SearchResponse>
companion object {
val apiKey = "YOUR_KEY"
val baseUrl = "http://www.omdbapi.com/"
}
}
class Movie {
@SerializedName("Title")
var title : String = ""
@SerializedName("Year")
var year : String = ""
@SerializedName("ImdbID")
var imdbID : String = ""
@SerializedName("Type")
var type : String = ""
@SerializedName("Poster")
part 'Movie.g.dart';
@JsonSerializable()
class Movie {
@JsonKey(name: "Title")
final String title;
@JsonKey(name: "Year")
final String year;
@JsonKey(name: "ImdbID")
final String imdbID;
class OmdbRepository {
final apiKey = "my_key";
const OmdbRepository();
Future<List<Movie>> searchMovies(String byName) async {
final response = await http.get('http://www.omdbapi.com/?s=$byName&apikey=$apiKey');
final jsonValue = json.decode(response.body);
return SearchResponse.fromJson(jsonValue).movies;
}
}
class SearchViewModel {
//Stream <=> MediatorLiveData
final StreamController<SearchViewState> _viewModelController = StreamController();
final OmdbRepository _repository;
//Stream <=> LiveData
Stream<SearchViewState> get viewState => _viewModelController.stream;
//constructor
SearchViewModel(this._repository) {
User use = molki(User.class)
.given(user -> user.getName()).willReturn(3)
.given(user -> user.getFirstName()).willReturn(4)