Skip to content

Instantly share code, notes, and snippets.

Avatar
🐝
Beeing

Aseem Wangoo AseemWangoo

🐝
Beeing
View GitHub Profile
View locator.dart
final GetIt locator = GetIt.instance;
void setupLocator() {
locator.registerFactory<HomeRepository>(() => HomeRepoImpl());
// Alternatively you could write it
GetIt.I.registerFactory<HomeRepository>(HomeRepoImpl());
}
View main.dart
Future<void> main() async {
setupLocator();
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => HomeViewModel(repo: locator<HomeRepo>()),
),
],
View view_model.dart
late HomeViewModel viewModel;
@override
void initState() {
viewModel = Provider.of<HomeViewModel>(context, listen: false);
WidgetsBinding.instance.addPostFrameCallback((_) {
viewModel.fetchData();
});
super.initState();
}
View package_info.dart
abstract class PackageInfoService {
Future<String> appVersion();
}
class PackageInfoServiceImpl implements PackageInfoService {
@override
Future<String> appVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version;
String build = packageInfo.buildNumber;
return 'v$version ($build)';
View home_repo.dart
class HomeRepositoryImpl extends HomeRepository {
@override
Future<CarouselModel> fetchData() async {
await Future.delayed(const Duration(milliseconds: 1800));
final resp = await rootBundle.loadString('assets/data/first_screen.json');
return carouselModelFromJson(resp);
}
}
View change_notifier.dart
class Person extends ChangeNotifier {
Person({this.name, this.age});
final String name;
int age;
void increaseAge() {
this.age++;
notifyListeners();
}
}
@AseemWangoo
AseemWangoo / flutter_2.dart
Created Mar 7, 2021
Flutter 2 Widgets - Link | RawAutoComplete | CupertinoFormSection | ScaffoldMessenger | CupertinoSearchTextField | CupertinoTextFormFieldRow
View flutter_2.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';
// Link
class LinkerDemo extends StatelessWidget {
const LinkerDemo({Key key}) : super(key: key);