repo_id
stringlengths
21
168
file_path
stringlengths
36
210
content
stringlengths
1
9.98M
__index_level_0__
int64
0
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/view/expense_form_page.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_objectbox_example/expense/expense.dart'; import 'package:flutter_objectbox_example/form_inputs/form_inputs.dart'; import 'package:flutter_objectbox_example/repository/repository.dart'; import 'package:formz/formz.dart'; class ExpenseFormPage extends StatelessWidget { const ExpenseFormPage({super.key}); static Route route() => MaterialPageRoute( builder: (_) => const ExpenseFormPage(), ); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('EXPENSE'), centerTitle: true, ), body: Padding( padding: const EdgeInsets.all(16.0), child: BlocProvider<ExpenseFormBloc>( create: (context) => ExpenseFormBloc( expenseRepository: context.read<ExpenseRepository>(), expenseTypeRepository: context.read<ExpenseTypeRepository>(), )..add(InitExpenseForm()), child: const ExpenseFormView(), ), ), ); } } class ExpenseFormView extends StatelessWidget { const ExpenseFormView({super.key}); @override Widget build(BuildContext context) { return BlocListener<ExpenseFormBloc, ExpenseFormState>( listenWhen: (previous, current) => previous.status != current.status, listener: (context, state) { if (state.status.isSubmissionFailure) { ScaffoldMessenger.of(context) ..hideCurrentSnackBar() ..showSnackBar( SnackBar( content: Text(state.errorMessage ?? 'Something went wrong'), ), ); } else if (state.status.isSubmissionSuccess) { Navigator.pop(context); } }, child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Text('Add amount', style: TextStyle(fontSize: 18)), _AmountTextField(), const SizedBox(height: 16), const Text('Add a note', style: TextStyle(fontSize: 18)), _NoteTextField(), const SizedBox(height: 24), const Text('Select an expense type', style: TextStyle(fontSize: 18)), const SizedBox(height: 16), _ExpenseTypeSelectionWidget(), const SizedBox(height: 16), _AddExpenseButton(), ], ), ), ); } } class _AmountTextField extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder<ExpenseFormBloc, ExpenseFormState>( buildWhen: (previous, current) => previous.amount != current.amount, builder: (context, state) { return TextField( key: const Key('expenseForm_amount_textField'), onChanged: (value) => context.read<ExpenseFormBloc>().add(AmountChanged(value)), keyboardType: TextInputType.number, decoration: InputDecoration( hintText: 'Amount', errorText: state.amount.invalid ? 'Must be a number' : null, ), ); }, ); } } class _NoteTextField extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder<ExpenseFormBloc, ExpenseFormState>( buildWhen: (previous, current) => previous.note != current.note, builder: (context, state) { return TextField( key: const Key('expenseForm_note_textField'), onChanged: (value) => context.read<ExpenseFormBloc>().add(NoteChanged(value)), decoration: InputDecoration( hintText: 'Note', errorText: state.note.invalid ? 'Must be within 10 characters' : null, ), ); }, ); } } class _ExpenseTypeSelectionWidget extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder<ExpenseFormBloc, ExpenseFormState>( buildWhen: (previous, current) => previous.selectedTypeIndex != current.selectedTypeIndex || previous.expenseTypes != current.expenseTypes, builder: (context, state) { return GridView.builder( physics: const ScrollPhysics(), shrinkWrap: true, gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 4, ), itemCount: state.expenseTypes.length, itemBuilder: (context, index) { final expenseType = state.expenseTypes.elementAt(index); return InkWell( onTap: () => context .read<ExpenseFormBloc>() .add(ExpenseTypeChanged(index)), child: TypeSelectionCard( expenseType: expenseType, backgroundColor: index == state.selectedTypeIndex ? Colors.grey[300] : null, ), ); }, ); }, ); } } class _AddExpenseButton extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder<ExpenseFormBloc, ExpenseFormState>( buildWhen: (previous, current) => previous.status != current.status, builder: (context, state) { return ElevatedButton( key: const Key('expenseForm_addExpense_elevatedButton'), style: ElevatedButton.styleFrom( padding: const EdgeInsets.symmetric(vertical: 16), primary: const Color(0xFF252525), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), ), onPressed: state.status.isValidated ? () => context.read<ExpenseFormBloc>().add(ExpenseFormSubmitted()) : null, child: state.status.isSubmissionInProgress ? const CircularProgressIndicator() : const Text( 'SAVE', style: TextStyle(fontSize: 18), ), ); }, ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/widgets/type_selection_card.dart
import 'package:flutter/material.dart'; import 'package:flutter_objectbox_example/entities/entities.dart'; class TypeSelectionCard extends StatelessWidget { const TypeSelectionCard({ super.key, required this.expenseType, this.backgroundColor, }); final ExpenseType expenseType; final Color? backgroundColor; @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: backgroundColor, ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( expenseType.identifier, style: const TextStyle(fontSize: 30), ), const SizedBox(height: 12), Text( expenseType.name, style: const TextStyle( fontSize: 15, color: Color(0xDD232323), overflow: TextOverflow.ellipsis, ), ), ], ), ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/widgets/expense_tile.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_objectbox_example/entities/entities.dart'; import 'package:flutter_objectbox_example/expense/expense.dart'; class ExpenseTile extends StatelessWidget { const ExpenseTile({super.key, required this.expense}); final Expense expense; Future<void> _showDeleteDialog(BuildContext context) { return showDialog<void>( context: context, builder: (_) => AlertDialog( title: const Text('Delete Expense'), content: const Text('Are you sure you want to delete this expense?'), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text( 'CANCEL', style: TextStyle(color: Colors.black54), ), ), TextButton( onPressed: () { context.read<ExpenseBloc>().add(ExpenseDeleted(expense.id)); Navigator.pop(context); }, child: const Text('OK'), ), ], ), ); } @override Widget build(BuildContext context) { return InkWell( onLongPress: () => _showDeleteDialog(context), child: Column( children: [ Row( children: [ Text( expense.expenseType.target?.identifier ?? '', style: const TextStyle(fontSize: 25), ), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( expense.expenseType.target?.name ?? '', style: const TextStyle(fontSize: 18), ), const SizedBox(height: 4), Text( expense.note, style: const TextStyle(fontSize: 16, color: Colors.black45), ), ], ), ), const SizedBox(width: 8), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( '₹ ${expense.amount.toStringAsFixed(2)}', style: const TextStyle(fontSize: 18), ), const SizedBox(height: 4), Text( expense.date.formattedTime, style: const TextStyle(fontSize: 14, color: Colors.black45), ), ], ), ], ), const SizedBox(height: 6), const Divider(), ], ), ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/bloc/expense_bloc.dart
import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_objectbox_example/entities/entities.dart'; import 'package:flutter_objectbox_example/repository/repository.dart'; part 'expense_event.dart'; part 'expense_state.dart'; class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> { ExpenseBloc({ required ExpenseRepository expenseRepository, }) : _expenseRepository = expenseRepository, super(const ExpenseState()) { on<ExpenseListRequested>(_onExpenseList); on<ExpenseListSortByTimeRequested>(_onExpenseListSortByTime); on<ExpenseListSortByAmountRequested>(_onExpenseListSortByAmount); on<ToggleExpenseSort>(_onToggleExpenseSort); on<ExpenseInLast7DaysRequested>(_onExpenseInLast7DaysRequested); on<ExpenseDeleted>(_onExpenseDeleted); } final ExpenseRepository _expenseRepository; Future<void> _onExpenseList( ExpenseListRequested event, Emitter<ExpenseState> emit ) async { emit(state.copyWith(status: ExpenseStatus.loading)); await emit.forEach<List<Expense>>( _expenseRepository.getAllExpenseStream(), onData: (expenses) => state.copyWith( status: ExpenseStatus.success, expenses: expenses, ), onError: (_, __) => state.copyWith( status: ExpenseStatus.failure, ), ); } Future<void> _onExpenseListSortByTime( ExpenseListSortByTimeRequested event, Emitter<ExpenseState> emit, ) async { emit(state.copyWith(status: ExpenseStatus.loading)); await emit.forEach<List<Expense>>( _expenseRepository.getExpenseSortByTime(), onData: (expenses) => state.copyWith( status: ExpenseStatus.success, expenses: expenses, ), onError: (_, __) => state.copyWith( status: ExpenseStatus.failure, ), ); } Future<void> _onExpenseListSortByAmount( ExpenseListSortByAmountRequested event, Emitter<ExpenseState> emit, ) async { emit(state.copyWith(status: ExpenseStatus.loading)); await emit.forEach<List<Expense>>( _expenseRepository.getExpenseSortByAmount(), onData: (expenses) => state.copyWith( status: ExpenseStatus.success, expenses: expenses, ), onError: (_, __) => state.copyWith( status: ExpenseStatus.failure, ), ); } void _onToggleExpenseSort( ToggleExpenseSort event, Emitter<ExpenseState> emit ) { if (state.expenseSort == ExpenseSort.none) { emit(state.copyWith(expenseSort: ExpenseSort.time)); add(ExpenseListSortByTimeRequested()); } else if (state.expenseSort == ExpenseSort.time) { emit(state.copyWith(expenseSort: ExpenseSort.amount)); add(ExpenseListSortByAmountRequested()); } else if (state.expenseSort == ExpenseSort.amount) { emit(state.copyWith(expenseSort: ExpenseSort.none)); add(ExpenseListRequested()); } } Future<void> _onExpenseInLast7DaysRequested( ExpenseInLast7DaysRequested event, Emitter<ExpenseState> emit ) async { await emit.forEach<double>( _expenseRepository.expenseInLast7Days(), onData: (totalExpenses) => state.copyWith( expenseInLast7Days: totalExpenses, ), onError: (_, __) => state.copyWith( expenseInLast7Days: 0.0, ), ); } void _onExpenseDeleted(ExpenseDeleted event, Emitter<ExpenseState> emit) { _expenseRepository.removeExpense(event.id); } }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/bloc/expense_state.dart
part of 'expense_bloc.dart'; enum ExpenseStatus { initial, loading, success, failure } enum ExpenseSort { none, time, amount } class ExpenseState extends Equatable { const ExpenseState({ this.status = ExpenseStatus.initial, this.expenses = const [], this.expenseSort = ExpenseSort.none, this.expenseInLast7Days = 0.0, }); final ExpenseStatus status; final List<Expense> expenses; final ExpenseSort expenseSort; final double expenseInLast7Days; @override List<Object> get props => [status, expenses, expenseSort, expenseInLast7Days]; ExpenseState copyWith({ ExpenseStatus? status, List<Expense>? expenses, ExpenseSort? expenseSort, double? expenseInLast7Days, }) { return ExpenseState( status: status ?? this.status, expenses: expenses ?? this.expenses, expenseSort: expenseSort ?? this.expenseSort, expenseInLast7Days: expenseInLast7Days ?? this.expenseInLast7Days, ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/bloc/expense_event.dart
part of 'expense_bloc.dart'; abstract class ExpenseEvent extends Equatable { const ExpenseEvent(); @override List<Object> get props => []; } class ExpenseListRequested extends ExpenseEvent {} class ExpenseListSortByTimeRequested extends ExpenseEvent {} class ExpenseListSortByAmountRequested extends ExpenseEvent {} class ToggleExpenseSort extends ExpenseEvent {} class ExpenseInLast7DaysRequested extends ExpenseEvent {} class ExpenseDeleted extends ExpenseEvent { const ExpenseDeleted(this.id); final int id; @override List<Object> get props => [id]; }
0
mirrored_repositories/flutter-objectbox-example/lib/expense
mirrored_repositories/flutter-objectbox-example/lib/expense/helpers/date_time_ext.dart
extension DateTimeExt on DateTime { String get formattedTime { final months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ]; final ampm = hour >= 12 ? 'PM' : 'AM'; final hrInt = hour % 12 == 0 ? 12 : (hour % 12); final hr = hrInt < 10 ? '0$hrInt' : '$hrInt'; final mn = minute < 10 ? '0$minute' : '$minute'; return '${months[month - 1]} $day, $hr:$mn $ampm'; } }
0
mirrored_repositories/flutter-objectbox-example/lib
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/amount.dart
import 'package:formz/formz.dart'; enum AmountValidationError { invalid } class Amount extends FormzInput<String, AmountValidationError> { const Amount.pure() : super.pure(''); const Amount.dirty([String amount = '']) : super.dirty(amount); static final RegExp _amountRegExp = RegExp(r'^\d+(\.\d{1,2})?$'); @override AmountValidationError? validator(String value) { return _amountRegExp.hasMatch(value) ? null : AmountValidationError.invalid; } }
0
mirrored_repositories/flutter-objectbox-example/lib
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/identifier.dart
import 'package:formz/formz.dart'; enum IdentifierValidationError { invalid } class Identifier extends FormzInput<String, IdentifierValidationError> { const Identifier.pure() : super.pure(''); const Identifier.dirty([String identifier = '']) : super.dirty(identifier); static final RegExp _identifierRegExp = RegExp(r'^.{1,5}$'); @override IdentifierValidationError? validator(String value) { return _identifierRegExp.hasMatch(value) ? null : IdentifierValidationError.invalid; } }
0
mirrored_repositories/flutter-objectbox-example/lib
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/note.dart
import 'package:formz/formz.dart'; enum NoteValidationError { invalid } class Note extends FormzInput<String, NoteValidationError> { const Note.pure() : super.pure(''); const Note.dirty([String note = '']) : super.dirty(note); static final RegExp _noteRegExp = RegExp(r'^.{1,20}$'); @override NoteValidationError? validator(String value) { return _noteRegExp.hasMatch(value) ? null : NoteValidationError.invalid; } }
0
mirrored_repositories/flutter-objectbox-example/lib
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/form_inputs.dart
export 'amount.dart'; export 'identifier.dart'; export 'name.dart'; export 'note.dart'; export 'expense_form_bloc/expense_form_bloc.dart'; export 'expense_type_form_bloc/expense_type_form_bloc.dart';
0
mirrored_repositories/flutter-objectbox-example/lib
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/name.dart
import 'package:formz/formz.dart'; enum NameValidationError { invalid } class Name extends FormzInput<String, NameValidationError> { const Name.pure() : super.pure(''); const Name.dirty([String name = '']) : super.dirty(name); static final RegExp _nameRegExp = RegExp(r'^.{1,20}$'); @override NameValidationError? validator(String value) { return _nameRegExp.hasMatch(value) ? null : NameValidationError.invalid; } }
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_form_bloc/expense_form_bloc.dart
import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_objectbox_example/entities/entities.dart'; import 'package:flutter_objectbox_example/form_inputs/form_inputs.dart'; import 'package:flutter_objectbox_example/repository/repository.dart'; import 'package:formz/formz.dart'; part 'expense_form_event.dart'; part 'expense_form_state.dart'; class ExpenseFormBloc extends Bloc<ExpenseFormEvent, ExpenseFormState> { ExpenseFormBloc({ required ExpenseRepository expenseRepository, required ExpenseTypeRepository expenseTypeRepository, }) : _expenseRepository = expenseRepository, _expenseTypeRepository = expenseTypeRepository, super(const ExpenseFormState()) { on<InitExpenseForm>(_onInitExpenseForm); on<AmountChanged>(_onAmountChanged); on<NoteChanged>(_onNoteChanged); on<ExpenseTypeChanged>(_onExpenseTypeChanged); on<ExpenseFormSubmitted>(_onExpenseFormSubmitted); } final ExpenseRepository _expenseRepository; final ExpenseTypeRepository _expenseTypeRepository; void _onInitExpenseForm( InitExpenseForm event, Emitter<ExpenseFormState> emit, ) { final expenseTypes = _expenseTypeRepository.getAllExpenseTypes(); emit(state.copyWith(expenseTypes: expenseTypes)); } void _onAmountChanged( AmountChanged event, Emitter<ExpenseFormState> emit, ) { final amount = Amount.dirty(event.value); emit(state.copyWith( amount: amount, status: Formz.validate([amount, state.note]), )); } void _onNoteChanged( NoteChanged event, Emitter<ExpenseFormState> emit, ) { final note = Note.dirty(event.value); emit(state.copyWith( note: note, status: Formz.validate([state.amount, note]), )); } void _onExpenseTypeChanged( ExpenseTypeChanged event, Emitter<ExpenseFormState> emit, ) { emit(state.copyWith( selectedTypeIndex: event.selectedIndex, status: Formz.validate([state.amount, state.note]), )); } void _onExpenseFormSubmitted( ExpenseFormSubmitted event, Emitter<ExpenseFormState> emit, ) { if (!state.status.isValidated) return; emit(state.copyWith(status: FormzStatus.submissionInProgress)); final expenseType = state.expenseTypes.elementAt(state.selectedTypeIndex); try { _expenseRepository.addExpense( Expense( amount: double.parse(state.amount.value), note: state.note.value, date: DateTime.now(), ), expenseType, ); emit(state.copyWith(status: FormzStatus.submissionSuccess)); } catch (e) { emit(state.copyWith( status: FormzStatus.submissionFailure, errorMessage: e.toString(), )); } } }
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_form_bloc/expense_form_event.dart
part of 'expense_form_bloc.dart'; abstract class ExpenseFormEvent extends Equatable { const ExpenseFormEvent(); @override List<Object> get props => []; } class InitExpenseForm extends ExpenseFormEvent {} class AmountChanged extends ExpenseFormEvent { const AmountChanged(this.value); final String value; @override List<Object> get props => [value]; } class NoteChanged extends ExpenseFormEvent { const NoteChanged(this.value); final String value; @override List<Object> get props => [value]; } class ExpenseTypeChanged extends ExpenseFormEvent { const ExpenseTypeChanged(this.selectedIndex); final int selectedIndex; @override List<Object> get props => [selectedIndex]; } class ExpenseFormSubmitted extends ExpenseFormEvent {}
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_form_bloc/expense_form_state.dart
part of 'expense_form_bloc.dart'; class ExpenseFormState extends Equatable { const ExpenseFormState({ this.amount = const Amount.pure(), this.note = const Note.pure(), this.expenseTypes = const [], this.selectedTypeIndex = 0, this.status = FormzStatus.pure, this.errorMessage, }); final Amount amount; final Note note; final List<ExpenseType> expenseTypes; final int selectedTypeIndex; final FormzStatus status; final String? errorMessage; @override List<Object> get props => [amount, note, expenseTypes, selectedTypeIndex, status]; ExpenseFormState copyWith({ Amount? amount, Note? note, List<ExpenseType>? expenseTypes, int? selectedTypeIndex, FormzStatus? status, String? errorMessage, }) { return ExpenseFormState( amount: amount ?? this.amount, note: note ?? this.note, expenseTypes: expenseTypes ?? this.expenseTypes, selectedTypeIndex: selectedTypeIndex ?? this.selectedTypeIndex, status: status ?? this.status, errorMessage: errorMessage ?? this.errorMessage, ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_type_form_bloc/expense_type_form_event.dart
part of 'expense_type_form_bloc.dart'; abstract class ExpenseTypeFormEvent extends Equatable { const ExpenseTypeFormEvent(); @override List<Object> get props => []; } class IdentifierChanged extends ExpenseTypeFormEvent { const IdentifierChanged(this.value); final String value; @override List<Object> get props => [value]; } class NameChanged extends ExpenseTypeFormEvent { const NameChanged(this.value); final String value; @override List<Object> get props => [value]; } class ExpenseTypeFormSubmitted extends ExpenseTypeFormEvent {}
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_type_form_bloc/expense_type_form_state.dart
part of 'expense_type_form_bloc.dart'; class ExpenseTypeFormState extends Equatable { const ExpenseTypeFormState({ this.identifier = const Identifier.pure(), this.name = const Name.pure(), this.status = FormzStatus.pure, this.errorMessage, }); final Identifier identifier; final Name name; final FormzStatus status; final String? errorMessage; @override List<Object> get props => [identifier, name, status]; ExpenseTypeFormState copyWith({ Identifier? identifier, Name? name, FormzStatus? status, String? errorMessage, }) { return ExpenseTypeFormState( identifier: identifier ?? this.identifier, name: name ?? this.name, status: status ?? this.status, errorMessage: errorMessage ?? this.errorMessage, ); } }
0
mirrored_repositories/flutter-objectbox-example/lib/form_inputs
mirrored_repositories/flutter-objectbox-example/lib/form_inputs/expense_type_form_bloc/expense_type_form_bloc.dart
import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_objectbox_example/entities/entities.dart'; import 'package:flutter_objectbox_example/form_inputs/form_inputs.dart'; import 'package:flutter_objectbox_example/repository/repository.dart'; import 'package:formz/formz.dart'; part 'expense_type_form_event.dart'; part 'expense_type_form_state.dart'; class ExpenseTypeFormBloc extends Bloc<ExpenseTypeFormEvent, ExpenseTypeFormState> { ExpenseTypeFormBloc({ required ExpenseTypeRepository expenseTypeRepository, }) : _expenseTypeRepository = expenseTypeRepository, super(const ExpenseTypeFormState()) { on<IdentifierChanged>(_onIdentifierChanged); on<NameChanged>(_onNameChanged); on<ExpenseTypeFormSubmitted>(_onExpenseTypeFormSubmitted); } final ExpenseTypeRepository _expenseTypeRepository; void _onIdentifierChanged( IdentifierChanged event, Emitter<ExpenseTypeFormState> emit, ) { final identifier = Identifier.dirty(event.value); emit(state.copyWith( identifier: identifier, status: Formz.validate([identifier, state.name]), )); } void _onNameChanged( NameChanged event, Emitter<ExpenseTypeFormState> emit, ) { final name = Name.dirty(event.value); emit(state.copyWith( name: name, status: Formz.validate([state.identifier, name]), )); } void _onExpenseTypeFormSubmitted( ExpenseTypeFormSubmitted event, Emitter<ExpenseTypeFormState> emit, ) { if (!state.status.isValidated) return; emit(state.copyWith(status: FormzStatus.submissionInProgress)); try { _expenseTypeRepository.addExpenseType( ExpenseType(identifier: state.identifier.value, name: state.name.value), ); emit(state.copyWith(status: FormzStatus.submissionSuccess)); } catch (e) { emit(state.copyWith( status: FormzStatus.submissionFailure, errorMessage: 'You may have entered a duplicate expense type', )); } } }
0
mirrored_repositories/flutter-objectbox-example
mirrored_repositories/flutter-objectbox-example/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_objectbox_example/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/GraphQL-Flutter
mirrored_repositories/GraphQL-Flutter/lib/main.dart
import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphqldemo/feature/homepage/data/respositories/geo_graphql_repo.dart'; import 'package:graphqldemo/feature/homepage/presentation/homepage.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { MyApp({super.key}); final GeoGraphQlRepo geoGraphQlRepo = GeoGraphQlRepo(); @override Widget build(BuildContext context) { return GraphQLProvider( client: geoGraphQlRepo.client, child: MaterialApp( debugShowCheckedModeBanner: false, home: HomeScreen(), ), ); } }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data/respositories/geo_repo.dart
import 'package:dio/dio.dart'; import 'package:graphqldemo/feature/homepage/data/data_providers/api.dart'; import 'package:graphqldemo/feature/homepage/data/model/geo_model.dart'; class GeoRepo { API api = API(); Future<List<GeoModel>> fetchData() async { try { Response response = await api.dio.get(api.dio.options.baseUrl); List<dynamic> result = response.data; return result.map((e) => GeoModel.fromJson(e)).toList(); } catch (e) { rethrow; } } }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data/respositories/geo_graphql_repo.dart
import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; class GeoGraphQlRepo { String documentNode = """ query getGeoData{ continents{ name, countries{ name } } } """; static HttpLink httpLink = HttpLink("https://countries.trevorblades.com/"); ValueNotifier<GraphQLClient> client = ValueNotifier(GraphQLClient(link: httpLink, cache: GraphQLCache())); }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data/model/geo_model.dart
class GeoModel { Data? data; GeoModel({this.data}); GeoModel.fromJson(Map<String, dynamic> json) { data = json['data'] != null ? Data.fromJson(json['data']) : null; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>{}; if (this.data != null) { data['data'] = this.data!.toJson(); } return data; } } class Data { List<Continents>? continents; Data({this.continents}); Data.fromJson(Map<String, dynamic> json) { if (json['continents'] != null) { continents = <Continents>[]; json['continents'].forEach((v) { continents!.add(Continents.fromJson(v)); }); } } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>{}; if (continents != null) { data['continents'] = continents!.map((v) => v.toJson()).toList(); } return data; } } class Continents { String? name; List<Countries>? countries; Continents({this.name, this.countries}); Continents.fromJson(Map<String, dynamic> json) { name = json['name']; if (json['countries'] != null) { countries = <Countries>[]; json['countries'].forEach((v) { countries!.add(Countries.fromJson(v)); }); } } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>{}; data['name'] = name; if (countries != null) { data['countries'] = countries!.map((v) => v.toJson()).toList(); } return data; } } class Countries { String? name; Countries({this.name}); Countries.fromJson(Map<String, dynamic> json) { name = json['name']; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = <String, dynamic>{}; data['name'] = name; return data; } }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/data/data_providers/api.dart
import 'package:dio/dio.dart'; class API { Dio dio = Dio(); API() { dio.options.baseUrl = "https://countries.trevorblades.com/"; } }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/presentation/homepage.dart
import 'package:flutter/material.dart'; import 'package:graphqldemo/feature/homepage/data/respositories/geo_graphql_repo.dart'; import 'package:graphqldemo/feature/homepage/presentation/widgets/querybuilder.dart'; class HomeScreen extends StatelessWidget { HomeScreen({super.key}); final GeoGraphQlRepo graphQlRepo = GeoGraphQlRepo(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("GraphQL"), ), body: QueryBuilder(), ); } }
0
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/presentation
mirrored_repositories/GraphQL-Flutter/lib/feature/homepage/presentation/widgets/querybuilder.dart
import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphqldemo/feature/homepage/data/respositories/geo_graphql_repo.dart'; class QueryBuilder extends StatelessWidget { QueryBuilder({super.key}); final GeoGraphQlRepo geoGraphQlRepo = GeoGraphQlRepo(); @override Widget build(BuildContext context) { return Query( options: QueryOptions(document: gql(geoGraphQlRepo.documentNode)), builder: (result, {fetchMore, refetch}) { if (result.isLoading) { return const Center( child: CircularProgressIndicator.adaptive(), ); } if (result.data == null) { return const Center( child: Text("No data found"), ); } else { return ListView.separated( itemBuilder: (context, index) { return ExpansionTile( title: Text(result.data!["continents"][index]["name"]), children: [ CountryName( result: result, indexs: index, ), ], ); }, separatorBuilder: (context, index) { return const Divider(); }, itemCount: result.data!["continents"].length); } }); } } class CountryName extends StatelessWidget { const CountryName({ required this.result, required this.indexs, super.key, }); final QueryResult result; final int indexs; @override Widget build(BuildContext context) { return ListView.builder( physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, itemCount: result.data!["continents"][indexs]["countries"].length, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text( result.data!["continents"][indexs]["countries"][index]["name"]), ); }, ); } }
0
mirrored_repositories/GraphQL-Flutter
mirrored_repositories/GraphQL-Flutter/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:graphqldemo/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/FLUTTER-TIC-TAC-TOE
mirrored_repositories/FLUTTER-TIC-TAC-TOE/lib/tictactoe.dart
import 'package:flutter/material.dart'; import 'main.dart'; class Tictactoe extends StatefulWidget { const Tictactoe({super.key}); @override State<Tictactoe> createState() => _TictactoeState(); } class _TictactoeState extends State<Tictactoe> { Color buttoncolor = const Color.fromARGB(255, 167, 172, 255); @override Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ const SizedBox( height: 170, ), Visibility( visible: showchance, child: Text( xx ? onename + "'s chance" : twoname + "'s chance", style: const TextStyle(fontSize: 30, fontWeight: FontWeight.w700), ), ), const SizedBox(height: 50), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: enablebutton ? () { setState(() { if (one == "") { if (xx) { one = "X"; } else { one = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( one, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (two == "") { if (xx) { two = "X"; } else { two = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( two, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (three == "") { if (xx) { three = "X"; } else { three = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( three, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), ], ), const SizedBox( height: 10, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: enablebutton ? () { setState(() { if (four == "") { if (xx) { four = "X"; } else { four = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( four, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (five == "") { if (xx) { five = "X"; } else { five = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( five, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (six == "") { if (xx) { six = "X"; } else { six = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( six, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), ], ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: enablebutton ? () { setState(() { if (seven == "") { if (xx) { seven = "X"; } else { seven = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( seven, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (eight == "") { if (xx) { eight = "X"; } else { eight = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( eight, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), const SizedBox( width: 10, ), ElevatedButton( onPressed: enablebutton ? () { setState(() { if (nine == "") { if (xx) { nine = "X"; } else { nine = "O"; } xx = !xx; result(); } }); } : null, style: ElevatedButton.styleFrom( fixedSize: const Size.square(70), primary: buttoncolor), child: Text( nine, style: const TextStyle( fontSize: 55, color: Colors.black, fontWeight: FontWeight.normal), ), ), ], ), const SizedBox( height: 10, ), Visibility( visible: showwinner, child: Text( winner + ", won the match.", style: const TextStyle( fontSize: 30, color: Colors.black, fontWeight: FontWeight.bold), ), ), Visibility( visible: showtie, child: const Text( "It's a Tie", style: TextStyle( fontSize: 30, color: Colors.black, fontWeight: FontWeight.bold), ), ), Visibility( visible: resetvisible, child: ElevatedButton( onPressed: () { setState(() { reset(); }); }, child: const Text( "RESET", style: TextStyle(color: Colors.white, fontSize: 17), ), ), ), const SizedBox( height: 15, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( onename + ": " + onescore.toString(), style: const TextStyle( color: Color.fromARGB(255, 226, 5, 5), fontSize: 25), ), const Text( " | ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 19), ), Text( twoname + ": " + twoscore.toString(), style: const TextStyle( color: Color.fromARGB(255, 226, 5, 5), fontSize: 25), ) ], ), const SizedBox(height: 20), Visibility( visible: celebrate, child: Image.asset('images/celebrate.png', height: 185), ) ], ), ), ); } } void result() { if ([one, two, three].every((element) => (element == "X"))) { winner = onename; showwinner = true; enablebutton = false; resetvisible = true; showchance = false; onescore = onescore + 1; celebrate = true; //X wins } else if ([four, five, six].every((element) => element == "X")) { winner = onename; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; showchance = false; celebrate = true; //X wins } else if ([seven, eight, nine].every((element) => element == "X")) { winner = onename; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; showchance = false; celebrate = true; //X wins } else if ([one, four, seven].every((element) => element == "X")) { winner = onename; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; celebrate = true; //X wins } else if ([two, five, eight].every((element) => element == "X")) { winner = onename; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; celebrate = true; //X wins } else if ([three, six, nine].every((element) => element == "X")) { winner = onename; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; celebrate = true; //X wins } else if ([one, five, nine].every((element) => element == "X")) { winner = onename; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; celebrate = true; //X wins } else if ([three, five, seven].every((element) => element == "X")) { winner = onename; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; onescore = onescore + 1; celebrate = true; //X wins } else if ([one, two, three].every((element) => (element == "O"))) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([four, five, six].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([seven, eight, nine].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([one, four, seven].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([two, five, eight].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([three, six, nine].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([one, five, nine].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([three, five, seven].every((element) => element == "O")) { winner = twoname; showchance = false; showwinner = true; enablebutton = false; resetvisible = true; twoscore = twoscore + 1; celebrate = true; //X wins } else if ([one, two, three, four, five, six, seven, eight, nine] .every((element) => element == "O" || element == "X")) { showtie = true; showchance = false; enablebutton = false; resetvisible = true; } } void reset() { one = ""; two = ""; three = ""; four = ""; five = ""; six = ""; seven = ""; eight = ""; nine = ""; showwinner = false; winner = ""; enablebutton = true; resetvisible = false; first = !first; xx = first; showtie = false; showchance = true; celebrate = false; }
0
mirrored_repositories/FLUTTER-TIC-TAC-TOE
mirrored_repositories/FLUTTER-TIC-TAC-TOE/lib/playername.dart
import 'package:flutter/material.dart'; import 'main.dart'; import 'tictactoe.dart'; class PlayerName extends StatefulWidget { const PlayerName({super.key}); @override State<PlayerName> createState() => _PlayerNameState(); } class _PlayerNameState extends State<PlayerName> { final playeronecontrol = TextEditingController(); final playertwocontrol = TextEditingController(); bool clearone = false; bool cleartwo = false; bool showplayererror = false; @override Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( child: Column(children: [ const SizedBox( height: 60, ), const Text( "TIC TAC TOE", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30), ), const SizedBox( height: 70, ), Image.asset('images/tictactoe.png', height: 160), const SizedBox( height: 40, ), const Text( "Enter Player Names", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25), ), const SizedBox( height: 25, ), Padding( padding: const EdgeInsets.symmetric(horizontal: 60), child: TextField( controller: playeronecontrol, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w400, color: Colors.black), textAlign: TextAlign.center, onChanged: (value) { setState(() { if (value == "") { clearone = false; } else { clearone = true; } }); }, decoration: InputDecoration( suffixIcon: Visibility( visible: clearone, child: IconButton( onPressed: () { setState(() { clearone = false; playeronecontrol.clear(); }); }, icon: const Icon( Icons.clear, color: Colors.red, )), ), prefixIcon: Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: Image.asset( 'images/x.png', color: Colors.blue, height: 0, ), ), fillColor: Colors.white, filled: true, hintStyle: const TextStyle( fontSize: 18, fontWeight: FontWeight.w400, ), hintText: "Player Name", enabledBorder: const OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(18)), borderSide: BorderSide( color: Color.fromARGB(255, 248, 177, 177), width: 2)), focusedBorder: const OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(18)), borderSide: BorderSide( color: Color.fromARGB(255, 0, 0, 0), width: 2))), ), ), const SizedBox( height: 20, ), Padding( padding: const EdgeInsets.symmetric(horizontal: 60), child: TextField( controller: playertwocontrol, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w400, color: Colors.black), textAlign: TextAlign.center, onChanged: (value) { setState(() { if (value == "") { cleartwo = false; } else { cleartwo = true; } }); }, decoration: InputDecoration( suffixIcon: Visibility( visible: cleartwo, child: IconButton( onPressed: () { setState(() { cleartwo = false; playertwocontrol.clear(); }); }, icon: const Icon( Icons.clear, color: Colors.red, )), ), prefixIcon: Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: Image.asset( 'images/o.png', color: Colors.blue, height: 0, ), ), fillColor: Colors.white, filled: true, hintStyle: const TextStyle( fontSize: 18, fontWeight: FontWeight.w400, ), hintText: "Player Name", enabledBorder: const OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(18)), borderSide: BorderSide( color: Color.fromARGB(255, 248, 177, 177), width: 2)), focusedBorder: const OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(18)), borderSide: BorderSide( color: Color.fromARGB(255, 0, 0, 0), width: 2))), ), ), const SizedBox( height: 15, ), ElevatedButton( onPressed: () { if (playeronecontrol.text != "" && playertwocontrol.text != "") { setState(() { showplayererror = false; }); one = ""; two = ""; three = ""; four = ""; five = ""; six = ""; seven = ""; eight = ""; nine = ""; first = true; showchance = true; onescore = 0; twoscore = 0; resetvisible = false; showwinner = false; showtie = false; celebrate = false; winner = ""; enablebutton = true; xx = true; onename = playeronecontrol.text; twoname = playertwocontrol.text; Navigator.of(context) .push(MaterialPageRoute(builder: (BuildContext context) { return Tictactoe(); })); } else { setState(() { showplayererror = true; }); } }, child: const Text( "PLAY", style: TextStyle(color: Colors.white, fontSize: 17), ), ), Visibility( visible: showplayererror, child: const Text( "Please enter valid name.", style: TextStyle(color: Colors.red, fontSize: 25), )) ]), ), ); } }
0
mirrored_repositories/FLUTTER-TIC-TAC-TOE
mirrored_repositories/FLUTTER-TIC-TAC-TOE/lib/main.dart
import 'package:flutter/material.dart'; import 'playername.dart'; String one = ""; String two = ""; String three = ""; String four = ""; String five = ""; String six = ""; String seven = ""; String eight = ""; String nine = ""; bool xx = true; bool first = true; bool showwinner = false; String winner = ""; bool enablebutton = true; bool resetvisible = false; bool showchance = true; bool celebrate = false; bool showtie = false; String yourname = ""; String hib = ""; String onename = ""; String twoname = ""; int onescore = 0; int twoscore = 0; void main() { runApp(const MaterialApp( home: PlayerName(), debugShowCheckedModeBanner: false, )); }
0
mirrored_repositories/FLUTTER-TIC-TAC-TOE
mirrored_repositories/FLUTTER-TIC-TAC-TOE/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tic_tac_toe/main.dart'; import 'package:tic_tac_toe/playername.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const PlayerName()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/notes_app_learning
mirrored_repositories/notes_app_learning/lib/simple_bloc_observer.dart
import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class SimpleBlocObserver implements BlocObserver { @override void onChange(BlocBase bloc, Change change) { debugPrint('Debug on Change: $change'); } @override void onClose(BlocBase bloc) { debugPrint('Debug on Close: $bloc'); } @override void onCreate(BlocBase bloc) { debugPrint('Debug on Create: $bloc'); } @override void onError(BlocBase bloc, Object error, StackTrace stackTrace) { debugPrint('Debug on Create: $error'); } @override void onEvent(Bloc bloc, Object? event) { debugPrint('Debug on Create: $event'); } @override void onTransition(Bloc bloc, Transition transition) { debugPrint('Debug on Create: $transition'); } }
0
mirrored_repositories/notes_app_learning
mirrored_repositories/notes_app_learning/lib/constants.dart
import 'package:flutter/material.dart'; const kPrimaryColor = Color(0xff62fcd7); const kNotesBox = 'notes_box'; List<Color> kColors = const [ Color(0xff6DA34D), Color(0xff56445D), Color(0xff548687), Color(0xff8FBC94), Color(0xffC5E99B), ];
0
mirrored_repositories/notes_app_learning
mirrored_repositories/notes_app_learning/lib/main.dart
import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:notter/simple_bloc_observer.dart'; import 'package:notter/views/notes_view.dart'; import 'constants.dart'; import 'cubits/notes_cubit/notes_cubit.dart'; import 'models/note_model.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; void main() async { // just to be able to deal with native code.. WidgetsFlutterBinding.ensureInitialized(); // initialize hive adaptor to be able to use it. await Hive.initFlutter(); // observe bloc statue for debugging.. Bloc.observer = SimpleBlocObserver(); // register hive adaptor in order to deal with it Hive.registerAdapter(NoteModelAdapter()); // open our box named with const value to get, put data await Hive.openBox<NoteModel>(kNotesBox); runApp(const NotesApp()); } class NotesApp extends StatelessWidget { const NotesApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => NotesCubit(), child: MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( brightness: Brightness.dark, fontFamily: 'Poppins', ), home: const NotesView(), ), ); } }
0
mirrored_repositories/notes_app_learning/lib
mirrored_repositories/notes_app_learning/lib/views/notes_view.dart
import 'package:flutter/material.dart'; import 'package:notter/views/widgets/add_note_bottom_sheet.dart'; import 'package:notter/views/widgets/notes_view_body.dart'; import '../constants.dart'; class NotesView extends StatelessWidget { const NotesView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( floatingActionButton: FloatingActionButton( onPressed: () { showModalBottomSheet( isScrollControlled: true, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16.0), ), context: context, builder: (context) => const AddNoteBottomSheet(), ); }, backgroundColor: kPrimaryColor, child: const Icon(Icons.add), ), body: const SafeArea( child: NotesViewBody(), ), ); } }
0
mirrored_repositories/notes_app_learning/lib
mirrored_repositories/notes_app_learning/lib/views/edit_note_view.dart
import 'package:flutter/material.dart'; import 'package:notter/models/note_model.dart'; import 'package:notter/views/widgets/edit_note_view_body.dart'; class EditNoteView extends StatelessWidget { const EditNoteView({Key? key, required this.note}) : super(key: key); final NoteModel note; @override Widget build(BuildContext context) { return Scaffold( body: EditNoteViewBody(note: note), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/custom_button.dart
import 'package:flutter/material.dart'; import '../../constants.dart'; class CustomButton extends StatelessWidget { const CustomButton({Key? key, this.onTap, this.isLoading = false}) : super(key: key); final void Function()? onTap; final bool isLoading; @override Widget build(BuildContext context) { return GestureDetector( onTap: onTap, child: Container( width: MediaQuery.of(context).size.width, height: 55.0, decoration: BoxDecoration( color: kPrimaryColor, borderRadius: BorderRadius.circular(8.0), ), child: Center( child: isLoading == true ? const SizedBox( height: 24.0, width: 24.0, child: CircularProgressIndicator( color: Colors.black, ), ) : const Text( 'Add Note', style: TextStyle( color: Colors.black, fontSize: 20.0, fontWeight: FontWeight.bold, ), ), ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/custom_note_item.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:notter/cubits/notes_cubit/notes_cubit.dart'; import '../../models/note_model.dart'; import '../edit_note_view.dart'; class NoteItem extends StatelessWidget { const NoteItem({Key? key, required this.note}) : super(key: key); final NoteModel note; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => EditNoteView( note: note, ), ), ); }, child: Container( padding: const EdgeInsets.only( top: 24.0, bottom: 24.0, left: 16.0, ), decoration: BoxDecoration( color: Color(note.color), borderRadius: BorderRadius.circular(16.0), ), child: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ ListTile( title: Padding( padding: const EdgeInsets.only(bottom: 16.0), child: Text( note.title, style: const TextStyle( color: Colors.black, fontSize: 26.0, ), ), ), subtitle: Padding( padding: const EdgeInsets.only(bottom: 16.0), child: Text( note.subTitle, style: TextStyle( color: Colors.black.withOpacity(0.5), fontSize: 18.0, ), ), ), trailing: IconButton( onPressed: () { note.delete(); BlocProvider.of<NotesCubit>(context).fetchAllNotes(); }, icon: const Icon( FontAwesomeIcons.trash, color: Color(0xff9C2D41), size: 24.0, ), ), ), Padding( padding: const EdgeInsets.only(right: 24.0), child: Text( // DateFormat('EEEE, MMM d, yyyy').format( DateTime.parse(note.date) ), note.date, style: TextStyle( color: Colors.black.withOpacity(0.5), fontSize: 16.0, ), ), ), ], ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/notes_list_view.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:notter/cubits/notes_cubit/notes_cubit.dart'; import 'package:notter/models/note_model.dart'; import 'custom_note_item.dart'; class NotesListView extends StatelessWidget { const NotesListView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return BlocBuilder<NotesCubit, NotesState>( builder: (context, state) { List<NoteModel> notes = BlocProvider.of<NotesCubit>(context).notes ?? []; return Padding( padding: const EdgeInsets.symmetric(vertical: 16.0), child: ListView.builder( itemCount: notes.length, padding: EdgeInsets.zero, itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: NoteItem(note: notes[index]), ); }, ), ); }, ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/colors_list_view.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:notter/cubits/add_note_cubit/add_note_cubit.dart'; import '../../constants.dart'; class ColorItem extends StatelessWidget { const ColorItem({Key? key, required this.isActive, required this.color}) : super(key: key); final bool isActive; final Color color; @override Widget build(BuildContext context) { return isActive ? CircleAvatar( backgroundColor: Colors.white, radius: 35, child: CircleAvatar( radius: 32, backgroundColor: color, ), ) : CircleAvatar( radius: 35, backgroundColor: color, ); } } class ColorsListView extends StatefulWidget { const ColorsListView({Key? key}) : super(key: key); @override State<ColorsListView> createState() => _ColorsListViewState(); } class _ColorsListViewState extends State<ColorsListView> { int currentIndex = 0; @override Widget build(BuildContext context) { return SizedBox( height: 38 * 2, child: ListView.builder( itemCount: kColors.length, scrollDirection: Axis.horizontal, itemBuilder: (context, index) => Padding( padding: const EdgeInsets.symmetric(horizontal: 6.0), child: GestureDetector( onTap: (){ currentIndex = index; BlocProvider.of<AddNoteCubit>(context).color = kColors[index]; setState(() {}); }, child: ColorItem( color: kColors[index], isActive: currentIndex == index, ), ), ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/add_note_bottom_sheet.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:notter/cubits/add_note_cubit/add_note_cubit.dart'; import 'package:notter/cubits/notes_cubit/notes_cubit.dart'; import 'add_note_form.dart'; class AddNoteBottomSheet extends StatelessWidget { const AddNoteBottomSheet({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => AddNoteCubit(), child: SizedBox( child: BlocConsumer<AddNoteCubit, AddNoteState>( listener: (context, state) { if (state is AddNoteFailure) { print('error: ${state.errMessage}'); } if (state is AddNoteSuccess) { BlocProvider.of<NotesCubit>(context).fetchAllNotes(); Navigator.pop(context); } }, builder: (context, state) { return AbsorbPointer( absorbing: state is AddNoteLoading ? true : false, child: Padding( padding: EdgeInsets.only( left: 16.0, right: 16.0, bottom: MediaQuery.of(context).viewInsets.bottom+30, ), child: const SingleChildScrollView(child: AddNoteForm()), ), ); }, ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/edit_note_view_body.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:notter/cubits/notes_cubit/notes_cubit.dart'; import 'package:notter/views/widgets/custom_app_bar.dart'; import '../../models/note_model.dart'; import 'custom_text_fiedls.dart'; import 'edit_note_colors_list_view.dart'; class EditNoteViewBody extends StatefulWidget { const EditNoteViewBody({Key? key, required this.note}) : super(key: key); final NoteModel note; @override State<EditNoteViewBody> createState() => _EditNoteViewBodyState(); } class _EditNoteViewBodyState extends State<EditNoteViewBody> { String? title, content; @override Widget build(BuildContext context) { return SafeArea( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 24.0), child: Column( children: [ const SizedBox(height: 20.0), CustomAppBar( onPress: () { widget.note.title = title ?? widget.note.title; widget.note.subTitle = content ?? widget.note.subTitle; widget.note.save(); BlocProvider.of<NotesCubit>(context).fetchAllNotes(); Navigator.pop(context); }, title: 'Edit Note', icon: Icons.check, ), const SizedBox(height: 20.0), CustomTextField( hint: widget.note.title, onChanged: (value) => title = value), const SizedBox(height: 20.0), CustomTextField( onChanged: (value) => content = value, hint: widget.note.subTitle, maxLines: 4, ), const SizedBox(height: 20.0), EditNoteColorsList(note: widget.note), ], ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/notes_view_body.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:notter/cubits/notes_cubit/notes_cubit.dart'; import 'custom_app_bar.dart'; import 'notes_list_view.dart'; class NotesViewBody extends StatefulWidget { const NotesViewBody({Key? key}) : super(key: key); @override State<NotesViewBody> createState() => _NotesViewBodyState(); } class _NotesViewBodyState extends State<NotesViewBody> { // initial notes cubit function to load all box data and trigger the function fetchAllNotes(); @override void initState() { BlocProvider.of<NotesCubit>(context).fetchAllNotes(); super.initState(); } @override Widget build(BuildContext context) { return const Padding( padding: EdgeInsets.symmetric(horizontal: 24.0), child: Column( children: [ SizedBox(height: 20.0), CustomAppBar(title: 'Notes', icon: Icons.search,), SizedBox(height: 20.0), Expanded(child: NotesListView()), ], ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/add_note_form.dart
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:intl/intl.dart'; import 'package:notter/cubits/add_note_cubit/add_note_cubit.dart'; import 'package:notter/models/note_model.dart'; import 'colors_list_view.dart'; import 'custom_button.dart'; import 'custom_text_fiedls.dart'; class AddNoteForm extends StatefulWidget { const AddNoteForm({ super.key, }); @override State<AddNoteForm> createState() => _AddNoteFormState(); } class _AddNoteFormState extends State<AddNoteForm> { final GlobalKey<FormState> formKey = GlobalKey(); AutovalidateMode autovalidateMode = AutovalidateMode.disabled; String? title, subtitle; @override Widget build(BuildContext context) { return Form( key: formKey, autovalidateMode: autovalidateMode, child: Column( children: [ const SizedBox(height: 32.0), CustomTextField( hint: 'Title', onSaved: (value) { title = value; }, ), const SizedBox(height: 24.0), CustomTextField( hint: 'Note Content', maxLines: 4, onSaved: (value) { subtitle = value; }, ), const SizedBox(height: 35.0), const ColorsListView(), const SizedBox(height: 35.0), BlocBuilder<AddNoteCubit, AddNoteState>( builder: (context, state) { return CustomButton( isLoading: state is AddNoteLoading ? true : false, onTap: () { if (formKey.currentState!.validate()) { formKey.currentState!.save(); // create note model to receive the data from the form var noteModel = NoteModel( title: title!, subTitle: subtitle!, date: DateFormat('EEEE, MMM d, yyyy') .format(DateTime.now()) .toString(), color: Colors.blue.value, ); BlocProvider.of<AddNoteCubit>(context).addNote(noteModel); } else { autovalidateMode = AutovalidateMode.always; setState(() {}); } }, ); }, ), ], ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/custom_text_fiedls.dart
import 'package:flutter/material.dart'; import '../../constants.dart'; class CustomTextField extends StatelessWidget { const CustomTextField( {Key? key, required this.hint, this.maxLines = 1, this.onSaved, this.onChanged}) : super(key: key); final String hint; final int maxLines; final Function(String)? onChanged; final void Function(String?)? onSaved; @override Widget build(BuildContext context) { return TextFormField( onChanged: onChanged, onSaved: onSaved, validator: (value) { if (value?.isEmpty ?? true) { return 'Field is Required'; } }, cursorColor: kPrimaryColor, maxLines: maxLines, decoration: InputDecoration( hintText: hint, border: BuildBorder(), enabledBorder: BuildBorder(), focusedBorder: BuildBorder(kPrimaryColor), ), ); } OutlineInputBorder BuildBorder([color]) { return OutlineInputBorder( borderRadius: BorderRadius.circular(10.0), borderSide: BorderSide( color: color ?? Colors.white, ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/edit_note_colors_list_view.dart
import 'package:flutter/material.dart'; import '../../constants.dart'; import '../../models/note_model.dart'; import 'colors_list_view.dart'; class EditNoteColorsList extends StatefulWidget { const EditNoteColorsList({Key? key, required this.note}) : super(key: key); final NoteModel note; @override State<EditNoteColorsList> createState() => _EditNoteColorsListState(); } class _EditNoteColorsListState extends State<EditNoteColorsList> { late int currentIndex; @override void initState() { currentIndex = kColors.indexOf(Color(widget.note.color)); super.initState(); } @override Widget build(BuildContext context) { return SizedBox( height: 38 * 2, child: ListView.builder( itemCount: kColors.length, scrollDirection: Axis.horizontal, itemBuilder: (context, index) => Padding( padding: const EdgeInsets.symmetric(horizontal: 6.0), child: GestureDetector( onTap: () { currentIndex = index; widget.note.color = kColors[index].value; setState(() {}); }, child: ColorItem( color: kColors[index], isActive: currentIndex == index, ), ), ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/custom_app_bar.dart
import 'package:flutter/material.dart'; import 'custom_search_icon.dart'; class CustomAppBar extends StatelessWidget { const CustomAppBar({Key? key, required this.title, required this.icon, this.onPress}) : super(key: key); final String? title; final IconData icon; final void Function()? onPress; @override Widget build(BuildContext context) { return Row( children: [ Text( '$title', style: const TextStyle(fontSize: 32.0), ), const Spacer(), CustomSearchIcon(icon: icon, onPress: onPress,), ], ); } }
0
mirrored_repositories/notes_app_learning/lib/views
mirrored_repositories/notes_app_learning/lib/views/widgets/custom_search_icon.dart
import 'package:flutter/material.dart'; class CustomSearchIcon extends StatelessWidget { const CustomSearchIcon({Key? key, required this.icon, this.onPress}) : super(key: key); final IconData icon; final void Function()? onPress; @override Widget build(BuildContext context) { return Container( height: 46.0, width: 46.0, decoration: BoxDecoration( color: Colors.grey.withOpacity(0.2), borderRadius: BorderRadius.circular(16.0), ), child: Center( child: IconButton( onPressed: onPress, icon: Icon( icon, size: 28, ), ), ), ); } }
0
mirrored_repositories/notes_app_learning/lib/cubits
mirrored_repositories/notes_app_learning/lib/cubits/notes_cubit/notes_state.dart
part of 'notes_cubit.dart'; @immutable abstract class NotesState {} class NotesInitial extends NotesState {} class NotesSuccess extends NotesState {}
0
mirrored_repositories/notes_app_learning/lib/cubits
mirrored_repositories/notes_app_learning/lib/cubits/notes_cubit/notes_cubit.dart
import 'package:bloc/bloc.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:meta/meta.dart'; import 'package:notter/constants.dart'; import 'package:notter/models/note_model.dart'; part 'notes_state.dart'; class NotesCubit extends Cubit<NotesState> { NotesCubit() : super(NotesInitial()); List<NoteModel>? notes; fetchAllNotes () { // define our hive worker var notesBox = Hive.box<NoteModel>(kNotesBox); // load all notes from hive notes = notesBox.values.toList(); emit(NotesSuccess()); } }
0
mirrored_repositories/notes_app_learning/lib/cubits
mirrored_repositories/notes_app_learning/lib/cubits/add_note_cubit/add_note_state.dart
part of 'add_note_cubit.dart'; @immutable abstract class AddNoteState {} class AddNoteInitial extends AddNoteState {} class AddNoteLoading extends AddNoteState {} class AddNoteSuccess extends AddNoteState {} class AddNoteFailure extends AddNoteState { final String errMessage; AddNoteFailure(this.errMessage); }
0
mirrored_repositories/notes_app_learning/lib/cubits
mirrored_repositories/notes_app_learning/lib/cubits/add_note_cubit/add_note_cubit.dart
import 'package:flutter/material.dart'; import 'package:bloc/bloc.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:meta/meta.dart'; import 'package:notter/constants.dart'; import 'package:notter/models/note_model.dart'; part 'add_note_state.dart'; class AddNoteCubit extends Cubit<AddNoteState> { AddNoteCubit() : super(AddNoteInitial()); // assign default value for color Color color = const Color(0xff6DA34D); // start logic from here addNote(NoteModel note) async { // assign imported color on adding the box note.color = color.value; // return state of loading. emit(AddNoteLoading()); try { // define our hive worker var notesBox = Hive.box<NoteModel>(kNotesBox); // insert data (execute process) await notesBox.add(note); // return state of success emit(AddNoteSuccess()); } catch (e) { // return state if failure with error exception emit(AddNoteFailure('Error on catch: ${e.toString()}')); // emit(AddNoteFailure(e.toString())); } } }
0
mirrored_repositories/notes_app_learning/lib
mirrored_repositories/notes_app_learning/lib/models/note_model.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND part of 'note_model.dart'; // ************************************************************************** // TypeAdapterGenerator // ************************************************************************** class NoteModelAdapter extends TypeAdapter<NoteModel> { @override final int typeId = 0; @override NoteModel read(BinaryReader reader) { final numOfFields = reader.readByte(); final fields = <int, dynamic>{ for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), }; return NoteModel( title: fields[0] as String, subTitle: fields[1] as String, date: fields[2] as String, color: fields[3] as int, ); } @override void write(BinaryWriter writer, NoteModel obj) { writer ..writeByte(4) ..writeByte(0) ..write(obj.title) ..writeByte(1) ..write(obj.subTitle) ..writeByte(2) ..write(obj.date) ..writeByte(3) ..write(obj.color); } @override int get hashCode => typeId.hashCode; @override bool operator ==(Object other) => identical(this, other) || other is NoteModelAdapter && runtimeType == other.runtimeType && typeId == other.typeId; }
0
mirrored_repositories/notes_app_learning/lib
mirrored_repositories/notes_app_learning/lib/models/note_model.dart
import 'package:hive/hive.dart'; part 'note_model.g.dart'; @HiveType(typeId: 0) class NoteModel extends HiveObject{ @HiveField(0) String title; @HiveField(1) String subTitle; @HiveField(2) final String date; @HiveField(3) int color; NoteModel({ required this.title, required this.subTitle, required this.date, required this.color, }); }
0
mirrored_repositories/flutter-tutorials/SEP2023/hi_world
mirrored_repositories/flutter-tutorials/SEP2023/hi_world/lib/main.dart
import 'package:flutter/material.dart'; void main(List<String> args) { runApp( MaterialApp( theme: ThemeData( useMaterial3: false, primarySwatch: Colors.red, ), // Blank app debugShowCheckedModeBanner: false, title: 'Hi App', // In web-browser tab home: Scaffold( // Blank screen appBar: AppBar( // Blank app bar title: const Text('Contacts'), // App bar title ), body: ListTile( leading: const Icon(Icons.account_circle, size: 35.1, color: Colors.blue), title: const Text('Usama Sarwar'), subtitle: const Text('+92 310 0007773'), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ // Icon(Icons.video_call, size: 30, color: Colors.green), IconButton( icon: const Icon(Icons.video_call, size: 30.5, color: Colors.green), onPressed: () { debugPrint('Video call button pressed'); }, ), // const SizedBox(width: 15), // const Icon(Icons.phone, size: 30, color: Colors.green), IconButton( icon: const Icon(Icons.phone, size: 30.5, color: Colors.green), onPressed: () { debugPrint('Voice call button pressed'); }, ), ], ), ), ), ), ); }
0
mirrored_repositories/flutter-tutorials/SEP2023/hello_world
mirrored_repositories/flutter-tutorials/SEP2023/hello_world/lib/main.dart
// Material Library is used for Material Design by Google import 'package:flutter/material.dart'; main() { // runApp is responsible for running the app runApp( // Material App is the root widget of the app MaterialApp( title: 'Hello World App', debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( backgroundColor: Colors.purpleAccent.withOpacity(0.1), title: const Text('Hello World App'), ), body: const Center( child: Text( 'Hello World', ), ), ), ), ); }
0
mirrored_repositories/flutter-tutorials/SEP2023/portfolio
mirrored_repositories/flutter-tutorials/SEP2023/portfolio/lib/main.dart
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // TRY THIS: Try running your application with "flutter run". You'll see // the application has a purple toolbar. Then, without quitting the app, // try changing the seedColor in the colorScheme below to Colors.green // and then invoke "hot reload" (save your changes or press the "hot // reload" button in a Flutter-supported IDE, or press "r" if you used // the command line to start the app). // // Notice that the counter didn't reset back to zero; the application // state is not lost during the reload. To reset the state, use hot // restart instead. // // This works for code too, not just values: Most code changes can be // tested with just a hot reload. colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { // This call to setState tells the Flutter framework that something has // changed in this State, which causes it to rerun the build method below // so that the display can reflect the updated values. If we changed // _counter without calling setState(), then the build method would not be // called again, and so nothing would appear to happen. _counter++; }); } @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( // TRY THIS: Try changing the color here to a specific color (to // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar // change color while the other colors stay the same. backgroundColor: Theme.of(context).colorScheme.inversePrimary, // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: Center( // Center is a layout widget. It takes a single child and positions it // in the middle of the parent. child: Column( // Column is also a layout widget. It takes a list of children and // arranges them vertically. By default, it sizes itself to fit its // children horizontally, and tries to be as tall as its parent. // // Column has various properties to control how it sizes itself and // how it positions its children. Here we use mainAxisAlignment to // center the children vertically; the main axis here is the vertical // axis because Columns are vertical (the cross axis would be // horizontal). // // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" // action in the IDE, or press "p" in the console), to see the // wireframe for each widget. mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( 'You have pushed the button this many times:', ), Text( '$_counter', style: Theme.of(context).textTheme.headlineMedium, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: const Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
0
mirrored_repositories/flutter-tutorials/SEP2023/portfolio
mirrored_repositories/flutter-tutorials/SEP2023/portfolio/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:portfolio/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/SEP2023/files
mirrored_repositories/flutter-tutorials/SEP2023/files/lib/welcome.dart
import 'package:flutter/material.dart'; class Welcome extends StatelessWidget { const Welcome({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Welcome!'), ), body: const Center( child: Text('Hello World'), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/SEP2023/files
mirrored_repositories/flutter-tutorials/SEP2023/files/lib/main.dart
import 'package:flutter/material.dart'; import 'welcome.dart'; main() { runApp(const Welcome()); } // main() { // runApp( // MaterialApp( // home: Scaffold( // appBar: AppBar( // title: const Text('Welcome!'), // ), // body: const Center( // child: Text('Hello World'), // ), // )), // ); // }
0
mirrored_repositories/flutter-tutorials/SEP2023/rowscolumns
mirrored_repositories/flutter-tutorials/SEP2023/rowscolumns/lib/rows_columns.dart
import 'package:flutter/material.dart'; class ContactsBook extends StatefulWidget { const ContactsBook({super.key}); @override State<ContactsBook> createState() => _ContactsBookState(); } class _ContactsBookState extends State<ContactsBook> { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Messenger', home: Scaffold( appBar: AppBar(title: const Text('Messenger')), body: Column( children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 15), child: Card( elevation: 0, color: Colors.blueGrey.shade50.withOpacity(0.8), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)), child: const Row( children: [ Padding( padding: EdgeInsets.all(10), child: Icon(Icons.search), ), Expanded( child: TextField( decoration: InputDecoration( hintText: 'Search', border: InputBorder.none, ), ), ), ], ), ), ), // Statuses const SingleChildScrollView( scrollDirection: Axis.horizontal, child: Padding( padding: EdgeInsets.all(18.0), child: Row( children: [ // using circle avatar and using demo images Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=30'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=31'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=32'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=33'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=34'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=35'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=36'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=37'))), Padding(padding: EdgeInsets.only(right: 10), child: CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=38'))), ], ), ), ), Expanded( child: SingleChildScrollView( child: Column( children: [ // Image.asset('assets/usama.jpg', height: 200, width: 200), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: AssetImage('assets/usama.jpg')), title: const Text('Usama Sarwar'), subtitle: const Text('0310 0007773'), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ IconButton(onPressed: () {}, icon: const Icon(Icons.video_call, color: Colors.green)), IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ], ), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=2')), title: const Text('Muhammad Yahya'), subtitle: const Text('0310 4445553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=3')), title: const Text('Muhammad Ali'), subtitle: const Text('0310 3335553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=4')), title: const Text('Muhammad Umer'), subtitle: const Text('0310 2225553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=1')), title: const Text('Muhammad Usman'), subtitle: const Text('0310 1115553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=5')), title: const Text('Usama Sarwar'), subtitle: const Text('0310 0007773'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=6')), title: const Text('Muhammad Yahya'), subtitle: const Text('0310 4445553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=7')), title: const Text('Muhammad Ali'), subtitle: const Text('0310 3335553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=8')), title: const Text('Muhammad Umer'), subtitle: const Text('0310 2225553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=9')), title: const Text('Muhammad Usman'), subtitle: const Text('0310 1115553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=10')), title: const Text('Usama Sarwar'), subtitle: const Text('0310 0007773'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=11')), title: const Text('Muhammad Yahya'), subtitle: const Text('0310 4445553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=12')), title: const Text('Muhammad Ali'), subtitle: const Text('0310 3335553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=13')), title: const Text('Muhammad Umer'), subtitle: const Text('0310 2225553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=14')), title: const Text('Muhammad Usman'), subtitle: const Text('0310 1115553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=15')), title: const Text('Usama Sarwar'), subtitle: const Text('0310 0007773'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=16')), title: const Text('Muhammad Yahya'), subtitle: const Text('0310 4445553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=17')), title: const Text('Muhammad Ali'), subtitle: const Text('0310 3335553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=18')), title: const Text('Muhammad Umer'), subtitle: const Text('0310 2225553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ListTile( leading: const CircleAvatar(radius: 30, backgroundImage: NetworkImage('https://picsum.photos/200?random=19')), title: const Text('Muhammad Usman'), subtitle: const Text('0310 1115553'), trailing: IconButton(onPressed: () {}, icon: const Icon(Icons.call, color: Colors.green)), ), ], ), ), ), ], ), ), ); } }
0
mirrored_repositories/flutter-tutorials/SEP2023/rowscolumns
mirrored_repositories/flutter-tutorials/SEP2023/rowscolumns/lib/main.dart
import 'package:flutter/material.dart'; import 'rows_columns.dart'; // main() => runApp(const ContactsBook()); void main(List<String> args) { runApp(const ContactsBook()); }
0
mirrored_repositories/flutter-tutorials/USMS/usms_first_app
mirrored_repositories/flutter-tutorials/USMS/usms_first_app/lib/main.dart
// material.dart: Material is a visual-design kit that helps bring Google's design to life. import 'package:flutter/material.dart'; // main(): Main function runs the program void main() { // runApp(): Runs the app runApp( // MaterialApp(): A convenience widget that wraps a number of widgets that are commonly required for applications implementing Material Design. MaterialApp( // debugShowCheckedModeBanner: Whether to show the banner when in debug mode. debugShowCheckedModeBanner: false, // title: The title to use for the application. title: 'USMS', // theme: The colors to use for the application's widgets. themeMode: ThemeMode.light, // Use the system-provided theme mode (light or dark) theme: ThemeData(// ThemeData(): A theme describes the colors and typographic choices of an application. // primarySwatch: The color swatch to use for the application's primary color. primarySwatch: Colors.deepPurple, // visualDensity: Defines the density of the user interface. visualDensity: VisualDensity.adaptivePlatformDensity, // brightness: The overall brightness of this theme. brightness: Brightness.light, ), darkTheme: ThemeData(// ThemeData(): A theme describes the colors and typographic choices of an application. // primarySwatch: The color swatch to use for the application's primary color. primarySwatch: Colors.deepPurple, // visualDensity: Defines the density of the user interface. visualDensity: VisualDensity.adaptivePlatformDensity, // brightness: The overall brightness of this theme. brightness: Brightness.dark, ), // home: The widget for the default route of the app (Navigator.defaultRouteName, which is /). home: Scaffold( // Scaffold(): Implements the basic material design visual layout structure. // appBar: The app bar to display at the top of the scaffold. appBar: AppBar( // title: The primary widget displayed in the app bar. title: const Text('USMS'), // centerTitle: Whether the title should be centered. centerTitle: true, ), // body: The primary content of the scaffold. body: const Center( // Center(): A widget that centers its child within itself. child: Text( 'University of Sufism', // style: The text style to apply to the text. style: TextStyle( // fontSize: The size of glyphs (in logical pixels) to use when painting the text. fontSize: 30, // color: The color to use when painting the text. color: Colors.deepPurple, ), ), ), floatingActionButton: FloatingActionButton( onPressed: () {}, child: const Icon(Icons.mail), ), ), ), ); }
0
mirrored_repositories/flutter-tutorials/USMS/usms_first_app
mirrored_repositories/flutter-tutorials/USMS/usms_first_app/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:usms_first_app/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/USMS/whatsapp
mirrored_repositories/flutter-tutorials/USMS/whatsapp/lib/chats.dart
import 'package:flutter/material.dart'; import 'database.dart'; class Chats extends StatefulWidget { const Chats({super.key}); @override State<Chats> createState() => _ChatsState(); } class _ChatsState extends State<Chats> { @override Widget build(BuildContext context) { return Scaffold( // List View Builder body: ListView.builder( itemCount: chats.length, itemBuilder: (context, index) { return ListTile( // Show images from picsum.photos leading: CircleAvatar( backgroundImage: NetworkImage('https://picsum.photos/seed/$index/200/200') , ), title: Text(name[index]), subtitle: Text(chats[index]), trailing: Text('$index:0$index'), ); }, ), floatingActionButton: FloatingActionButton( child: const Icon(Icons.add), onPressed: () { setState(() { name.add('New Chat'); chats.add('What\'s up Man'); }); }, ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/whatsapp
mirrored_repositories/flutter-tutorials/USMS/whatsapp/lib/main.dart
import 'package:flutter/material.dart'; import 'package:whatsapp/statuses.dart'; import 'chats.dart'; main() => runApp(const WhatsApp()); class WhatsApp extends StatefulWidget { const WhatsApp({super.key}); @override State<WhatsApp> createState() => _WhatsAppState(); } class _WhatsAppState extends State<WhatsApp> { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(primarySwatch: Colors.teal), title: 'WhatsApp', home: DefaultTabController( initialIndex: 1, length: 3, child: Scaffold( appBar: AppBar( actions: [ IconButton( onPressed: () {}, icon: const Icon(Icons.camera_alt_rounded), ), IconButton( onPressed: () {}, icon: const Icon(Icons.search), ), IconButton( onPressed: () {}, icon: const Icon(Icons.more_vert_outlined), ), ], title: const Text('WhatsApp'), // tab bar bottom: const TabBar( tabs: [ Tab( text: 'CHATS', ), Tab( text: 'STATUS', ), Tab( text: 'CALLS', ), ], ), ), body: const TabBarView( children: <Widget>[ Chats(), Statuses(), Center( child: Text("Calls"), ), ], ), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/whatsapp
mirrored_repositories/flutter-tutorials/USMS/whatsapp/lib/statuses.dart
import 'package:flutter/material.dart'; import 'database.dart'; class Statuses extends StatefulWidget { const Statuses({super.key}); @override State<Statuses> createState() => _StatusesState(); } class _StatusesState extends State<Statuses> { @override Widget build(BuildContext context) { return Scaffold( // List View Builder body: Column( children: [ const ListTile( // Show images from picsum.photos leading: CircleAvatar( backgroundImage: NetworkImage('https://picsum.photos/seed/500/200/200'), ), title: Text('My status'), subtitle: Text('Tap to add status update'), ), Container( width: double.infinity, color: Colors.grey[300], child: const Padding( padding: EdgeInsets.all(8.0), child: Text('Recent updates'), ), ), Expanded( child: ListView.builder( itemCount: chats.length, itemBuilder: (context, index) { return ListTile( // Show images from picsum.photos leading: CircleAvatar( backgroundImage: NetworkImage( 'https://picsum.photos/seed/$index/200/200'), ), title: Text(name[index]), subtitle: Text('$index:0$index'), ); }, ), ), ], ), floatingActionButton: FloatingActionButton( child: const Icon(Icons.camera_alt), onPressed: () { setState(() { name.add('New Chat'); chats.add('What\'s up Man'); }); }, ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/whatsapp
mirrored_repositories/flutter-tutorials/USMS/whatsapp/lib/database.dart
List<String> name = [ 'Alia Ali', 'Usama Sarwar', 'Bano Qudsia', 'Ali Ahmad', 'Alina Saleem', 'Qamtum Julia', 'Alia Ali', 'Usama Sarwar', 'Bano Qudsia', 'Ali Ahmad', 'Alina Saleem', 'Qamtum Julia', 'Alia Ali', 'Usama Sarwar', 'Bano Qudsia', 'Ali Ahmad', 'Alina Saleem', 'Qamtum Julia', ]; List<String> chats = [ 'Whats\'s Up dear?', 'Hi', 'Okay, bye', 'Khatam, ta ta', 'Bye Bye', 'Nice to meet you.', 'Welcome dear', 'Whats\'s Up dear?', 'Hi', 'Okay, bye', 'Khatam, ta ta', 'Bye Bye', 'Nice to meet you.', 'Welcome dear', 'Whats\'s Up dear?', 'Hi', 'Okay, bye', 'Khatam, ta ta', ];
0
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/lib/main.dart
import 'package:flutter/material.dart'; import 'package:usms_stateful_counter_app/Screens/counter_stateless_app.dart'; main() => runApp(CounterStatelessApp());
0
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/lib
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/lib/Screens/counter_stateless_app.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; // ignore: must_be_immutable class CounterStatelessApp extends StatelessWidget { CounterStatelessApp({super.key}); RxInt num = 0.obs; @override Widget build(BuildContext context) { return MaterialApp( title: 'Material App', debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: const Text('Counter App'), ), body: Center( child: Obx(() => Text( num.toString(), style: const TextStyle( fontSize: 50, ), )), ), floatingActionButton: FloatingActionButton( onPressed: () { num++; print(num); }, child: const Icon(Icons.add), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/lib
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/lib/Screens/counter_stateful_app.dart
import 'package:flutter/material.dart'; class CounterStatefulApp extends StatefulWidget { const CounterStatefulApp({super.key}); @override State<CounterStatefulApp> createState() => _CounterStatefulAppState(); } class _CounterStatefulAppState extends State<CounterStatefulApp> { int num = 0; @override Widget build(BuildContext context) { return MaterialApp( title: 'Material App', debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: const Text('Counter App'), ), body: Center( child: Text( num.toString(), style: const TextStyle( fontSize: 50, ), ), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { num++; }); print(num); }, child: const Icon(Icons.add), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app
mirrored_repositories/flutter-tutorials/USMS/usms_stateful_counter_app/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:usms_stateful_counter_app/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/USMS/usms_game
mirrored_repositories/flutter-tutorials/USMS/usms_game/lib/main.dart
import 'package:flutter/material.dart'; void main() { runApp(TicTacToeApp()); } class TicTacToeApp extends StatelessWidget { const TicTacToeApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Tic-Tac-Toe', theme: ThemeData( primarySwatch: Colors.blue, ), home: TicTacToeScreen(), ); } } class TicTacToeScreen extends StatefulWidget { const TicTacToeScreen({super.key}); @override _TicTacToeScreenState createState() => _TicTacToeScreenState(); } class _TicTacToeScreenState extends State<TicTacToeScreen> { List<List<String>> board = [ ['', '', ''], ['', '', ''], ['', '', ''], ]; String currentPlayer = 'X'; bool gameOver = false; String winner = ''; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Tic-Tac-Toe'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ buildBoard(), const SizedBox(height: 20.0), if (gameOver) Text( (winner == 'Draw') ? 'It\'s a Draw!' : 'Player $winner wins!', style: const TextStyle(fontSize: 20.0), ), const SizedBox(height: 20.0), ElevatedButton( onPressed: resetGame, child: const Text('Reset'), ), ], ), ), ); } Widget buildBoard() { return Column( children: [ for (int row = 0; row < 3; row++) Row( mainAxisAlignment: MainAxisAlignment.center, children: [ for (int col = 0; col < 3; col++) SizedBox( width: 100.0, height: 100.0, child: buildCell(row, col), ), ], ), ], ); } Widget buildCell(int row, int col) { return GestureDetector( onTap: () => makeMove(row, col), child: Container( decoration: BoxDecoration( border: Border.all(color: Colors.black), ), child: Center( child: Text( board[row][col], style: const TextStyle(fontSize: 40.0), ), ), ), ); } void checkGameOver() { // Check rows for (int row = 0; row < 3; row++) { if (board[row][0] != '' && board[row][0] == board[row][1] && board[row][0] == board[row][2]) { gameOver = true; winner = board[row][0]; break; } } // Check columns for (int col = 0; col < 3; col++) { if (board[0][col] != '' && board[0][col] == board[1][col] && board[0][col] == board[2][col]) { gameOver = true; winner = board[0][col]; break; } } // Check diagonals if (board[0][0] != '' && board[0][0] == board[1][1] && board[0][0] == board[2][2]) { gameOver = true; winner = board[0][0]; } else if (board[0][2] != '' && board[0][2] == board[1][1] && board[0][2] == board[2][0]) { gameOver = true; winner = board[0][2]; } // Check for a draw if (!gameOver && isBoardFull()) { gameOver = true; winner = 'Draw'; } } bool isBoardFull() { for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { if (board[row][col] == '') { return false; } } } return true; } void makeMove(int row, int col) { if (board[row][col] == '' && !gameOver) { setState(() { board[row][col] = currentPlayer; currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; checkGameOver(); }); } } void resetGame() { setState(() { board = [ ['', '', ''], ['', '', ''], ['', '', ''], ]; currentPlayer = 'X'; gameOver = false; winner = ''; }); } }
0
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib/main.dart
import 'package:flutter/material.dart'; import 'View/home_screen.dart'; main() => runApp(const App()); class App extends StatefulWidget { const App({super.key}); @override State<App> createState() => _AppState(); } class _AppState extends State<App> { @override Widget build(BuildContext context) { return const MaterialApp( title: 'Counter', home: HomeScreen(), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib/Model/counter.dart
class Counter { int count = 0; Counter({this.count = 0}); }
0
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib/View/home_screen.dart
import 'package:flutter/material.dart'; class HomeScreen extends StatefulWidget { const HomeScreen({super.key}); @override State<HomeScreen> createState() => _HomeScreenState(); } class _HomeScreenState extends State<HomeScreen> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Counter'), ), body: const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text('You have pushed the button this many times:'), Text('0'), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () {}, tooltip: 'Increment', child: const Icon(Icons.add), ), ); } }
0
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib
mirrored_repositories/flutter-tutorials/USMS/flutter_mvc/lib/Controller/controller.dart
import '../Model/counter.dart'; class Controller { Counter counter = Counter(count: 0); increment() { counter.count++; } }
0
mirrored_repositories/flutter-tutorials/projects/animatedappbar
mirrored_repositories/flutter-tutorials/projects/animatedappbar/lib/main.dart
import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart'; import 'package:flutter/material.dart'; void main() { runApp(const MaterialApp(home: MyApp())); } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { int _bottomNavIndex = 0; final _navBarIcons = [ Icons.home, Icons.search, ]; var bodyList = const [ Home(), Search(), ]; @override Widget build(BuildContext context) { return Scaffold( body: bodyList[_bottomNavIndex], //destination screen floatingActionButton: FloatingActionButton( child: const Icon(Icons.add), onPressed: () {}, ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: AnimatedBottomNavigationBar( icons: _navBarIcons, activeIndex: _bottomNavIndex, gapLocation: GapLocation.center, notchSmoothness: NotchSmoothness.verySmoothEdge, leftCornerRadius: 32, rightCornerRadius: 32, onTap: (index) => setState(() => _bottomNavIndex = index), //other params ), ); } } class Home extends StatelessWidget { const Home({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const Center( child: Icon(Icons.home), ); } } class Search extends StatelessWidget { const Search({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const Center( child: Icon(Icons.search), ); } }
0
mirrored_repositories/flutter-tutorials/projects/animatedappbar
mirrored_repositories/flutter-tutorials/projects/animatedappbar/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:animatedappbar/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/flutterwidgettree
mirrored_repositories/flutter-tutorials/projects/flutterwidgettree/lib/main.dart
// Importing Material UI Kit Package import 'package:flutter/material.dart'; // Main Function void main() { // Running the App runApp(const MyApp()); } // Stateless Widget class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Widget Tree', themeMode: ThemeMode.system, theme: ThemeData( primarySwatch: Colors.deepPurple, brightness: Brightness.light, ), darkTheme: ThemeData( primarySwatch: Colors.deepPurple, brightness: Brightness.dark, appBarTheme: const AppBarTheme( backgroundColor: Colors.deepPurpleAccent, ), floatingActionButtonTheme: const FloatingActionButtonThemeData( backgroundColor: Colors.deepPurpleAccent, ), ), home: Scaffold( appBar: AppBar( leading: const Icon(Icons.menu_rounded), actions: [ IconButton( onPressed: () {}, icon: const Icon(Icons.search), ), IconButton( onPressed: () {}, icon: const Icon(Icons.more_vert), ), ], centerTitle: true, // backgroundColor: Colors.deepPurple, title: const Text('Sindh Agriculture University, Umerkot'), ), body: Container( // color: Colors.deepPurple.withOpacity(0.1), child: const Center( child: Text( 'Sindh Agriculture University, Umerkot', style: TextStyle( // color: Colors.deepPurple, fontSize: 20, // letterSpacing: 2.0, ), ), ), ), floatingActionButton: FloatingActionButton( onPressed: () {}, child: const Icon(Icons.add), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/projects/flutterwidgettree
mirrored_repositories/flutter-tutorials/projects/flutterwidgettree/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutterwidgettree/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/hello_world
mirrored_repositories/flutter-tutorials/projects/hello_world/lib/main.dart
// Material Package for Flutter import 'package:flutter/material.dart'; // Entry Point of the App void main(List<String> args) { runApp( // runApp() is a built-in function that runs the app MaterialApp( debugShowCheckedModeBanner: false, title: 'Hello World App', home: Scaffold( appBar: AppBar( backgroundColor: Colors.amber, centerTitle: true, title: const Text('Hello World App'), ), body: const Center( child: Text( 'Hello World!', style: TextStyle(fontSize: 30.0), ), ), ), ), ); }
0
mirrored_repositories/flutter-tutorials/projects/hello_world
mirrored_repositories/flutter-tutorials/projects/hello_world/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hello_world/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/lib/potrait.dart
import 'package:flutter/material.dart'; // Some landscape UI var potrait = Center( child: Container( color: Colors.blue, width: 100, height: 100, ), );
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/lib/controller.dart
import 'package:get/get.dart'; class Controller extends GetxController { final width = 0.0.obs; final height = 0.0.obs; // Getter double get getWidth => width.value; double get getHeight => height.value; // Setter set setWidth(double value) => width.value = value; set setHeight(double value) => height.value = value; }
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/lib/main.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:responsive_ui/controller.dart'; import 'home.dart'; void main() { runApp(const MyApp()); Get.put(Controller()); } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return const GetMaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Responsive UI', home: Home(), ); } }
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/lib/home.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:responsive_ui/landscape.dart'; import 'package:responsive_ui/potrait.dart'; class Home extends StatefulWidget { const Home({super.key}); @override State<Home> createState() => _HomeState(); } class _HomeState extends State<Home> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: context.isLandscape // context.isLandscape is a GetX method ? const FittedBox( child: Text( 'Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen Landscape Screen '), ) : const FittedBox( child: Text( 'Potrait Screen Potrait Screen Potrait Screen Potrait Screen ')), ), body: context.isLandscape ? landscape : potrait, ); } }
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/lib/landscape.dart
import 'package:flutter/material.dart'; // Some landscape UI var landscape = Center( child: Container( color: Colors.red, width: 100, height: 100, ), );
0
mirrored_repositories/flutter-tutorials/projects/responsive_ui
mirrored_repositories/flutter-tutorials/projects/responsive_ui/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:responsive_ui/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/first_app
mirrored_repositories/flutter-tutorials/projects/first_app/lib/main.dart
import 'package:flutter/material.dart'; void main(List<String> args) { runApp( MaterialApp( debugShowCheckedModeBanner: false, title: 'First App', theme: ThemeData( primarySwatch: Colors.amber, // brightness: Brightness.dark, ), home: Scaffold( appBar: AppBar( centerTitle: true, title: const Text('This is a Text Widget'), ), body: const Center( child: Text('This is a Text Widget'), ), floatingActionButton: FloatingActionButton( onPressed: () {}, child: const Icon(Icons.add), ), ), ), ); }
0
mirrored_repositories/flutter-tutorials/projects/getxapp
mirrored_repositories/flutter-tutorials/projects/getxapp/lib/controller.dart
import 'package:get/get.dart'; class Controller extends GetxController { // int count = 0; RxInt count = 0.obs; // Observable increment() => count++; decrement() => count--; /// increment(){ /// count.value++; /// } }
0
mirrored_repositories/flutter-tutorials/projects/getxapp
mirrored_repositories/flutter-tutorials/projects/getxapp/lib/main.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:getxapp/controller.dart'; void main() => runApp( const GetMaterialApp( home: Home(), ), ); class Home extends StatelessWidget { const Home({Key? key}) : super(key: key); @override Widget build(context) { // Instantiate your class using Get.put() to make it available for all "child" routes there. final Controller controller = Get.put(Controller()); return Scaffold( // Use Obx(()=> to update Text() whenever count is changed. appBar: AppBar( title: Obx(() => Text("Clicks: ${controller.count}")), ), // Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context body: Center( child: ElevatedButton( child: const Text("Go to Other"), onPressed: () => Get.to(Other()), onLongPress: () => controller.decrement(), ), ), floatingActionButton: FloatingActionButton( onPressed: controller.increment, child: const Icon(Icons.add), ), ); } } class Other extends StatelessWidget { // You can ask Get to find a Controller that is being used by another page and redirect you to it. final Controller controller = Get.find(); Other({Key? key}) : super(key: key); @override Widget build(context) { // Access the updated count variable return Scaffold( body: Center( child: Obx(() => Text("${controller.count}")), ), ); } }
0
mirrored_repositories/flutter-tutorials/projects/flutter_column_rows
mirrored_repositories/flutter-tutorials/projects/flutter_column_rows/lib/main.dart
import 'package:flutter/material.dart'; void main() { runApp(const Portfolio()); } // Portfolio App class Portfolio extends StatelessWidget { const Portfolio({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Usama Sarwar', theme: ThemeData( primarySwatch: Colors.grey, ), home: Scaffold( body: Padding( padding: const EdgeInsets.symmetric(horizontal: 10.0), child: Center( child: Column( children: [ Center( child: Padding( padding: const EdgeInsets.fromLTRB(0, 60, 0, 20), child: Container( decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: Colors.blue, width: 3, ), ), child: const CircleAvatar( maxRadius: 80, minRadius: 70, backgroundColor: Colors.grey, /// NetworkImage // backgroundImage: NetworkImage( // 'https://i0.wp.com/www.usama.dev/wp-content/uploads/2022/03/cropped-UsamaSarwar-1.png'), /// AssetImage backgroundImage: AssetImage('assets/usama.jpg'), ), ), ), ), Text( 'USAMA SARWAR', style: TextStyle( color: Colors.blue[800], fontSize: 22, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 5), Text( 'Lead Flutter Trainer', style: TextStyle(color: Colors.blue[400]), ), const SizedBox(height: 10), Card( color: Colors.cyan[50], child: const ListTile( leading: Icon(Icons.phone), title: Text('Contact Number'), subtitle: Text('(+9231) 0000-777-3'), ), ), Card( color: Colors.amber[50], child: const ListTile( leading: Icon(Icons.email), title: Text('Email Address'), subtitle: Text('[email protected]'), ), ), Card( color: Colors.red[50], child: const ListTile( leading: Icon(Icons.web), title: Text('Website'), subtitle: Text('www.usama.dev'), ), ), Card( color: Colors.purple[50], child: const ListTile( leading: Icon(Icons.location_on), title: Text('Address'), subtitle: Text('Faisalabad, Punjab, Pakistan'), ), ), const SizedBox(height: 15), ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.blue), ), onPressed: () {}, child: const Text( 'Hire Me!', style: TextStyle( color: Colors.white, ), ), ), ], ), ), ), ), ); } }
0
mirrored_repositories/flutter-tutorials/projects/flutter_column_rows
mirrored_repositories/flutter-tutorials/projects/flutter_column_rows/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_column_rows/main.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const Portfolio()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/getx_state_management
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib/main.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'Controller/Controller.dart'; import 'Views/tasbih_counter_page.dart'; void main() { runApp(const TasbihCounterApp()); Get.put(Controller()); } class TasbihCounterApp extends StatelessWidget { const TasbihCounterApp({super.key}); @override Widget build(BuildContext context) { return GetMaterialApp( debugShowCheckedModeBanner: false , title: 'Tasbih Counter', theme: ThemeData( primarySwatch: Colors.blue, ), home: TasbihCounterPage(title: 'Tasbih Counter'), ); } }
0
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib/Functions/increment.dart
int increment(int number) { return number + 1; }
0
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib/Views/tasbih_counter_page.dart
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:getx_state_management/Functions/increment.dart'; import '../Controller/Controller.dart'; class TasbihCounterPage extends StatelessWidget { TasbihCounterPage({super.key, required this.title}); final String title; final Controller c = Get.find(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ const Text( 'You have pushed the button this many times:', ), Obx(() => Text( c.getCounter.toString(), style: Theme.of(context).textTheme.headlineMedium, )), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () => c.setCounter = increment(c.getCounter), tooltip: 'Increment', child: const Icon(Icons.add), ), ); } }
0
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib
mirrored_repositories/flutter-tutorials/projects/getx_state_management/lib/Controller/controller.dart
import 'package:get/get.dart'; class Controller extends GetxController { // Observable is a reactive variable final counter = 0.obs; // Setter set setCounter(int value) => counter.value = value; // Getter int get getCounter => counter.value; }
0
mirrored_repositories/flutter-tutorials/projects/getx_state_management
mirrored_repositories/flutter-tutorials/projects/getx_state_management/test/widget_test.dart
// This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester // utility in the flutter_test package. For example, you can send tap and scroll // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:getx_state_management/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const TasbihCounterApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing); // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); // Verify that our counter has incremented. expect(find.text('0'), findsNothing); expect(find.text('1'), findsOneWidget); }); }
0
mirrored_repositories/flutter-tutorials/projects/counterapp
mirrored_repositories/flutter-tutorials/projects/counterapp/lib/main.dart
// ignore_for_file: prefer_const_constructors import 'package:flutter/material.dart'; void main(List<String> args) { runApp(MyApp()); } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { int count = 0; void increment() { count++; } @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Counter App', theme: ThemeData( primarySwatch: Colors.red, // useMaterial3: true, ), home: Scaffold( appBar: AppBar( title: Text('Counter'), actions: [ IconButton( onPressed: () { increment(); setState(() {}); }, icon: Icon( Icons.add, ), ), ], ), body: Center( child: Text( count.toString(), // '$count', style: TextStyle( fontSize: 50, color: Colors.redAccent[700], ), ), ), floatingActionButton: FloatingActionButton( onPressed: () { increment(); setState(() {}); }, child: Icon(Icons.add), ), ), ); } }
0