This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return Scaffold( | |
body: Center( | |
child: AnimatedContainer( | |
duration: const Duration(seconds: 1), | |
width: _toggled ? 200 : 100, | |
height: _toggled ? 200 : 100, | |
decoration: BoxDecoration( | |
color: _toggled ? Colors.blue : Colors.red, | |
borderRadius: BorderRadius.circular(_toggled ? 20 : 0), | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
// A simple counter class with immutable state | |
class Counter { | |
final int value; | |
Counter(this.value); | |
// Method to return a new instance with an incremented value | |
Counter copyWith({int? value}) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
// A simple counter class with mutable state | |
class Counter { | |
int value; | |
Counter(this.value); | |
} | |
// Creating a StateNotifier for the counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
// Define the FutureProvider for fetching data | |
final dataProvider = FutureProvider<String>((ref) async { | |
await Future.delayed(Duration(seconds: 2)); // Simulate network delay | |
return 'Hello, World!'; | |
}); | |
void main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
// Define the StateProvider for the counter | |
final counterProvider = StateProvider<int>((ref) => 0); | |
void main() { | |
runApp( | |
ProviderScope( | |
child: MyApp(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
class ThemeNotifier extends StateNotifier<ThemeData> { | |
ThemeNotifier() : super(ThemeData.light()); | |
bool isLight() { | |
return state == ThemeData.light(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
void main() { | |
runApp(const ProviderScope(child: MyApp())); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Custom Paint Animation'), | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/physics.dart'; | |
class DraggableSquare extends StatefulWidget { | |
const DraggableSquare({super.key}); | |
@override | |
State<DraggableSquare> createState() => _DraggableSquareState(); | |
} | |
class _DraggableSquareState extends State<DraggableSquare> with SingleTickerProviderStateMixin { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIT License | |
// | |
// Copyright (c) 2019 Simon Lightfoot | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: |
NewerOlder