Create personal Apis host with the use of mixins
Last active
September 22, 2022 15:34
-
-
Save singlesoup/5c24744f390f78c9841a9793889f5bf4 to your computer and use it in GitHub Desktop.
Mixins - 2
This file contains 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 'dart:developer' as devtools show log; | |
import 'dart:io'; | |
import 'package:meta/meta.dart'; | |
import 'dart:convert'; | |
extension Log on Object { | |
void log() => devtools.log(toString()); | |
} | |
extension getOnUri on Object{ | |
Future<HttpClientResponse> getUrl(String url) | |
=> HttpClient() | |
.getUrl(Uri.parse(url),) | |
.then((request)=> request.close()); | |
} | |
mixin CanMakeGetCall{ | |
String get url; | |
@useResult // imp meta tag which gives warning if result returned is not used | |
Future<String> getString() | |
=> getUrl(url) | |
.then((resp) => resp.transform(utf8.decoder).join()); | |
} | |
void testIt() {} | |
void main() { | |
'Hello'.log(); | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
testIt(); | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: Colors.amberAccent, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Text( | |
'Hello, World!', | |
style: | |
Theme.of(context).textTheme.headline5!.copyWith(color: Colors.black), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment