Skip to content

Instantly share code, notes, and snippets.

@it-one-mm
Last active June 26, 2021 18:54
Show Gist options
  • Save it-one-mm/a9166e2b07384f7079a76d81264b1aa4 to your computer and use it in GitHub Desktop.
Save it-one-mm/a9166e2b07384f7079a76d81264b1aa4 to your computer and use it in GitHub Desktop.
Flutter Movie App Snippet
import 'dart:io';
class AdHelper {
static String get bannerAdUnitId => Platform.isAndroid
? 'ca-app-pub-3940256099942544/6300978111'
: 'ca-app-pub-3940256099942544/2934735716';
static String get interstitialAdUnitId => Platform.isAndroid
? "ca-app-pub-3940256099942544/1033173712"
: "ca-app-pub-3940256099942544/4411468910";
static String get rewardedAdUnitId => Platform.isAndroid
? "ca-app-pub-3940256099942544/5224354917"
: "ca-app-pub-3940256099942544/1712485313";
}
import 'package:flutter/material.dart';
const InputDecoration kFormFieldInputDecoration = InputDecoration(
errorStyle: TextStyle(
color: Color(0xff69f0ae),
),
);
const InputDecoration kSearchInputDecoration = InputDecoration(
filled: true,
fillColor: Color(0xFF444444),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
borderSide: BorderSide.none,
),
);
class Episode {
final String id;
final String no;
final String seriesId;
final String seriesTitle;
final String key;
Episode({
this.id,
this.no,
this.seriesId,
this.seriesTitle,
this.key,
});
static const String noField = 'no';
static const String keyField = 'key';
static const String seriesIdField = 'seriesId';
static const String seriesTitleField = 'seriesTitle';
static const String createdField = 'created';
}
import 'package:flutter/material.dart';
class ImageTile extends StatelessWidget {
ImageTile({
this.imageUrl = 'https://via.placeholder.com/120x160.png',
this.title = '',
this.subTitle = '',
this.onEdit,
});
final String imageUrl;
final String title;
final String subTitle;
final Function onEdit;
@override
Widget build(BuildContext context) {
return ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
// 3 : 4
minWidth: 45,
minHeight: 60,
maxWidth: 60,
maxHeight: 80,
),
child: Image.network(
imageUrl,
fit: BoxFit.cover,
),
),
title: Text(title),
subtitle: Text(subTitle),
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: onEdit,
),
);
}
}
import 'dart:io';
class InternetHandler {
static const String host = 'example.com';
static Future<void> checkConnection({Function onSuccess, Function onError}) async {
try {
final result = await InternetAddress.lookup(host);
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
// Connected to the Internet
if (onSuccess != null) onSuccess();
}
} on SocketException {
// No Internet
if (onError != null) onError();
}
}
}
class Movie {
Movie({
this.id,
this.title,
this.imageUrl,
this.key,
this.genreId,
this.genreName,
});
final String id;
final String title;
final String imageUrl;
final String key;
final String genreId;
final String genreName;
static const String titleField = 'title';
static const String imageUrlField = 'imageUrl';
static const String keyField = 'key';
static const String genreIdField = 'genreId';
static const String genreNameField = 'genreName';
static const String createdField = 'created';
}
import 'package:flutter/material.dart' hide Router;
import '../models/movie.dart';
class MovieTile extends StatelessWidget {
MovieTile({@required this.movie});
final Movie movie;
@override
Widget build(BuildContext context) {
return ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
// 3 : 4
minWidth: 45,
minHeight: 60,
maxWidth: 60,
maxHeight: 80,
),
child: Image.network(
movie.imageUrl,
fit: BoxFit.cover,
),
),
title: Text(movie.title),
subtitle: Text(movie.genreName),
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: () async {},
),
);
}
}
import 'package:flutter/material.dart';
class MyTextFormField extends StatelessWidget {
MyTextFormField({
this.controller,
this.autocorrect = false,
this.autofocus = false,
this.textCapitalization = TextCapitalization.none,
this.decoration,
this.textInputAction,
this.keyboardType,
this.validator,
this.onChanged,
this.onFieldSubmitted,
});
final TextEditingController controller;
final bool autocorrect;
final bool autofocus;
final TextCapitalization textCapitalization;
final InputDecoration decoration;
final Function validator;
final TextInputAction textInputAction;
final TextInputType keyboardType;
final Function onChanged;
final Function onFieldSubmitted;
@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
autocorrect: autocorrect,
textCapitalization: textCapitalization,
autofocus: autofocus,
textInputAction: textInputAction,
keyboardType: keyboardType,
decoration: decoration,
onChanged: onChanged,
validator: validator,
onFieldSubmitted: onFieldSubmitted,
);
}
}
import 'dart:ui';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class PlatFormAwareDialog extends StatelessWidget {
PlatFormAwareDialog({
this.title = 'No title',
this.content = 'No Content',
this.contentWidget,
this.actions = const [],
});
final String title;
final String content;
final Widget contentWidget;
final List<Widget> actions;
@override
Widget build(BuildContext context) {
final imageFilter = ImageFilter.blur(sigmaX: 6, sigmaY: 6);
return Platform.isIOS
? BackdropFilter(
filter: imageFilter,
child: CupertinoAlertDialog(
title: Text(title),
content: content == 'No Content' ? contentWidget : Text(content),
actions: [
...actions,
],
),
)
: BackdropFilter(
filter: imageFilter,
child: AlertDialog(
title: Text(title),
content: content == 'No Content' ? contentWidget : Text(content),
actions: [
...actions,
],
),
);
}
}
class ProgressHUD extends StatelessWidget {
final Widget child;
final bool inAsyncCall;
final double opacity;
final Color color;
final Animation<Color> valueColor;
ProgressHUD({
Key key,
@required this.child,
@required this.inAsyncCall,
this.opacity = 0.3,
this.color = Colors.grey,
this.valueColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
List<Widget> widgetList = [];
widgetList.add(child);
if (inAsyncCall) {
final modal = Stack(
children: [
Opacity(
opacity: opacity,
child: ModalBarrier(dismissible: false, color: color),
),
Center(
child: CircularProgressIndicator(
valueColor: valueColor,
),
),
],
);
widgetList.add(modal);
}
return Stack(
children: widgetList,
);
}
}
class Series {
final String id;
final String title;
final String description;
final String imageUrl;
final String genreId;
final String genreName;
Series({
this.id,
this.title,
this.description,
this.imageUrl,
this.genreId,
this.genreName,
});
static const String titleField = 'title';
static const String imageUrlField = 'imageUrl';
static const String descriptionField = 'description';
static const String genreIdField = 'genreId';
static const String genreNameField = 'genreName';
}
import 'package:flutter/widgets.dart';
class SpinKitDoubleBounce extends StatefulWidget {
const SpinKitDoubleBounce({
Key key,
this.color,
this.size = 50.0,
this.itemBuilder,
this.duration = const Duration(milliseconds: 2000),
this.controller,
}) : assert(
!(itemBuilder is IndexedWidgetBuilder && color is Color) &&
!(itemBuilder == null && color == null),
'You should specify either a itemBuilder or a color'),
assert(size != null),
super(key: key);
final Color color;
final double size;
final IndexedWidgetBuilder itemBuilder;
final Duration duration;
final AnimationController controller;
@override
_SpinKitDoubleBounceState createState() => _SpinKitDoubleBounceState();
}
class _SpinKitDoubleBounceState extends State<SpinKitDoubleBounce>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _animation;
@override
void initState() {
super.initState();
_controller = (widget.controller ??
AnimationController(vsync: this, duration: widget.duration))
..addListener(() => setState(() {}))
..repeat(reverse: true);
_animation = Tween(begin: -1.0, end: 1.0)
.animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: Stack(
children: List.generate(2, (i) {
return Transform.scale(
scale: (1.0 - i - _animation.value.abs()).abs(),
child: SizedBox.fromSize(
size: Size.square(widget.size), child: _itemBuilder(i)),
);
}),
),
);
}
Widget _itemBuilder(int index) => widget.itemBuilder != null
? widget.itemBuilder(context, index)
: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle, color: widget.color.withOpacity(0.6)));
}
import 'package:flutter/material.dart';
import 'package:flushbar/flushbar.dart'; // require flushbar package
class UIHelper {
static void _buildFlushbar(BuildContext context,
{String message, IconData icon, Color color}) {
Flushbar(
flushbarPosition: FlushbarPosition.TOP,
flushbarStyle: FlushbarStyle.FLOATING,
message: message ?? '',
icon: Icon(
icon ?? Icons.done,
size: 28.0,
color: color ?? Colors.green[300],
),
duration: Duration(seconds: 3),
leftBarIndicatorColor: color ?? Colors.green[300],
)..show(context);
}
static void showSuccessFlushbar(BuildContext context, String message) {
_buildFlushbar(context, message: message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment