Skip to content

Instantly share code, notes, and snippets.

@suragch
suragch / page_manager.dart
Created Apr 23, 2021
Steaming audio in Flutter with Just Audio (state)
View page_manager.dart
import 'package:flutter/material.dart';
class PageManager {
final progressNotifier = ValueNotifier<ProgressBarState>(
ProgressBarState(
current: Duration.zero,
buffered: Duration.zero,
total: Duration.zero,
),
);
@suragch
suragch / main.dart
Created Apr 23, 2021
Steaming audio in Flutter with Just Audio (setup)
View main.dart
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
import 'package:flutter/material.dart';
import 'page_manager.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
@suragch
suragch / main.dart
Last active Apr 22, 2021
Playing short audio clips in Flutter with Just Audio (setup)
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@suragch
suragch / service_locator.dart
Created Apr 10, 2021
Minimalist state management: Timer tutorial: get_it
View service_locator.dart
import 'package:get_it/get_it.dart';
import 'timer_serice/timer_service.dart';
import '../timer_page/timer_page_manager.dart';
final getIt = GetIt.instance;
void setupGetIt() {
// state management layer
getIt.registerLazySingleton<TimerPageManager>(() => TimerPageManager());
@suragch
suragch / main.dart
Created Apr 10, 2021
Minimalist state management: Timer tutorial: timer page UI
View main.dart
import 'package:flutter/material.dart';
import 'timer_page/timer_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
@suragch
suragch / timer_page.dart
Created Apr 9, 2021
Minimalist state management: Timer tutorial: timer page UI
View timer_page.dart
import 'package:flutter/material.dart';
class TimerPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('building MyHomePage');
return Scaffold(
appBar: AppBar(title: Text('My Timer App')),
body: Center(
child: Column(
@suragch
suragch / service_locator.dart
Last active Mar 31, 2021
service locator example
View service_locator.dart
//import 'storage_service_fake.dart';
import 'storage_service_shared_pref.dart';
import 'package:get_it/get_it.dart';
import 'storage_service.dart';
final getIt = GetIt.instance;
setupServiceLocator() {
//getIt.registerLazySingleton<StorageService>(() => StorageServiceFake());
@suragch
suragch / counter_screen.dart
Created Mar 31, 2021
Services: counter UI
View counter_screen.dart
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'counter_viewmodel.dart';
class CounterScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ViewModelBuilder<CounterViewModel>.reactive(
viewModelBuilder: () {
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: HomeWidget(),
@suragch
suragch / socket_client.dart
Created Jan 16, 2021
Working with Sockets in Dart
View socket_client.dart
import 'dart:io';
import 'dart:typed_data';
void main() async {
// connect to the socket server
final socket = await Socket.connect('localhost', 4567);
print('Connected to: ${socket.remoteAddress.address}:${socket.remotePort}');
// listen for responses from the server