Commit 6feb322e authored by Timothe's avatar Timothe

midi mercredi

parent 285c5ed2
import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'dart:math';
void main() {
runApp(MyApp());
}
/// Flutter code sample for [Draggable].
class MyApp extends StatelessWidget {
const MyApp({super.key});
void main() => runApp(const TindBookApp());
class TindBookApp extends StatelessWidget {
const TindBookApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MyAppState(),
create: (context) => TindBookState(),
child: MaterialApp(
title: 'Namer App',
title: 'Tind Book',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Color.fromARGB(255, Random().nextInt(255), Random().nextInt(255), Random().nextInt(255))),
colorScheme: ColorScheme.fromSeed(seedColor:Color.fromARGB(255, Random().nextInt(255), Random().nextInt(255), Random().nextInt(255))),
),
home: Builder(
builder: (context) {
return Directionality(
textDirection: TextDirection.ltr, // or TextDirection.rtl
child: Scaffold(
appBar: AppBar(title: const Text('Draggable Sample')),
body: MyHomePage(),
),
);
},
),
home: MyHomePage(),
),
);
}
}
class MyAppState extends ChangeNotifier {
var current = WordPair.random();
class TindBookState extends ChangeNotifier {
void getNext(){
current = WordPair.random();
notifyListeners();
}
var favorites = <WordPair>[];
}
void toggleFavorite() {
if (favorites.contains(current)) {
favorites.remove(current);
} else {
favorites.add(current);
}
notifyListeners();
class TindBook extends StatefulWidget {
const TindBook({super.key});
@override
State<TindBook> createState() => _TindBookApp();
}
class _TindBookApp extends State<TindBook> {
bool acceptedData = false;
double dragDistance = 0.0;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
double containerWidth = constraints.maxWidth / 3; // Adjust as needed
double containerHeight = constraints.maxHeight; // Adjust as needed
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
DragTarget<bool>(
builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Container(
height: containerHeight,
width: containerWidth,
color: Colors.cyan,
child: Center(
child: Text('Value is updated to: $acceptedData'),
),
);
},
onAccept: (bool data) {
setState(() {
acceptedData = data;
acceptedData = false;
});
},
),
GestureDetector(
onHorizontalDragUpdate: (details) {
setState(() {
print('selected: ${details.primaryDelta}');
dragDistance = details.primaryDelta!;
});
},
child: Draggable<bool>(
// Data is the value this Draggable stores.
data: true,
feedback: AnimatedContainer(
duration: Duration(milliseconds: 4), // No animation for feedback
transform: Matrix4.rotationZ(dragDistance*50),
child: Container(
color: Colors.deepOrange,
height: containerHeight,
width: containerWidth,
child: const Icon(Icons.directions_run),
),
),
childWhenDragging: Container(
height: containerHeight,
width: containerWidth,
color: Colors.pinkAccent,
child: const Center(
child: Text('Child When Dragging'),
),
),
child: Container(
height: containerHeight,
width: containerWidth,
color: const Color.fromARGB(255, 255, 89, 89),
child: const Center(
child: Text('Draggable'),
),
),
),
),
DragTarget<bool>(
builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Container(
height: containerHeight,
width: containerWidth,
color: Colors.cyan,
child: Center(
child: Text('Value is updated to: $acceptedData'),
),
);
},
onAccept: (bool data) {
setState(() {
acceptedData = data;
});
},
),
],
);
},
);
}
}
// test
class FavoritePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Text('Test'),
],)
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
......@@ -62,11 +188,14 @@ class _MyHomePageState extends State<MyHomePage> {
Widget page;
switch (selectedIndex) {
case 0:
page = GeneratorPage();
page = TindBook();
break;
case 1:
page = FavoritePage();
break;
case 2:
page = Placeholder();
break;
default:
throw UnimplementedError('no widget for $selectedIndex');
}
......@@ -85,9 +214,13 @@ class _MyHomePageState extends State<MyHomePage> {
label: Text('Home'),
),
NavigationRailDestination(
icon: Icon(Icons.favorite),
label: Text('Favorites'),
icon: Icon(Icons.swipe),
label: Text('Swipe'),
),
NavigationRailDestination(
icon: Icon(Icons.info),
label: Text('About'),
),
],
selectedIndex: selectedIndex,
onDestinationSelected: (value) {
......@@ -108,105 +241,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
}
);
}
}
class GeneratorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var pair = appState.current;
IconData icon;
if (appState.favorites.contains(pair)) {
icon = Icons.favorite;
} else {
icon = Icons.favorite_border;
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BigCard(pair: pair),
SizedBox(height: 10),
Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton.icon(
onPressed: () {
appState.toggleFavorite();
},
icon: Icon(icon),
label: Text('Like'),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: () {
appState.getNext();
},
child: Text('Next'),
),
],
),
],
),
);
}
}
class BigCard extends StatelessWidget {
const BigCard({
super.key,
required this.pair,
});
final WordPair pair;
@override
Widget build(BuildContext context) {
final theme=Theme.of(context);
final style = theme.textTheme.displayMedium!.copyWith(
color: theme.colorScheme.onPrimary,
);
return Card(
color: theme.colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(
pair.asLowerCase,
style: style,
semanticsLabel: "${pair.first} ${pair.second}",
),
),
);
}
}
class FavoritePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var favorites = appState.favorites;
return Scaffold(
body: Column(children: [
Text('Favorites'),
for (var fav in favorites)
Text(fav.asLowerCase),
],)
);
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ import 'package:tp1/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(const TindBook());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment