Skip to content

Instantly share code, notes, and snippets.

View defensive-wizard's full-sized avatar

Defen Wizard defensive-wizard

View GitHub Profile
@defensive-wizard
defensive-wizard / cached_network_image.dart
Created September 21, 2021 06:44
Example of cached_network_image
import 'package:cached_network_image/cached_network_image.dart';
CachedNetworkImage(
imageUrl: "http://via.placeholder.com/350x150",
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
);
@defensive-wizard
defensive-wizard / url_launcher.dart
Created September 21, 2021 06:54
example of url launcher
Future<Null> _launchInBrowser(String url) async {
if (await canLaunch(url)) {
await launch(url, forceSafariVC: false, forceWebView: false);
} else {
throw 'Could not launch $url';
}
}
// or
Text(
'This is Google Fonts',
style: GoogleFonts.lato(
textStyle: Theme.of(context).textTheme.headline4,
fontSize: 48,
fontWeight: FontWeight.w700,
fontStyle: FontStyle.italic,
),
),
import 'package:http/http.dart' as http;
var client = http.Client();
try {
var uriResponse = await client.post(Uri.parse('https://example.com/whatsit/'),
var data =await client.get(uriResponse);
print(json.decode(data));
} finally {
FaIcon(FontAwesomeIcons.gamepad)
final PaletteGenerator paletteGenerator =
await PaletteGenerator.fromImageProvider(
image,
);
// 'Dominant',
paletteGen.dominantColor?.color
// 'Light Vibrant',
paletteGen.lightVibrantColor?.color
// 'Vibrant',
paletteGen.vibrantColor?.color
// 'Dark Vibrant',
paletteGen.darkVibrantColor?.color
// 'Light Muted',
paletteGen.lightMutedColor?.color
import 'package:palette_generator/palette_generator.dart';
class FetchColorFromImage{
Future<Color?> getColor(ImageProvider image>{
final PaletteGenerator paletteGenerator =
await PaletteGenerator.fromImageProvider(
image,
);
return paletteGenrator.dominantColor!.color;
final repo= FetchColorsFromImage();
// i have used networkImage you can use any ImageProvider class for it
var image=NetworkImage(<imageurl>);
Color backgroundColor =Colors.black;
void initState(){
getColors();